recent patrons wip
authorBill Erickson <berickxx@gmail.com>
Sun, 6 Aug 2017 20:37:27 +0000 (16:37 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 9 Aug 2017 02:12:56 +0000 (22:12 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.data.recent-patrons.sql
Open-ILS/web/js/ui/default/staff/circ/patron/app.js

index c40c86d..34ca281 100644 (file)
@@ -17103,3 +17103,31 @@ VALUES (
 );
 
 INSERT INTO config.copy_tag_type (code, label, owner) VALUES ('bookplate', 'Digital Bookplate', 1);
+
+INSERT INTO config.org_unit_setting_type
+    (name, label, description, grp, datatype)
+VALUES (
+    'ui.staff.max_recent_patrons',
+    oils_i18n_gettext(
+        'ui.staff.max_recent_patrons',
+        'Number of Retrievable Recent Patrons',
+        'coust',
+        'label'
+    ),
+    oils_i18n_gettext(
+        'ui.staff.max_recent_patrons',
+        'Number of most recently accessed patrons that can be re-retrieved ' ||
+        'in the staff client.  A value of 0 or less disables the feature',
+        'coust',
+        'description'
+    ),
+    'circ',
+    'integer'
+);
+
+-- For backwards compat apply a max count value of 1 globally.
+INSERT INTO actor.org_unit_setting (org_unit, name, value) 
+    SELECT id, 'ui.staff.max_recent_patrons', '1' 
+        FROM actor.org_unit WHERE parent_ou IS NULL;
+
+
index 26548f4..8179879 100644 (file)
@@ -1,6 +1,7 @@
 BEGIN;
 
 -- SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
 INSERT INTO config.org_unit_setting_type
     (name, label, description, grp, datatype)
 VALUES (
@@ -13,14 +14,18 @@ VALUES (
     ),
     oils_i18n_gettext(
         'ui.staff.max_recent_patrons',
-        'Number of most recently accessed patrons that can be re-retrieved in the staff client.  A value of 0 or less disables the feature',
+        'Number of most recently accessed patrons that can be re-retrieved ' ||
+        'in the staff client.  A value of 0 or less disables the feature',
         'coust',
         'description'
     ),
-    'opac',
+    'circ',
     'integer'
 );
 
-
+-- For backwards compat apply a max count value of 1 globally.
+INSERT INTO actor.org_unit_setting (org_unit, name, value) 
+    SELECT id, 'ui.staff.max_recent_patrons', '1' 
+        FROM actor.org_unit WHERE parent_ou IS NULL;
 
 COMMIT;
index 8c991d9..34acd7f 100644 (file)
@@ -298,6 +298,30 @@ function($q , $timeout , $location , egCore,  egUser , $locale) {
         return $q.when();
     }
 
+    service.getRecentPatrons = function() {
+        if (service.maxRecentPatrons < 1) return $q.when();
+        var patrons = 
+            egCore.hatch.getLoginSessionItem('eg.circ.recent_patrons') || [];
+
+        var deferred = $q.defer();
+        function getNext() {
+            if (patrons.length == 0) {
+                deferred.resolve();
+                return;
+            }
+            console.debug('getRecentPatrons fetching ' + patrons[0]);
+            egUser.get(patrons[0]).then(function(usr) { // fetch first user
+                deferred.notify(usr);
+                patrons.splice(0, 1); // remove first user from list
+                getNext();
+            });
+        }
+
+        getNext();
+        return deferred.promise;
+    }
+
+
     // sets the primary display user, fetching data as necessary.
     service.setPrimary = function(id, user, force) {
         var user_id = id ? id : (user ? user.id() : null);
@@ -307,8 +331,14 @@ function($q , $timeout , $location , egCore,  egUser , $locale) {
         if (!user_id) return $q.reject();
 
         // when loading a new patron, update the last patron setting
-        if (!service.current || service.current.id() != user_id)
-            egCore.hatch.setLoginSessionItem('eg.circ.last_patron', user_id);
+        if (service.maxRecentPatrons > 0 &&
+            (!service.current || service.current.id() != user_id)) {
+            var patrons = 
+                egCore.hatch.getLoginSessionItem('eg.circ.recent_patrons') || [];
+            patrons.splice(0, 0, user_id);  // put this user at front
+            patrons.splice(service.maxRecentPatrons, 1); // remove excess
+            egCore.hatch.setLoginSessionItem('eg.circ.recent_patrons', patrons);
+        }
 
         // avoid running multiple retrievals for the same patron, which
         // can happen during dbl-click by maintaining a single running
@@ -653,6 +683,12 @@ function($scope,  $q , $location , $filter , egCore , egNet , egUser , egAlertDi
         $scope.aous = egCore.env.aous;
         $scope.auth_user_id = egCore.auth.user().id();
 
+        // max recents setting is loaded during startup.
+        // cache it in a local variable for ease of access.
+        egCore.org.settings('ui.staff.max_recent_patrons').then(function(s) {
+            patronSvc.maxRecentPatrons = s['ui.staff.max_recent_patrons'] || 0;
+        });
+
         if (patron_id) {
             $scope.patron_id = patron_id;
             return patronSvc.setPrimary($scope.patron_id)
@@ -906,6 +942,9 @@ function($scope,  $q,  $routeParams,  $timeout,  $window,  $location,  egCore,
         home_ou : egCore.org.tree()
     };
 
+    $scope.showRecentPatrons = 
+        Boolean($location.path().match(/patron\/recent/));
+
     // last used patron search form element
     var lastFormElement;
 
@@ -938,7 +977,7 @@ function($scope,  $q,  $routeParams,  $timeout,  $window,  $location,  egCore,
 
     var propagate;
     var propagate_inactive;
-    if (patronSvc.lastSearch) {
+    if (patronSvc.lastSearch && !$scope.showRecentPatrons) {
         propagate = patronSvc.lastSearch.search;
         // home_ou needs to be treated specially
         propagate.home_ou = {
@@ -993,6 +1032,9 @@ function($scope,  $q,  $routeParams,  $timeout,  $window,  $location,  egCore,
     provider.get = function(offset, count) {
         var deferred = $q.defer();
 
+        if ($scope.showRecentPatrons)
+            return patronSvc.getRecentPatrons();
+
         var fullSearch;
         if (patronSvc.urlSearch) {
             fullSearch = patronSvc.urlSearch;