LP#1758381: Force copy bucket pending list to scan order user/mccanna/lp1758381_copy_bucket_pending_order_signoff
authorMike Rylander <mrylander@gmail.com>
Wed, 20 May 2020 21:13:36 +0000 (17:13 -0400)
committerTerran McCanna <tmccanna@georgialibraries.org>
Mon, 10 Aug 2020 16:45:18 +0000 (12:45 -0400)
The order of rows in the pending list of copy buckets is currently
undefined and, due to the way the query is constructed, looks random.
This commit adds the ability to force a specific order on the contents
of a grid and uses that ability to match the grid row order to the scan
order.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Terran McCanna <tmccanna@georgialibraries.org>
Open-ILS/web/js/ui/default/staff/cat/bucket/copy/app.js
Open-ILS/web/js/ui/default/staff/services/grid.js

index e7aeccd..0174cc2 100644 (file)
@@ -393,6 +393,9 @@ function($scope,  $routeParams,  bucketSvc , egGridDataProvider,   egCore) {
 
     var query;
     $scope.gridControls = {
+        forceOrder : function () {
+            return { field : 'id', order : bucketSvc.pendingList };
+        },
         setQuery : function(q) {
             if (bucketSvc.pendingList.length)
                 return {id : bucketSvc.pendingList};
@@ -485,8 +488,11 @@ function($scope,  $routeParams,  bucketSvc , egGridDataProvider,   egCore) {
                 {}
             ).then(function(copy) {
                 if (copy) {
-                    bucketSvc.pendingList.push(copy.id());
-                    $scope.gridControls.setQuery({id : bucketSvc.pendingList});
+                    var seen = bucketSvc.pendingList.filter(function (e) { return e == copy.id()}).length;
+                    if (!seen) {
+                        bucketSvc.pendingList.push(copy.id());
+                        $scope.gridControls.setQuery({id : bucketSvc.pendingList});
+                    }
                     bucketSvc.barcodeString = ''; // clear form on valid copy
                 } else {
                     $scope.context.itemNotFound = true;
index ce84caa..0b8f24c 100644 (file)
@@ -1339,6 +1339,24 @@ angular.module('egGridMod',
                             $scope.selected[grid.indexValue(item)] = true
                     }
                 }).finally(function() { 
+                    if (grid.controls.forceOrder) {
+                        var f = grid.controls.forceOrder().field;
+                        var o = grid.controls.forceOrder().order;
+                        var ordered_items = [];
+                        angular.forEach(o, function(v) {
+                            ov = $scope.items.filter(function (i) {
+                                var test_val = i[f];
+                                if (angular.isFunction(test_val)) {
+                                    test_val = i[f]();
+                                }
+                                return v == test_val;
+                            });
+                            if (ov && angular.isArray(ov)) {
+                                ordered_items.push(ov[0])
+                            }
+                        });
+                        $scope.items = ordered_items;
+                    }
                     console.debug('egGrid.collect() complete');
                     grid.collecting = false 
                     $scope.selected = angular.copy($scope.selected);