From 093a4d6e21d575bc1f2dfd3680db7c9e2630eb66 Mon Sep 17 00:00:00 2001 From: Josh Stompro Date: Wed, 27 Feb 2019 15:07:43 -0600 Subject: [PATCH] LP#1798187 - Support CRLF and LF format for item status import files 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 --- Open-ILS/src/templates/staff/cat/item/index.tt2 | 1 + Open-ILS/web/js/ui/default/staff/cat/item/app.js | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Open-ILS/src/templates/staff/cat/item/index.tt2 b/Open-ILS/src/templates/staff/cat/item/index.tt2 index 0a782812fc..1363b1fb3e 100644 --- a/Open-ILS/src/templates/staff/cat/item/index.tt2 +++ b/Open-ILS/src/templates/staff/cat/item/index.tt2 @@ -71,6 +71,7 @@ +
diff --git a/Open-ILS/web/js/ui/default/staff/cat/item/app.js b/Open-ILS/web/js/ui/default/staff/cat/item/app.js index 19e45f921a..4550d9c4b5 100644 --- a/Open-ILS/web/js/ui/default/staff/cat/item/app.js +++ b/Open-ILS/web/js/ui/default/staff/cat/item/app.js @@ -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; } -- 2.11.0