LP#1775870 Fixes random sort order for print labels, picking up the sort field
authorAdam Bowling <abowling@emeralddata.net>
Wed, 13 Feb 2019 17:40:17 +0000 (12:40 -0500)
committerChris Sharp <csharp@georgialibraries.org>
Fri, 22 Feb 2019 14:26:37 +0000 (09:26 -0500)
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>
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 f39346e..62a4063
@@ -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 74f7190..6bd266d
@@ -1632,18 +1632,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 a8142b9..bcdfc24
@@ -536,13 +536,21 @@ function($scope , $q , $routeParams , $location , $timeout , $window , egCore ,
     $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 11547dc..92b9b91
@@ -1962,12 +1962,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) {
@@ -2140,7 +2147,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 e9f9f51..4ea1908
@@ -411,12 +411,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) {