LP#1798187 - Support CRLF and LF format for item status import files user/stompro/lp1798187-item-status-barcode-import-crlf
authorJosh Stompro <stompro@stompro.org>
Wed, 27 Feb 2019 21:07:43 +0000 (15:07 -0600)
committerJosh Stompro <stompro@stompro.org>
Tue, 12 Mar 2019 18:45:17 +0000 (13:45 -0500)
Testing Plan:

Before patch, try to import a file in CRLF end of line format that includes
leading and trailing spaces, empty lines, lines of just spaces or
barcodes with spaces.  The import will fail to load those items and will
stop processing when it hits certain situations.

After patch, try to import a file in CRLF EOL format that includes barcodes
with trailing spaces, leading spaces, barcodes with spaces, and/or
empty lines.  The import will load all barcodes.

Signed-off-by: Josh Stompro <stompro@stompro.org>
Open-ILS/src/templates/staff/cat/item/index.tt2
Open-ILS/web/js/ui/default/staff/cat/item/app.js

index 0a78281..1363b1f 100644 (file)
@@ -71,6 +71,7 @@
           <input type="file" eg-file-reader 
             container="barcodesFromFile" value="[% l('Upload from File') %]">
         </div>
+        <eg-help-popover help-text="[% l('File Format: One barcode per line. All whitespace and commas will be removed before processing.') %]">
       </div>
     </div>
     <div class="flex-cell"></div><!-- force the final divs to the right -->
index 19e45f9..4550d9c 100644 (file)
@@ -287,10 +287,14 @@ function($scope , $q , $routeParams , $location , $timeout , $window , egCore ,
             $scope.args.barcode = '';
             var barcodes = [];
 
-            angular.forEach(newVal.split(/\n/), function(line) {
+            angular.forEach(newVal.split(/\r?\n/), function(line) {
+                //remove all whitespace and commas
+                line = line.replace(/[\s,]+/g,'');
+
+                //Or remove leading/trailing whitespace
+                //line = line.replace(/(^[\s,]+|[\s,]+$/g,'');
+
                 if (!line) return;
-                // scrub any trailing spaces or commas from the barcode
-                line = line.replace(/(.*?)($|\s.*|,.*)/,'$1');
                 barcodes.push(line);
             });
 
@@ -299,10 +303,12 @@ function($scope , $q , $routeParams , $location , $timeout , $window , egCore ,
                 var barcode = barcodes.pop();
                 egProgressDialog.increment();
 
-                if (!barcode) { // All done here.
+                if (barcode == undefined) { // All done here.
                     egProgressDialog.close();
                     copyGrid.refresh();
-                    copyGrid.selectItems([itemSvc.copies[0].index]);
+                    if(itemSvc.copies[0]){  // Were any copies actually retrieved
+                        copyGrid.selectItems([itemSvc.copies[0].index]);
+                    }
                     return;
                 }