Skip to content

Commit

Permalink
Improves the review ignored people button introduced in #747
Browse files Browse the repository at this point in the history
It is a minimal improvement on how the application should always have
been. Instead of getting the information at the start of the
application, we do it only when we know there are values and the user
wants to do something with it.

This also applies to the user's enablement value as well as to the set
of new people to recognize.
  • Loading branch information
matiasdelellis committed May 17, 2024
1 parent 6689358 commit 8e3b381
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 63 deletions.
1 change: 0 additions & 1 deletion lib/Controller/ClusterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ public function findUnassigned(): DataResponse {
* @return DataResponse
*/
Public function findIgnored(): DataResponse {
sleep(1); // button "Review ignored people" should be created delayed (after "Review people found" button)
$userEnabled = $this->settingsService->getUserEnabled($this->userId);

$resp = array();
Expand Down
67 changes: 50 additions & 17 deletions lib/Settings/Personal.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,41 @@

use OCP\EventDispatcher\IEventDispatcher;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\Settings\ISettings;
use OCP\App\IAppManager;
use OCP\IConfig;
use OCP\IL10N;

use OCA\FaceRecognition\Db\Person;
use OCA\FaceRecognition\Db\PersonMapper;

use OCA\FaceRecognition\Service\SettingsService;

class Personal implements ISettings {

/** @var IEventDispatcher */
private $eventDispatcher;

/** @var IConfig */
protected $config;
/** @var \OCP\AppFramework\Services\IInitialState **/
protected IInitialState $initialState;

/** @var \OCP\App\IAppManager **/
protected $appManager;
/** @var PersonMapper */
protected $personMapper;

/** @var IL10N */
protected $l;
/** @var SettingsService */
protected $settingsService;

protected ?string $userId;

public function __construct(IEventDispatcher $eventDispatcher,
IConfig $config,
IAppManager $appManager,
IL10N $l)
IInitialState $initialState,
PersonMapper $personmapper,
SettingsService $settingsService,
string $userId)
{
$this->eventDispatcher = $eventDispatcher;
$this->config = $config;
$this->appManager = $appManager;
$this->l = $l;
$this->initialState = $initialState;
$this->personMapper = $personmapper;
$this->settingsService = $settingsService;
$this->userId = $userId;
}

public function getPriority()
Expand All @@ -53,9 +60,35 @@ public function getSectionID(): string

public function getForm()
{
$params = [];
$userEnabled = $this->settingsService->getUserEnabled($this->userId);
$unamedCount = 0;
$hiddenCount = 0;

if ($userEnabled) {
$modelId = $this->settingsService->getCurrentFaceModel();
$minClusterSize = $this->settingsService->getMinimumFacesInCluster();

$clusters = $this->personMapper->findUnassigned($this->userId, $modelId);
foreach ($clusters as $cluster) {
$clusterSize = $this->personMapper->countClusterFaces($cluster->getId());
if ($clusterSize >= $minClusterSize)
$unamedCount++;
}

$clusters = $this->personMapper->findIgnored($this->userId, $modelId);
foreach ($clusters as $cluster) {
$clusterSize = $this->personMapper->countClusterFaces($cluster->getId());
if ($clusterSize >= $minClusterSize)
$hiddenCount++;
}
}

$this->initialState->provideInitialState('user-enabled', $userEnabled);
$this->initialState->provideInitialState('has-unamed', $unamedCount > 0);
$this->initialState->provideInitialState('has-hidden', $hiddenCount > 0);

$this->eventDispatcher->dispatch(LoadViewer::class, new LoadViewer());
return new TemplateResponse('facerecognition', 'settings/personal', $params, '');
return new TemplateResponse('facerecognition', 'settings/personal');
}

public function getPanel(): TemplateResponse
Expand Down
76 changes: 33 additions & 43 deletions src/personal.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ var Persons = function (baseUrl) {
this._unassignedClusters = [];
this._ignoredClusters = [];

this._enabled = false;
this._loaded = false;
this._mustReload = false;
};
Expand All @@ -34,9 +33,6 @@ Persons.prototype = {
/*
* View State
*/
isEnabled: function () {
return this._enabled;
},
isLoaded: function () {
return this._loaded;
},
Expand All @@ -50,7 +46,6 @@ Persons.prototype = {
var deferred = $.Deferred();
var self = this;
$.get(this._baseUrl+'/persons').done(function (response) {
self._enabled = response.enabled;
self._persons = response.persons.sort(function(a, b) {
return b.count - a.count;
});
Expand Down Expand Up @@ -216,12 +211,7 @@ Persons.prototype = {
return deferred.promise();
},
unsetActive: function () {
// this._persons = [];

this._activePerson = undefined;

// this._unassignedClusters = [];

this._clustersByName = [];
}
};
Expand All @@ -230,6 +220,10 @@ Persons.prototype = {
* View.
*/
var View = function (persons) {
this._enabled = OCP.InitialState.loadState('facerecognition', 'user-enabled');
this._hasUnamed = OCP.InitialState.loadState('facerecognition', 'has-unamed');
this._hasHidden = OCP.InitialState.loadState('facerecognition', 'has-hidden');

this._persons = persons;
this._observer = lozad('.lozad');
};
Expand Down Expand Up @@ -258,40 +252,17 @@ View.prototype = {
} else {
OC.Notification.showTemporary(t('facerecognition', 'The analysis is disabled. Soon all the information found for facial recognition will be removed.'));
}
self._enabled = enabled;
self.reload();
}
});
},
searchUnassignedClusters: function () {
var self = this;
self._persons.loadUnassignedClusters().done(function () {
if (self._persons.getUnassignedClusters().length > 0) {
var button = $("<button id='show-more-clusters' type='button' class='primary'>" + t('facerecognition', 'Review people found') + "</button>");
$('#optional-buttons-div').append(button);
button.click(function () {
self.renameUnassignedClusterDialog();
});
OC.Notification.showTemporary(t('facerecognition', 'You got some people to recognize'));
}
});
},
searchIgnoredClusters: function () {
var self = this;
self._persons.loadIgnoredClusters().done(function () {
if (self._persons.getIgnoredClusters().length > 0) {
var button = $("<button id='show-ignored-clusters' type='button' class='primary'>" + t('facerecognition', 'Review ignored people') + "</button>");
$('#optional-buttons-div').append(button);
button.click(function () {
self.renameIgnoredClusterDialog();
});
}
});
},
renameUnassignedClusterDialog: function () {
var self = this;
var unassignedClusters = this._persons.getUnassignedClusters();
var cluster = unassignedClusters.shift();
if (cluster === undefined) {
OC.Notification.showTemporary(t('facerecognition', 'You don\'t have more people to recognize.'));
self.renderContent();
if (self._persons.mustReload())
self.reload();
Expand Down Expand Up @@ -330,6 +301,7 @@ View.prototype = {
var ignoredClusters = this._persons.getIgnoredClusters();
var cluster = ignoredClusters.shift();
if (cluster === undefined) {
OC.Notification.showTemporary(t('facerecognition', 'You no longer have people ignored'));
self.renderContent();
if (self._persons.mustReload())
self.reload();
Expand All @@ -349,11 +321,7 @@ View.prototype = {
self.renameIgnoredClusterDialog();
}
} else {
self._persons.setClusterVisibility(cluster.id, false).done(function () {
self.renameIgnoredClusterDialog();
}).fail(function () {
OC.Notification.showTemporary(t('facerecognition', 'There was an error ignoring this person'));
});
self.renameIgnoredClusterDialog();
}
} else {
// Cancelled
Expand All @@ -379,10 +347,14 @@ View.prototype = {
loadingIcon: OC.imagePath('core', 'loading.gif')
};

if (this._persons.isEnabled() === true) {
if (this._enabled === true) {
context.enabled = true;
context.hasUnamed = this._hasUnamed;
context.hasHidden = this._hasHidden;
context.persons = this._persons.getPersons();

context.reviewPeopleMsg = t('facerecognition', 'Review people found');
context.reviewIgnoredMsg = t('facerecognition', 'Review ignored people');
context.emptyMsg = t('facerecognition', 'Your friends have not been recognized yet');
context.emptyHint = t('facerecognition', 'Please, be patient');
}
Expand Down Expand Up @@ -438,6 +410,26 @@ View.prototype = {
}
});

$('#show-more-clusters').click(function () {
self._persons.loadUnassignedClusters().done(function () {
if (self._persons.getUnassignedClusters().length > 0) {
self.renameUnassignedClusterDialog();
} else {
OC.Notification.showTemporary(t('facerecognition', 'You dont have more people to recognize.'));
};
});
});

$('#show-ignored-clusters').click(function () {
self._persons.loadIgnoredClusters().done(function () {
if (self._persons.getIgnoredClusters().length > 0) {
self.renameIgnoredClusterDialog();
} else {
OC.Notification.showTemporary(t('facerecognition', 'You no longer have people ignored'));
};
});
});

$('#facerecognition .file-preview-big').click(function () {
var filename = $(this).data('id');
if (window.event.ctrlKey) {
Expand Down Expand Up @@ -628,8 +620,6 @@ if (personName !== undefined) {
view.renderContent();
persons.load().done(function () {
view.renderContent();
view.searchUnassignedClusters();
view.searchIgnoredClusters();
}).fail(function () {
OC.Notification.showTemporary(t('facerecognition', 'There was an error trying to show your friends'));
});
Expand Down
18 changes: 16 additions & 2 deletions src/templates/personal.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@
</h2>
<input id="enableFacerecognition" name="enableFacerecognition" type="checkbox" class="checkbox" value="1" {{#if enabled}}checked{{/if}}>
<label for="enableFacerecognition">{{enableDescription}}</label><br>
<div id="optional-buttons-div"></div>
<div id="optional-buttons-div">
{{#if hasUnamed}}
<button id="show-more-clusters" type="button" class="primary">{{reviewPeopleMsg}}</button>
{{/if}}
{{#if hasHidden}}
<button id="show-ignored-clusters" type="button" class="primary">{{reviewIgnoredMsg}}</button>
{{/if}}
</div>
<div class="persons-previews">
{{#each persons}}
<div class="person-box" data-id="{{name}}">
Expand All @@ -63,7 +70,14 @@
</h2>
<input id="enableFacerecognition" name="enableFacerecognition" type="checkbox" class="checkbox" value="1" {{#if enabled}}checked{{/if}}>
<label for="enableFacerecognition">{{enableDescription}}</label><br>
<div id="optional-buttons-div"></div>
<div id="optional-buttons-div">
{{#if hasUnamed}}
<button id="show-more-clusters" type="button" class="primary">{{reviewPeopleMsg}}</button>
{{/if}}
{{#if hasHidden}}
<button id="show-ignored-clusters" type="button" class="primary">{{reviewIgnoredMsg}}</button>
{{/if}}
</div>
<div class="emptycontent">
<div class="icon-contacts-dark svg"></div>
<h2>
Expand Down

0 comments on commit 8e3b381

Please sign in to comment.