From 553381eb82709d1d44a04bd9d2d4a9deea7b6c59 Mon Sep 17 00:00:00 2001 From: Cesar Velez Date: Fri, 21 Sep 2018 11:46:59 -0400 Subject: [PATCH] LP#1727345 - fix bibsource when importing or overlaying This addresses several issues that were causing the bib source to either not display correctly on the record page or not save correctly when editing z3950 imports/overlays Refactors passing around of bib source into eg-marc-edit and it's child directive egMarcEditBibsource. Two paths to test: Path A) 1. Import a new bib record from z3950, but via "Edit then Import" 2. Bring up marc editor and choose save w/ bib source. 3. Verify chosen bib source saved correctly on record page. Path B) 1. Mark a record as target for Overlay, go to z3950 import. 2. Make a search, select item for Overlay. 3. Choose Edit z3950 record to bring up marceditor, save with a bib source. 4. Verify chosen bib source saved correctly on record page. Signed-off by: Cesar Velez Signed-off-by: Mike Rylander Signed-off-by: Jane Sandberg --- .../staff/cat/z3950/t_edit_overlay_record.tt2 | 2 +- .../templates/staff/cat/z3950/t_marc_edit.tt2 | 4 +-- .../ui/default/staff/cat/services/marcedit.js | 25 ++++++++++---- .../web/js/ui/default/staff/cat/z3950/app.js | 34 +++++++++++++++---- 4 files changed, 50 insertions(+), 15 deletions(-) diff --git a/Open-ILS/src/templates/staff/cat/z3950/t_edit_overlay_record.tt2 b/Open-ILS/src/templates/staff/cat/z3950/t_edit_overlay_record.tt2 index 7ebc94e5f3..1281b43d75 100644 --- a/Open-ILS/src/templates/staff/cat/z3950/t_edit_overlay_record.tt2 +++ b/Open-ILS/src/templates/staff/cat/z3950/t_edit_overlay_record.tt2 @@ -5,7 +5,7 @@ diff --git a/Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js b/Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js index a3cca7ad80..d288669533 100644 --- a/Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js +++ b/Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js @@ -654,6 +654,7 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap']) dirtyFlag : '=', recordId : '=', marcXml : '=', + bibSource : '=?', onSave : '=', // in-place mode means that the editor is being // used just to munge some MARCXML client-side, rather @@ -719,8 +720,11 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap']) if (newVal != oldVal) egCore.hatch.setItem('cat.marcedit.flateditor', newVal); }); + // necessary to prevent ng-model scope hiding ugliness in egMarcEditBibSource: + $scope.bib_source = { + id : $scope.bibSource ? $scope.bibSource : null + }; $scope.brandNewRecord = false; - $scope.bib_source = null; $scope.record_type = $scope.recordType || 'bre'; $scope.max_undo = $scope.maxUndo || 100; $scope.record_undo_stack = []; @@ -1189,8 +1193,8 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap']) $scope.dirtyFlag = false; $scope.flat_text_marc = $scope.record.toBreaker(); - if ($scope.record_type == 'bre') { - $scope.bib_source = $scope.Record().source(); + if ($scope.record_type == 'bre' && !$scope.brandNewRecord) { + $scope.bib_source.id = $scope.bibSource = rec.source(); //$scope.Record().source(); } }).then(function(){ @@ -1368,10 +1372,17 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap']) }; $scope.saveRecord = function () { + if ($scope.inPlaceMode) { $scope.marcXml = $scope.record.toXmlString(); + + if ($scope.record_type == 'bre'){ + $scope.bibSource = $scope.bib_source.id; + } + return $timeout(processOnSaveCallbacks); } + $scope.mangle_005(); $scope.Record().editor(egCore.auth.user().id()); $scope.Record().edit_date('now'); @@ -1519,7 +1530,7 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap']) restrict: 'E', replace: true, template: ''+ - ''+ ''+ ''+ '', @@ -1527,9 +1538,11 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap']) function ($scope , egCore) { egCore.pcrud.retrieveAll('cbs', {}, {atomic : true}) - .then(function(list) { $scope.bib_sources = list; }); + .then(function(list) { + $scope.bib_sources = list; + }); - $scope.$watch('bib_source', + $scope.$watch('bib_source.id', function(newVal, oldVal) { if (newVal !== oldVal) { $scope.bre.source(newVal); diff --git a/Open-ILS/web/js/ui/default/staff/cat/z3950/app.js b/Open-ILS/web/js/ui/default/staff/cat/z3950/app.js index 2e67eea345..2de656a5e0 100644 --- a/Open-ILS/web/js/ui/default/staff/cat/z3950/app.js +++ b/Open-ILS/web/js/ui/default/staff/cat/z3950/app.js @@ -68,6 +68,10 @@ function($scope , $q , $location , $timeout , $window, egCore , egGridDataProvi $scope.total_hits = 0; + var bib_sources = null; + egCore.pcrud.retrieveAll('cbs', {}, {atomic : true}) + .then(function(l) { bib_sources = l; }); + var provider = egGridDataProvider.instance({}); provider.get = function(offset, count) { @@ -148,6 +152,16 @@ function($scope , $q , $location , $timeout , $window, egCore , egGridDataProvi $scope.raw_search_impossible = function() { return egZ3950TargetSvc.rawSearchImpossible(); } + + $scope.get_bibsrc_name_from_id = function(bs_id){ + // var sel_bib_src = bib_src.id ? bib_src.list.filter(s => s.id() == bib_src.id) : null; + // TODO can we use arrow syntax yet??? + if (!bs_id) return null; + var cbs = bib_sources.filter(function(s){ return s.id() == bs_id }); + + return (cbs && cbs[0] ? cbs[0].source() : null); + }; + $scope.showRawSearchForm = function() { $uibModal.open({ templateUrl: './cat/z3950/t_raw_search', @@ -218,14 +232,17 @@ function($scope , $q , $location , $timeout , $window, egCore , egGridDataProvi return $scope._import(items[0]['marcxml']); }; - $scope._import = function(marc_xml) { + $scope._import = function(marc_xml,bib_source) { + + var bibsrc_name = $scope.get_bibsrc_name_from_id(bib_source); + var deferred = $q.defer(); egCore.net.request( 'open-ils.cat', 'open-ils.cat.biblio.record.xml.import', egCore.auth.token(), marc_xml, - null, // FIXME bib source + bibsrc_name, null, null, $scope.selectFieldStripGroups() @@ -280,7 +297,9 @@ function($scope , $q , $location , $timeout , $window, egCore , egGridDataProvi $scope.focusMe = true; $scope.record_id = recId; $scope.dirty_flag = false; - $scope.marc_xml = items[0]['marcxml']; + $scope.args = {}; + $scope.args.marc_xml = items[0]['marcxml']; + $scope.args.bib_source = null; $scope.ok = function(args) { $uibModalInstance.close(args) } $scope.cancel = function () { $uibModalInstance.dismiss() } $scope.save_label = egCore.strings.IMPORT_BUTTON_LABEL; @@ -291,7 +310,7 @@ function($scope , $q , $location , $timeout , $window, egCore , egGridDataProvi // This timeout is required to allow angular to finish variable assignments // in the marcediter app. Allowing marc_xml to propigate here. $timeout( function() { - _import($scope.marc_xml).then( function(record_obj) { + _import($scope.args.marc_xml, $scope.args.bib_source).then( function(record_obj) { if( record_obj.id ) { $scope.record_id = record_obj.id(); $scope.save_label = egCore.strings.SAVE_BUTTON_LABEL; @@ -334,8 +353,10 @@ function($scope , $q , $location , $timeout , $window, egCore , egGridDataProvi var overlay_target = $scope.local_overlay_target; var live_overlay_target = egCore.hatch.getLocalItem('eg.cat.marked_overlay_record') || 0; var args = { - 'marc_xml' : items[0]['marcxml'] + 'marc_xml' : items[0]['marcxml'], + 'bib_source' : null }; + $uibModal.open({ templateUrl: './cat/z3950/t_overlay', backdrop: 'static', @@ -438,13 +459,14 @@ function($scope , $q , $location , $timeout , $window, egCore , egGridDataProvi }] }).result.then(function (args) { + var bibsrc_name = $scope.get_bibsrc_name_from_id(args.bib_source); egCore.net.request( 'open-ils.cat', 'open-ils.cat.biblio.record.marc.replace', egCore.auth.token(), overlay_target, (args.overlay_target.merged ? args.overlay_target.marc_xml : args.marc_xml), - null, // FIXME bib source + bibsrc_name, null, $scope.selectFieldStripGroups() ).then( -- 2.43.2