From: a. bellenir Date: Wed, 5 Sep 2018 15:05:03 +0000 (-0400) Subject: merge master X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=refs%2Fheads%2Fuser%2Fabellenir%2Flp1731272-record-reload;p=working%2FEvergreen.git merge master --- f13a48aaefad2c66bd0233202f36233c59c65fa0 diff --cc Open-ILS/web/js/ui/default/staff/cat/catalog/app.js index d171c4b3e4,43af4d568d..743735c31e --- a/Open-ILS/web/js/ui/default/staff/cat/catalog/app.js +++ b/Open-ILS/web/js/ui/default/staff/cat/catalog/app.js @@@ -1655,64 -1705,79 +1704,78 @@@ function($scope , $routeParams , $locat var provider = egGridDataProvider.instance({}); $scope.hold_grid_data_provider = provider; $scope.grid_actions = egHoldGridActions; - $scope.grid_actions.refresh = function () { provider.refresh() }; + $scope.grid_actions.refresh = function () { holds = []; hold_count = 0; provider.refresh() }; $scope.hold_grid_controls = {}; - var hold_ids = []; // current list of holds - function fetchHolds(offset, count) { - var ids = hold_ids.slice(offset, offset + count); - - return egHolds.fetch_holds(ids).then(null, null, - function(hold_data) { - return hold_data; - } - ); - } - + var holds = []; // current list of holds + var hold_count = 0; provider.get = function(offset, count) { if ($scope.record_tab != 'holds') return $q.when(); - var deferred = $q.defer(); - hold_ids = []; // no caching ATM - // open a determinate progress dialog, max value set below. - egProgressDialog.open({max : 1, value : 0}); + // see if we have the requested range cached + if (holds[offset]) { + return provider.arrayNotifier(holds, offset, count); + } - // fetch the IDs - egCore.net.request( - 'open-ils.circ', - 'open-ils.circ.holds.retrieve_all_from_title', - egCore.auth.token(), $scope.record_id, - {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)} - ).then( + hold_count = 0; + holds = []; + var restrictions = { + is_staff_request : 'true', + fulfillment_time : null, + cancel_time : null, + record_id : $scope.record_id, + pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true) + }; + + var order_by = [{ request_time : null }]; + if (provider.sort && provider.sort.length) { + order_by = []; + angular.forEach(provider.sort, function (c) { + if (!angular.isObject(c)) { + if (c.match(/^hold\./)) { + var i = c.replace('hold.',''); + var ob = {}; + ob[i] = null; + order_by.push(ob); + } + } else { + var i = Object.keys(c)[0]; + var direction = c[i]; + if (i.match(/^hold\./)) { + i = i.replace('hold.',''); + var ob = {} + ob[i] = {dir:direction}; + order_by.push(ob); + } + } + }); + } + + egProgressDialog.open({max : 1, value : 0}); + var first = true; + return egHolds.fetch_wide_holds( + restrictions, + order_by + ).then(function () { + return provider.arrayNotifier(holds, offset, count); + }, + null, function(hold_data) { - hold_ids = []; // clear the list of ids, hack to avoid dups - // TODO: fix the underlying problem, which is that - // this gets called twice when switching to the holds - // tab; once explicitly, and once via the change handler - // on the OU selector - angular.forEach(hold_data, function(list, type) { - hold_ids = hold_ids.concat(list); - }); + if (first) { + hold_count = hold_data; + first = false; + egProgressDialog.update({max:hold_count}); + } else { + egProgressDialog.increment(); + var new_item = { id : hold_data.id, hold : hold_data }; + new_item.status_string = + egCore.strings['HOLD_STATUS_' + hold_data.hold_status] + || hold_data.hold_status; - // Set the max value of the progress bar to the lesser of - // the total number of holds to fetch or the page size - // of the grid. - egProgressDialog.update( - {max : Math.min(hold_ids.length, count)}); - - var holds_fetched = 0; - fetchHolds(offset, count) - .then(deferred.resolve, null, - function(hold_data) { - holds_fetched++; - deferred.notify(hold_data); - egProgressDialog.increment(); - } - )['finally'](function(){ setTimeout(egProgressDialog.close); }); + holds.push(new_item); + } } - ); - ).finally(egProgressDialog.close); -- - return deferred.promise; ++ ).finally(function(){ setTimeout(egProgressDialog.close); }); } $scope.detail_view = function(action, user_data, items) {