From 2646e53dafd55d0570253b2356761fb668d8f676 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 20 Jul 2021 10:59:42 -0400 Subject: [PATCH] LP1786971 TCN fetching and maintenance tweaks Avoid storing the TCN value in local storage since it's not needed outside the Z app. Wait for async TCN lookups to complete before using the value. Signed-off-by: Bill Erickson Signed-off-by: Terran McCanna Signed-off-by: Mary Llewellyn --- .../web/js/ui/default/staff/cat/z3950/app.js | 55 +++++++++++++++---- 1 file changed, 44 insertions(+), 11 deletions(-) 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 a43401c032..a410ebe948 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 @@ -197,10 +197,15 @@ function($scope , $q , $location , $timeout , $window, egCore , egGridDataProvi }; $scope.local_overlay_target = egCore.hatch.getLocalItem('eg.cat.marked_overlay_record') || 0; - $scope.local_overlay_target_tcn = egCore.hatch.getLocalItem('eg.cat.marked_overlay_tcn') || 0; + + // Value is immediately replaced below + // $scope.local_overlay_target_tcn = egCore.hatch.getLocalItem('eg.cat.marked_overlay_tcn') || 0; + if($scope.local_overlay_target) { var currTarget = $scope.local_overlay_target; - get_tcn(currTarget); + + get_tcn(currTarget).then( + function(tcn) { $scope.local_overlay_target_tcn = tcn; }); } $scope.mark_as_overlay_target = function() { var items = $scope.gridControls.selectedItems(); @@ -210,19 +215,24 @@ function($scope , $q , $location , $timeout , $window, egCore , egGridDataProvi } else { $scope.local_overlay_target = items[0]['bibid']; var currTarget = items[0] ['bibid']; - get_tcn(currTarget); + get_tcn(currTarget).then( + function(tcn) { $scope.local_overlay_target_tcn = tcn; }); + } egCore.hatch.setLocalItem('eg.cat.marked_overlay_record',$scope.local_overlay_target); - egCore.hatch.setLocalItem('eg.cat.marked_overlay_tcn',$scope.local_overlay_target_tcn); + + // Here we are applying the previous value as the TCN + // since get_tcn() runs asynchronously. + // egCore.hatch.setLocalItem('eg.cat.marked_overlay_tcn',$scope.local_overlay_target_tcn); } + // Returns promise of TCN value function get_tcn(currTarget) { - egCore.pcrud.retrieve('bre', currTarget, { + return egCore.pcrud.retrieve('bre', currTarget, { select: {bre: ['tcn_value']} }).then(function(rec) { - $scope.local_overlay_target_tcn = rec.tcn_value(); + return rec.tcn_value(); }); - return; }; $scope.cant_overlay = function() { @@ -366,11 +376,31 @@ function($scope , $q , $location , $timeout , $window, egCore , egGridDataProvi } $scope.overlay_record = function() { - var items = $scope.gridControls.selectedItems(); + + var live_overlay_target = + egCore.hatch.getLocalItem('eg.cat.marked_overlay_record') || 0; + + if ($scope.local_overlay_target == live_overlay_target) { + // Avoid the extra network call when the target is unchanged. + overlay_record_modal( + $scope.local_overlay_target, $scope.local_overlay_target_tcn); + return; + } + + // Target changed. Fetch the new TCN. + get_tcn(live_overlay_target).then( + function(tcn) { + overlay_record_modal(live_overlay_target, tcn) + } + ); + } + + function overlay_record_modal(live_overlay_target, live_overlay_target_tcn) { + var overlay_target = $scope.local_overlay_target; var overlay_target_tcn = $scope.local_overlay_target_tcn; - var live_overlay_target = egCore.hatch.getLocalItem('eg.cat.marked_overlay_record') || 0; - var live_overlay_target_tcn = egCore.hatch.getLocalItem('eg.cat.marked_overlay_tcn') || 0; + + var items = $scope.gridControls.selectedItems(); var args = { 'marc_xml' : items[0]['marcxml'], 'bib_source' : null @@ -495,7 +525,10 @@ function($scope , $q , $location , $timeout , $window, egCore , egGridDataProvi $scope.local_overlay_target = 0; $scope.local_overlay_target_tcn = 0; egCore.hatch.removeLocalItem('eg.cat.marked_overlay_record'); - egCore.hatch.removeLocalItem('eg.cat.marked_overlay_tcn'); + + // No longer using. + // egCore.hatch.removeLocalItem('eg.cat.marked_overlay_tcn'); + console.debug('overlay complete, target removed'); $window.open('/eg2/staff/catalog/record/' + overlay_target); } -- 2.43.2