From 5b96eef17abe4a3f4de0c516d0b972a2c11a5e32 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Sun, 6 Aug 2017 16:37:27 -0400 Subject: [PATCH] recent patrons wip Signed-off-by: Bill Erickson --- Open-ILS/src/sql/Pg/950.data.seed-values.sql | 28 +++++++++++++ .../sql/Pg/upgrade/XXXX.data.recent-patrons.sql | 11 +++-- .../web/js/ui/default/staff/circ/patron/app.js | 48 ++++++++++++++++++++-- 3 files changed, 81 insertions(+), 6 deletions(-) diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index c40c86dbcc..34ca281fb2 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -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; + + diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.recent-patrons.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.recent-patrons.sql index 26548f48dc..81798796f3 100644 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.recent-patrons.sql +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.recent-patrons.sql @@ -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; diff --git a/Open-ILS/web/js/ui/default/staff/circ/patron/app.js b/Open-ILS/web/js/ui/default/staff/circ/patron/app.js index 8c991d9eb9..34acd7fcda 100644 --- a/Open-ILS/web/js/ui/default/staff/circ/patron/app.js +++ b/Open-ILS/web/js/ui/default/staff/circ/patron/app.js @@ -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; -- 2.11.0