From 056e4d6850834fbca198d66f4b7c6ea2766787ac Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 8 Aug 2017 23:24:00 -0400 Subject: [PATCH] recent patrons wip Signed-off-by: Bill Erickson --- Open-ILS/src/templates/staff/navbar.tt2 | 2 +- .../web/js/ui/default/staff/circ/patron/app.js | 39 ++++++++++++++-------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/Open-ILS/src/templates/staff/navbar.tt2 b/Open-ILS/src/templates/staff/navbar.tt2 index da27a17b56..096b5a3429 100644 --- a/Open-ILS/src/templates/staff/navbar.tt2 +++ b/Open-ILS/src/templates/staff/navbar.tt2 @@ -123,7 +123,7 @@
  • - 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 3329e20ef7..bb8514ec60 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 @@ -98,12 +98,6 @@ angular.module('egPatronApp', ['ngRoute', 'ui.bootstrap', resolve : resolver }); - $routeProvider.when('/circ/patron/recent', { - templateUrl: './circ/patron/t_search', - controller: 'PatronSearchCtrl', - resolve : resolver - }); - // the following require a patron ID $routeProvider.when('/circ/patron/:id/alerts', { @@ -298,7 +292,21 @@ function($q , $timeout , $location , egCore, egUser , $locale) { return $q.when(); } + // Set the show-recent flag true only once, then set it to + // false the first time it's used. + service.showRecentPatrons = function() { + if (service.showRecent === undefined + && Boolean($location.path().match(/search/)) + && Boolean($location.search().show_recent)) + service.showRecent = true; + + return service.showRecent; + } + service.getRecentPatrons = function() { + // avoid getting stuck in a show-recent loop + service.showRecent = false; + if (service.maxRecentPatrons < 1) return $q.when(); var patrons = egCore.hatch.getLoginSessionItem('eg.circ.recent_patrons') || []; @@ -337,6 +345,11 @@ function($q , $timeout , $location , egCore, egUser , $locale) { 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 + + // remove any other occurrences of user_id + var idx = patrons.indexOf(user_id, 1); + if (idx > 0) patrons.splice(idx, 1); + egCore.hatch.setLoginSessionItem('eg.circ.recent_patrons', patrons); } @@ -942,9 +955,6 @@ 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; @@ -977,7 +987,7 @@ function($scope, $q, $routeParams, $timeout, $window, $location, egCore, var propagate; var propagate_inactive; - if (patronSvc.lastSearch && !$scope.showRecentPatrons) { + if (patronSvc.lastSearch && !patronSvc.showRecentPatrons()) { propagate = patronSvc.lastSearch.search; // home_ou needs to be treated specially propagate.home_ou = { @@ -1032,8 +1042,10 @@ function($scope, $q, $routeParams, $timeout, $window, $location, egCore, provider.get = function(offset, count) { var deferred = $q.defer(); - if ($scope.showRecentPatrons) + if (patronSvc.showRecentPatrons()) { + // avoid getting stuck in show-recent mode return patronSvc.getRecentPatrons(); + } var fullSearch; if (patronSvc.urlSearch) { @@ -1814,8 +1826,9 @@ function($scope, $routeParams , $location , egCore , patronSvc) { ['$scope','$location','egCore', function($scope , $location , egCore) { - var id = egCore.hatch.getLoginSessionItem('eg.circ.last_patron'); - if (id) return $location.path('/circ/patron/' + id + '/checkout'); + var ids = egCore.hatch.getLoginSessionItem('eg.circ.recent_patrons') || []; + if (ids.length) + return $location.path('/circ/patron/' + ids[0] + '/checkout'); $scope.no_last = true; }]) -- 2.11.0