LP#1777207: teach prepend() how to reset sorting
authorGalen Charlton <gmc@equinoxinitiative.org>
Fri, 12 Jul 2019 15:08:29 +0000 (11:08 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Fri, 12 Jul 2019 15:08:29 +0000 (11:08 -0400)
This patch gives prepend() an option to reset the sort order
(and offset) and makes the checkin and checkout grids use that option.

The purpose of this is to retain the performance benefit
of prepend(), as otherwise prepend() will do a full collect()
when a sort order is in effect.

On the checkin and checkout grids, due to a quirk of how
sorting in arrayNotifier-based data sources work, the grids
will behave like this:

- User processes a bunch of items, with each new one
  showing up at the top of the list
- User sorts the grid to look at something
- User processes another item. A collect() happens.
  The new item will show up at the top of the list, with the remaining
  items following the previous sort order.
- User processes more items; the prepending will coninue
  and remain fast.

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/web/js/ui/default/staff/circ/checkin/app.js
Open-ILS/web/js/ui/default/staff/circ/patron/checkout.js
Open-ILS/web/js/ui/default/staff/services/grid.js

index 965529b..120690a 100644 (file)
@@ -236,9 +236,9 @@ function($scope , $q , $window , $location , $timeout , egCore , checkinSvc , eg
             if ($scope.trim_list && checkinSvc.checkins.length > 20) {
                 //cut array short at 20 items
                 checkinSvc.checkins.length = 20;
-                checkinGrid.prepend(20);
+                checkinGrid.prepend(true, 20);
             } else {
-                checkinGrid.prepend();
+                checkinGrid.prepend(true);
             }
         },
         function() {
index d79811c..cc0f82c 100644 (file)
@@ -189,7 +189,7 @@ function($scope , $q , $routeParams , egCore , egUser , patronSvc ,
         };
 
         $scope.checkouts.unshift(row_item);
-        $scope.gridDataProvider.prepend();
+        $scope.gridDataProvider.prepend(true);
 
         egCore.hatch.setItem('circ.checkout.strict_barcode', $scope.strict_barcode);
         var options = {check_barcode : $scope.strict_barcode};
index 0d2ce9b..e4bc86a 100644 (file)
@@ -339,8 +339,8 @@ angular.module('egGridMod',
                     grid.collect();
                 }
 
-                controls.prepend = function(limit) {
-                    grid.prepend(limit);
+                controls.prepend = function(resetSort, limit) {
+                    grid.prepend(resetSort, limit);
                 }
 
                 controls.setLimit = function(limit,forget) {
@@ -1327,7 +1327,7 @@ angular.module('egGridMod',
                 });
             }
 
-            grid.prepend = function(limit) {
+            grid.prepend = function(resetSort, limit) {
                 var ran_into_duplicate = false;
                 var sort = grid.dataProvider.sort;
                 if (sort && sort.length) {
@@ -1336,6 +1336,10 @@ angular.module('egGridMod',
                     // was most recently added nor that it
                     // belongs on top of the visible set of rows,
                     // so we default to a full collect()
+                    if (resetSort) { // and offset
+                        grid.dataProvider.sort = [];
+                        grid.offset = 0;
+                    }
                     grid.collect();
                     return;
                 }