diff --git a/lib/Controller/ClusterController.php b/lib/Controller/ClusterController.php index cffb12a4..665f7605 100644 --- a/lib/Controller/ClusterController.php +++ b/lib/Controller/ClusterController.php @@ -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(); diff --git a/lib/Settings/Personal.php b/lib/Settings/Personal.php index 4762e444..36e8d188 100644 --- a/lib/Settings/Personal.php +++ b/lib/Settings/Personal.php @@ -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() @@ -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 diff --git a/src/personal.js b/src/personal.js index 6c963d28..eab71f0c 100644 --- a/src/personal.js +++ b/src/personal.js @@ -25,7 +25,6 @@ var Persons = function (baseUrl) { this._unassignedClusters = []; this._ignoredClusters = []; - this._enabled = false; this._loaded = false; this._mustReload = false; }; @@ -34,9 +33,6 @@ Persons.prototype = { /* * View State */ - isEnabled: function () { - return this._enabled; - }, isLoaded: function () { return this._loaded; }, @@ -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; }); @@ -216,12 +211,7 @@ Persons.prototype = { return deferred.promise(); }, unsetActive: function () { -// this._persons = []; - this._activePerson = undefined; - -// this._unassignedClusters = []; - this._clustersByName = []; } }; @@ -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'); }; @@ -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 = $(""); - $('#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 = $(""); - $('#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(); @@ -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(); @@ -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 @@ -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'); } @@ -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) { @@ -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')); }); diff --git a/src/templates/personal.handlebars b/src/templates/personal.handlebars index 23537524..e93ca809 100644 --- a/src/templates/personal.handlebars +++ b/src/templates/personal.handlebars @@ -45,7 +45,14 @@
-
+
+ {{#if hasUnamed}} + + {{/if}} + {{#if hasHidden}} + + {{/if}} +
{{#each persons}}
@@ -63,7 +70,14 @@
-
+
+ {{#if hasUnamed}} + + {{/if}} + {{#if hasHidden}} + + {{/if}} +