LP#1775870 Fixes random sort order for print labels, picking up the sort field user/dpearl/LP1775870_print_label_order-signoff
authorAdam Bowling <abowling@emeralddata.net>
Wed, 13 Feb 2019 17:40:17 +0000 (12:40 -0500)
committerDan Pearl <dpearl@cwmars.org>
Thu, 23 May 2019 19:49:59 +0000 (15:49 -0400)
specified by the user in the source grid supplying the copies. In the case that
no sort field was clicked, copies are loaded into the label print interface in
ascending order from oldest to newest entry on the source grid.

This branch is dependent on the spine label customizations submitted in
a=commit;h=ace4c873538c95459fdba5439a6167fe665551c1.

Signed-off-by: Adam Bowling <abowling@emeralddata.net>
Signed-off-by: Dan Pearl <dpearl@cwmars.org>
Open-ILS/web/js/ui/default/staff/cat/bucket/copy/app.js [changed mode: 0644->0755]
Open-ILS/web/js/ui/default/staff/cat/catalog/app.js [changed mode: 0644->0755]
Open-ILS/web/js/ui/default/staff/cat/item/app.js [changed mode: 0644->0755]
Open-ILS/web/js/ui/default/staff/cat/printlabels/app.js [changed mode: 0644->0755]
Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js [changed mode: 0644->0755]
Open-ILS/web/js/ui/default/staff/circ/checkin/app.js [changed mode: 0644->0755]
Open-ILS/web/js/ui/default/staff/circ/services/item.js [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 70eb084..a900f26
@@ -586,24 +586,41 @@ function($scope,  $q , $routeParams , $timeout , $window , $uibModal , bucketSvc
         });
     }
 
-    $scope.print_labels = function() {
-        var cp_list = []
+    $scope.print_labels = function () {
+        var cp_list = [];
         angular.forEach($scope.gridControls.selectedItems(), function (i) {
             cp_list.push(i.id);
         })
 
-        egCore.net.request(
-            'open-ils.actor',
-            'open-ils.actor.anon_cache.set_value',
-            null, 'print-labels-these-copies', {
-                copies : cp_list
-            }
-        ).then(function(key) {
-            if (key) {
-                var url = egCore.env.basePath + 'cat/printlabels/' + key;
-                $timeout(function() { $window.open(url, '_blank') });
+        var cp_full = [], promises = [];
+        promises.push(
+            egCore.pcrud.search('ccbi', { bucket: bucketSvc.currentBucket.a[2], "target_copy": { "in": cp_list } }).then(
+                null
+                , null
+                , function (ccbi) {
+                    cp_full.push(egCore.idl.toHash(ccbi, true));
+                }
+            )
+        );
+
+        $q.all(promises).then(function () {
+            if (cp_full.length > 0) {
+                egCore.net.request(
+                    'open-ils.actor',
+                    'open-ils.actor.anon_cache.set_value',
+                    null, 'print-labels-these-copies', {
+                        copies: cp_full
+                    }
+                ).then(function (key) {
+                    if (key) {
+                        var url = egCore.env.basePath + 'cat/printlabels/' + key;
+                        $timeout(function () { $window.open(url, '_blank') });
+                    } else {
+                        alert('Could not create anonymous cache key!');
+                    }
+                });
             } else {
-                alert('Could not create anonymous cache key!');
+                alert('Could not create print label export.');
             }
         });
     }
old mode 100644 (file)
new mode 100755 (executable)
index 2988d95..3bd142f
@@ -1638,18 +1638,37 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
     }
 
     $scope.selectedHoldingsPrintLabels = function() {
-        egCore.net.request(
-            'open-ils.actor',
-            'open-ils.actor.anon_cache.set_value',
-            null, 'print-labels-these-copies', {
-                copies : gatherSelectedHoldingsIds()
-            }
-        ).then(function(key) {
-            if (key) {
-                var url = egCore.env.basePath + 'cat/printlabels/' + key;
-                $timeout(function() { $window.open(url, '_blank') });
+        var cp_list = gatherSelectedHoldingsIds();
+
+        var cp_full = [], promises = [];
+        promises.push(
+            egCore.pcrud.search('ccbi', { bucket: $scope.bucket_id, "target_copy": { "in": cp_list } }).then(
+                null
+                , null
+                , function (ccbi) {
+                    cp_full.push(egCore.idl.toHash(ccbi, true));
+                }
+            )
+        );
+
+        $q.all(promises).then(function () {
+            if (cp_full.length > 0) {
+                egCore.net.request(
+                    'open-ils.actor',
+                    'open-ils.actor.anon_cache.set_value',
+                    null, 'print-labels-these-copies', {
+                        copies: cp_full
+                    }
+                ).then(function (key) {
+                    if (key) {
+                        var url = egCore.env.basePath + 'cat/printlabels/' + key;
+                        $timeout(function () { $window.open(url, '_blank') });
+                    } else {
+                        alert('Could not create anonymous cache key!');
+                    }
+                });
             } else {
-                alert('Could not create anonymous cache key!');
+                alert('Could not create print label export.');
             }
         });
     }
old mode 100644 (file)
new mode 100755 (executable)
index fc3e823..49e94c4
@@ -591,13 +591,21 @@ function($scope , $q , $window , $location , $timeout , egCore , egNet , egGridD
     $scope.transferItems = function (){
         itemSvc.transferItems(copyGrid.selectedItems());
     }
-
+    
     $scope.print_labels = function() {
+        var cp_list = gatherSelectedHoldingsIds();
+        !$scope.gridDataProvider.sort ? cp_list.reverse() : $scope.gridDataProvider.sort.length === 0 ? cp_list.reverse() : false;
+        var i = 1;
+        var cp_full = [];
+        angular.forEach(cp_list, function (copy) {
+            cp_full.push({id: i, target_copy: copy})
+            i++;
+        });
         egCore.net.request(
             'open-ils.actor',
             'open-ils.actor.anon_cache.set_value',
             null, 'print-labels-these-copies', {
-                copies : gatherSelectedHoldingsIds()
+                copies : cp_full
             }
         ).then(function(key) {
             if (key) {
old mode 100644 (file)
new mode 100755 (executable)
index 2553689..a04f2ca
@@ -265,8 +265,9 @@ function ($scope, $q, $window, $routeParams, $location, $timeout, egCore, egNet,
 
                 angular.forEach(data.copies, function (copy) {
                     promises.push(
-                        itemSvc.fetch(null, copy).then(function (res) {
+                        itemSvc.fetch(null, copy.target_copy).then(function (res) {
                             var flat_copy = egCore.idl.toHash(res.copy, true);
+                            flat_copy.copy_bucket_item_id = copy.id;
                             $scope.preview_scope.copies.push(flat_copy);
                             $scope.record_details[flat_copy['call_number.record.id']] = 1;
                         })
@@ -289,6 +290,8 @@ function ($scope, $q, $window, $routeParams, $location, $timeout, egCore, egNet,
                     });
 
                     $q.all(promises2).then(function () {
+                        // sort copies into the order they were entered into the bucket
+                        $scope.preview_scope.copies.sort((a, b) => (a.copy_bucket_item_id > b.copy_bucket_item_id) ? 1 : ((b.copy_bucket_item_id > a.copy_bucket_item_id) ? -1 : 0));
                         // today, staff, current_location, etc.
                         egCore.print.fleshPrintScope($scope.preview_scope);
                         $scope.template_changed(); // load the default
@@ -933,4 +936,4 @@ function getPrintLabelOutputClass(index, settings) {
 
 function getPrintLabelStyle(index, settings) {
     return index > 0 && (index % settings.page.label.set.size === 0) ? settings.page.label.gap.size : "";
-}
\ No newline at end of file
+}
old mode 100644 (file)
new mode 100755 (executable)
index 5923b40..ba3beee
@@ -2009,12 +2009,19 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
             ).then(function(copy_ids) {
                 if (and_exit) {
                     $scope.dirty = false;
+                    !$scope.completedGridDataProvider.sort ? copy_ids.reverse() : $scope.completedGridDataProvider.sort.length === 0 ? copy_ids.reverse() : false;
                     if ($scope.defaults.print_item_labels) {
+                        var cp_full = [];
+                        var i = 1;
+                        angular.forEach(copy_ids, function (copy) {
+                            cp_full.push({ id: i, target_copy: copy });
+                            i++;
+                        });
                         egCore.net.request(
                             'open-ils.actor',
                             'open-ils.actor.anon_cache.set_value',
                             null, 'print-labels-these-copies', {
-                                copies : copy_ids
+                                copies : cp_full
                             }
                         ).then(function(key) {
                             if (key) {
@@ -2187,7 +2194,7 @@ function($scope , $q , $window , $routeParams , $location , $timeout , egCore ,
                         { order_by : { 'acpt' : ['label'] } }, { atomic: true }
                     ).then(function(list) {
                         return list.map(function(item) {
-                            return item.label() + " (" + egCore.org.get(item.owner()).shortname() + ")";
+                            return item.label();
                         });
                     });
                 }
old mode 100644 (file)
new mode 100755 (executable)
index 6d71f6c..452016a
@@ -397,12 +397,18 @@ function($scope , $q , $window , $location , $timeout , egCore , checkinSvc , eg
         });
     }
 
-    $scope.printSpineLabels = function(items){
-        var copy_ids = [];
+    $scope.printSpineLabels = function(items){      
+        var copy_ids = [], cp_full;
         angular.forEach(items, function(item) {
             if (item.acp) copy_ids.push(item.acp.id());
         });
-        itemSvc.print_spine_labels(copy_ids);
+        !$scope.gridDataProvider.sort ? copy_ids.reverse() : $scope.gridDataProvider.sort.length === 0 ? copy_ids.reverse() : false;
+        var i = 0;
+        angular.forEach(copy_ids, function (copy) {
+            cp_full.push({ id: i, target_copy: copy });
+            i++;
+        });
+        itemSvc.print_spine_labels(cp_full);
     }
 
     $scope.addCopyAlerts = function(items) {