recent patrons wip
authorBill Erickson <berickxx@gmail.com>
Wed, 9 Aug 2017 03:24:00 +0000 (23:24 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 9 Aug 2017 03:24:00 +0000 (23:24 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/templates/staff/navbar.tt2
Open-ILS/web/js/ui/default/staff/circ/patron/app.js

index da27a17..096b5a3 100644 (file)
             </a>
           </li>
           <li ng-if="showRecentPatrons">
-            <a href="./circ/patron/recent" target="_self"
+            <a href="./circ/patron/search?show_recent=1" target="_self"
               eg-accesskey="[% l('f8') %]" 
               eg-accesskey-desc="[% l('Retrieve Recent Patrons') %]">
               <span class="glyphicon glyphicon-share-alt"></span>
index 3329e20..bb8514e 100644 (file)
@@ -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;
 }])