LP#1697954 Items out fetch grids only when needed
authorBill Erickson <berickxx@gmail.com>
Thu, 29 Jun 2017 18:51:40 +0000 (14:51 -0400)
committerMike Rylander <mrylander@gmail.com>
Fri, 30 Jun 2017 14:45:26 +0000 (10:45 -0400)
Avoid forcing a refresh of Items Out grids in cases where the grids will
automatically refresh as a new grid is instantiated.  This prevents the
code from calling redundant data collection APIs, resulting in local
cache's with duplicate data sets.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>

Open-ILS/src/templates/staff/circ/patron/t_items_out.tt2
Open-ILS/web/js/ui/default/staff/circ/patron/items_out.js

index c6b6e62..c8b0d1f 100644 (file)
@@ -5,12 +5,12 @@
       circ list is meant to display -->
   <ul class="nav nav-tabs">
     <li ng-class="{active : items_out_display == 'main'}">
-      <a href ng-click="show_main_list()">
+      <a href ng-click="show_main_list(items_out_display=='alt')">
         [% l('Items Checked Out') %] ({{main_list.length}})
       </a>
     </li>
     <li ng-if="show_alt_circs" ng-class="{active : items_out_display == 'alt'}">
-      <a href ng-click="show_alt_list()">
+      <a href ng-click="show_alt_list(items_out_display=='main')">
         [% l('Other/Special Circulations') %] ({{alt_list.length}})
       </a>
     </li>
index 51f935f..be77ab2 100644 (file)
@@ -55,25 +55,30 @@ function($scope,  $q,  $routeParams,  $timeout,  egCore , egUser,  patronSvc , $
     }
 
     $scope.items_out_display = 'main';
-    $scope.show_main_list = function() {
+    $scope.show_main_list = function(refresh_grid) {
         // don't need a full reset_page() to swap tabs
         $scope.items_out_display = 'main';
         patronSvc.items_out = [];
-        provider.refresh();
+        // only refresh the grid when navigating from a tab that 
+        // shares the same grid.
+        if (refresh_grid) provider.refresh();
     }
 
-    $scope.show_alt_list = function() {
+    $scope.show_alt_list = function(refresh_grid) {
         // don't need a full reset_page() to swap tabs
         $scope.items_out_display = 'alt';
         patronSvc.items_out = [];
-        provider.refresh();
+        // only refresh the grid when navigating from a tab that 
+        // shares the same grid.
+        if (refresh_grid) provider.refresh();
     }
 
     $scope.show_noncat_list = function() {
         // don't need a full reset_page() to swap tabs
         $scope.items_out_display = 'noncat';
         patronSvc.items_out = [];
-        provider.refresh();
+        // Grid refresh is not necessary because switching to the
+        // noncat_list always involves instantiating a new grid.
     }
 
     // Reload the user to pick up changes in items out, fines, etc.
@@ -84,7 +89,7 @@ function($scope,  $q,  $routeParams,  $timeout,  egCore , egUser,  patronSvc , $
         patronSvc.items_out = []; 
         $scope.main_list = [];
         $scope.alt_list = [];
-        provider.refresh() 
+        $timeout(provider.refresh);  // allow scope changes to propagate
     }
 
     var provider = egGridDataProvider.instance({});
@@ -231,6 +236,7 @@ function($scope,  $q,  $routeParams,  $timeout,  egCore , egUser,  patronSvc , $
         var id_list = $scope[$scope.items_out_display + '_list'];
 
         // see if we have the requested range cached
+        // Note this items_out list is reset w/ each items-out tab change
         if (patronSvc.items_out[offset]) {
             return provider.arrayNotifier(
                 patronSvc.items_out, offset, count);