LP#1845556: Spine Label Enhanced Printing Rebase January 2022. Fixes known user/abowling/lp1845556_spine_label_enhanced_printing_final_01_2022
authorAdam Bowling <abowling@emeralddata.net>
Tue, 11 Jan 2022 22:10:11 +0000 (17:10 -0500)
committerAdam Bowling <abowling@emeralddata.net>
Tue, 11 Jan 2022 22:10:11 +0000 (17:10 -0500)
issues in spine label printing.

Signed-off-by: Adam Bowling <abowling@emeralddata.net>
Open-ILS/src/templates/staff/cat/printlabels/t_view.tt2
Open-ILS/web/js/ui/default/staff/cat/catalog/app.js
Open-ILS/web/js/ui/default/staff/cat/item/app.js
Open-ILS/web/js/ui/default/staff/cat/printlabels/app.js
Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js
Open-ILS/web/js/ui/default/staff/circ/checkin/app.js

index 47ccde6..4c720e3 100644 (file)
                             [% l('Manual adjustments may be made here. These do not get saved with templates.') %]<br/>
                         </span>
                     </div>
-                    <div ng-repeat="cn in rendered_call_number_set">
+                    <div ng-repeat="cn in rendered_cn_key_by_copy_id | orderBy:'idx'">
                         <textarea ng-model="cn.value" class="cn-template-text">
                         </textarea>
                     </div>
@@ -267,4 +267,4 @@ label. Use pocket label left margin to identify how much space to provide betwee
           context="preview_scope"></div>
     </div>
     <!-- col -->
-</div>
\ No newline at end of file
+</div>
index ecd0936..947e1b7 100644 (file)
@@ -1676,20 +1676,25 @@ 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') });
-            } else {
-                alert('Could not create anonymous cache key!');
-            }
-        });
+        var cp_list = gatherSelectedHoldingsIds();
+        if (cp_list.length > 0) {
+            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') });
+                } else {
+                    alert('Could not create anonymous cache key!');
+                }
+            });
+        } else {
+            alert('Could not create print label export.');
+        } 
     }
 
     $scope.selectedHoldingsDamaged = function () {
index 8e21e25..5c32cdb 100644 (file)
@@ -712,20 +712,24 @@ function($scope , $q , $window , $location , $timeout , egCore , egNet , egGridD
     }
 
     $scope.print_labels = 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') });
-            } else {
-                alert('Could not create anonymous cache key!');
-            }
-        });
+        var cp_list = gatherSelectedHoldingsIds();
+        !$scope.gridDataProvider.sort ? cp_list.reverse() : $scope.gridDataProvider.sort.length === 0 ? cp_list.reverse() : false;
+        if (cp_list.length > 0) {
+            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') });
+                } else {
+                    alert('Could not create anonymous cache key!');
+                }
+            });
+        }
     }
 
     $scope.print_list = function() {
index 2553689..a91c07c 100644 (file)
@@ -166,17 +166,7 @@ function ($scope, $q, $window, $routeParams, $location, $timeout, egCore, egNet,
                     , 'settings': {}
                     , 'toolbox_settings': JSON.parse(JSON.stringify(toolbox_settings))
                     , 'get_cn_for': function (copy) {
-                        var key = $scope.rendered_cn_key_by_copy_id[copy.id];
-                        if (key) {
-                            var manual_cn = $scope.rendered_call_number_set[key];
-                            if (manual_cn && manual_cn.value) {
-                                return manual_cn.value;
-                            } else {
-                                return '..';
-                            }
-                        } else {
-                            return '...';
-                        }
+                        return document.getElementById('cn_for_copy_' + copy.id).textContent;
                     }
                     , 'get_bib_for': function (copy) {
                         return $scope.record_details[copy['call_number.record.id']];
@@ -290,6 +280,7 @@ function ($scope, $q, $window, $routeParams, $location, $timeout, egCore, egNet,
 
                     $q.all(promises2).then(function () {
                         // today, staff, current_location, etc.
+                        $scope.preview_scope.copies.sort((a, b) => (data.copies.indexOf(a.id) > data.copies.indexOf(b.id)) ? 1 : ((data.copies.indexOf(b.id) > data.copies.indexOf(a.id)) ? -1 : 0));
                         egCore.print.fleshPrintScope($scope.preview_scope);
                         $scope.template_changed(); // load the default
                         $scope.rebuild_cn_set();
@@ -505,24 +496,17 @@ function ($scope, $q, $window, $routeParams, $location, $timeout, egCore, egNet,
     $scope.rebuild_cn_set = function () {
         $timeout(function () {
             $scope.rendered_call_number_set = {};
-            $scope.rendered_cn_key_by_copy_id = {};
+            $scope.rendered_cn_key_by_copy_id = [];
             for (var i = 0; i < $scope.preview_scope.copies.length; i++) {
                 var copy = $scope.preview_scope.copies[i];
-                var rendered_cn = document.getElementById('cn_for_copy_' + copy.id);
-                if (rendered_cn && rendered_cn.textContent) {
-                    var key = rendered_cn.textContent;
-                    if (typeof $scope.rendered_call_number_set[key] == 'undefined') {
-                        $scope.rendered_call_number_set[key] = {
-                            value: key
-                        };
-                    }
-                    $scope.rendered_cn_key_by_copy_id[copy.id] = key;
-                }
+                $scope.rendered_call_number_set[copy["call_number.label"]] = {value : document.getElementById('cn_for_copy_' + copy.id).textContent};
+                $scope.rendered_cn_key_by_copy_id[i] = {idx: 1, id: copy.id, value: document.getElementById('cn_for_copy_' + copy.id).textContent};
             }
             $scope.preview_scope.tickle = Date() + ' ' + Math.random();
         });
     }
 
+
     $scope.redraw_label_table = function () {
         if ($scope.print_label_form.$valid && $scope.print.template_content && $scope.preview_scope) {
             $scope.preview_scope.label_output_copies = labelOutputRowsFilter($scope.preview_scope.copies, $scope.preview_scope.toolbox_settings);
@@ -725,7 +709,9 @@ function ($scope, $q, $window, $routeParams, $location, $timeout, egCore, egNet,
 
 .filter('cn_wrap', function () {
     return function (input, w, h, wrap_type) {
-        var names;
+        var addedElements = 0;
+        /* Pattern matches for LC ([0]) and non-LC ([1]) CNs */
+        var patterns = [/^([A-Z]{1,3})\s*(\d{1,4}(?:\.*\d{1,3})?)\s*(\d[A-Z0-9]{0,3})?(\.*[A-Z]\d{1,3})?(\d[A-Z0-9]{0,3})?([A-Z]\d{1,3})?(.*)?/i, /^([A-Z]+)?\s*(\d+(?:\.\d+)?)\s*(.*)?$/i];
         var prefix = input[0];
         var callnum = input[1];
         var suffix = input[2];
@@ -733,78 +719,70 @@ function ($scope, $q, $window, $routeParams, $location, $timeout, egCore, egNet,
         if (!w) { w = 8; }
         if (!h) { h = 9; }
 
-        /* handle spine labels differently if using LC */
-        if (wrap_type == 'lc' || wrap_type == 3) {
-            /* Establish a pattern where every return value should be isolated on its own line 
-               on the spine label: subclass letters, subclass numbers, cutter numbers, trailing stuff (date) */
-            var patt1 = /^([A-Z]{1,3})\s*(\d+(?:\.\d+)?)\s*(\.[A-Z]\d*)\s*([A-Z]\d*)?\s*(\d\d\d\d(?:-\d\d\d\d)?)?\s*(.*)$/i;
-            var result = callnum.match(patt1);
-            if (result) {
-                callnum = result.slice(1).join('\t');
+        var cn_patt; /* <- regex from patterns to use based on wrap_type */
+        var z = 3; /* <-Text match position in patterns for variable text (7th position in LC regex pattern); default to non-LC (3rd position in non-LC regex pattern) */
+        if (wrap_type === 3 || wrap_type === 'lc') {
+            cn_patt = patterns[0];
+            z = 7;
+        } else {
+            cn_patt = patterns[1];
+        }
+
+        callnum = callnum.replace(/^\s+|\s+$/, "");
+
+
+        var result = callnum.split(/\s+/);
+        if (!result) {
+            var hasDigits = /\d/;
+            var hasSpace = /\s/;
+            if (!hasDigits.test(callnum) && hasSpace.test(callnum)) {
+                result = callnum.split(/\s+/);
             } else {
-                callnum = callnum.split(/\s+/).join('\t');
+                result = [];
+                divideOnCharLen(callnum, result, 0, 0);
             }
+        }
+        prefix ? result.splice(0, 0, prefix) : false;
+        suffix ? result.push(suffix) : false;
+
+        /* Give each line a final check and cleanup if it exceeds width of 'w' */
+        addedElements = 0;
+        for (var i = 0; i < result.length; i++) {
+            if (result[i]) {
+                var dec_test = /(\d+)\.(\d+)/;
+                if (dec_test.test(result[i])) {
+                    var dec_split = result[i].match(dec_test);
+                    result.splice(i, 1, dec_split[1], "." + dec_split[2]);
+                }
+                divideOnCharLen(result[i], result, i, addedElements);
+            }
+        }
+        var output = [];
+        for (var j = 0; j < result.length; j++) {
+            result[j] ? result[j] = result[j].replace(/^\s*(.*?)\s*$/, "$1") : false;
+            result[j] ? output.push(result[j]) : false;
+        }
+        output = output.slice(0, h); /*Limit lines to height in org unit settings (or default) */
 
-            /* If result is null, leave callnum alone. Can't parse this malformed call num */
-        } else {
-            callnum = callnum.split(/\s+/).join('\t');
-        }
-
-        if (prefix) {
-            callnum = prefix + '\t' + callnum;
-        }
-        if (suffix) {
-            callnum += '\t' + suffix;
-        }
-
-        /* At this point, the call number pieces are separated by tab characters.  This allows
-        *  some space-containing constructs like "v. 1" to appear on one line
-        */
-        callnum = callnum.replace(/\t\t/g, '\t');  /* Squeeze out empties */
-        names = callnum.split('\t');
-        var j = 0; var tb = [];
-        while (j < h) {
-
-            /* spine */
-            if (j < w) {
-
-                var name = names.shift();
-                if (name) {
-                    name = String(name);
-
-                    /* if the name is greater than the label width... */
-                    if (name.length > w) {
-                        /* then try to split it on periods */
-                        var sname = name.split(/\./);
-                        if (sname.length > 1) {
-                            /* if we can, then put the periods back in on each splitted element */
-                            if (name.match(/^\./)) sname[0] = '.' + sname[0];
-                            for (var k = 1; k < sname.length; k++) sname[k] = '.' + sname[k];
-                            /* and put all but the first one back into the names array */
-                            names = sname.slice(1).concat(names);
-                            /* if the name fragment is still greater than the label width... */
-                            if (sname[0].length > w) {
-                                /* then just truncate and throw the rest back into the names array */
-                                tb[j] = sname[0].substr(0, w);
-                                names = [sname[0].substr(w)].concat(names);
-                            } else {
-                                /* otherwise we're set */
-                                tb[j] = sname[0];
-                            }
-                        } else {
-                            /* if we can't split on periods, then just truncate and throw the rest back into the names array */
-                            tb[j] = name.substr(0, w);
-                            names = [name.substr(w)].concat(names);
-                        }
+        return output.join('\n');
+
+        function divideOnCharLen(val, arr, index, incr) {
+            var x = 1;
+            while ((val.length / x) > w) {
+                x++;
+            }
+            var charMatch = val.match(new RegExp(".{1," + Math.ceil((val.length / x)) + "}", "g"));
+            if (charMatch) {
+                for (var t = 0; t < charMatch.length; t++) {
+                    if (t === 0) {
+                        arr[index] = charMatch[t];
                     } else {
-                        /* otherwise we're set */
-                        tb[j] = name;
+                        arr.splice((index + t), 0, charMatch[t]);
+                        incr++;
                     }
                 }
             }
-            j++;
         }
-        return tb.join('\n');
     }
 })
 
@@ -933,4 +911,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
+}
index 3a479b7..4b78678 100644 (file)
@@ -2078,6 +2078,7 @@ 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) {
                         egCore.net.request(
                             'open-ils.actor',
index 0cf3439..00fd5b8 100644 (file)
@@ -447,6 +447,7 @@ function($scope , $q , $window , $location , $timeout , egCore , checkinSvc , eg
         angular.forEach(items, function(item) {
             if (item.acp) copy_ids.push(item.acp.id());
         });
+        !$scope.gridDataProvider.sort ? copy_ids.reverse() : $scope.gridDataProvider.sort.length === 0 ? copy_ids.reverse() : false;
         itemSvc.print_spine_labels(copy_ids);
     }