var provider = egGridDataProvider.instance({});
var holds = []; // current list of holds
var hold_count = 0;
+ var hold_grid_load_promise;
$scope.hold_grid_data_provider = provider;
$scope.grid_actions = egHoldGridActions;
provider.get = function(offset, count) {
if ($scope.record_tab != 'holds') return $q.when();
+ if (hold_grid_load_promise) {
+ // Active load in progress.
+ console.debug('Exiting concurrent hold fetch');
+ return hold_grid_load_promise;
+ }
+
// see if we have the requested range cached
if (holds[offset]) {
+ console.debug(
+ 'Serving holds from cache with pickup lib', $scope.pickup_ou.id());
return provider.arrayNotifier(holds, offset, count);
}
});
}
+ console.debug(
+ 'Fetching holds from network with PU lib', $scope.pickup_ou.id());
+
egProgressDialog.open({max : 1, value : 0});
var first = true;
- return egHolds.fetch_wide_holds(
+ hold_grid_load_promise = egHolds.fetch_wide_holds(
restrictions,
order_by
).then(function () {
+ hold_grid_load_promise = null;
return provider.arrayNotifier(holds, offset, count);
},
null,
holds.push(new_item);
}
}
- ).finally(egProgressDialog.close);
+ ).finally(function() {
+ hold_grid_load_promise = null;
+ egProgressDialog.close();
+ });
+ return hold_grid_load_promise;
}
$scope.detail_view = function(action, user_data, items) {
// refresh the list of record holds when the pickup lib is changed.
$scope.pickup_ou = egCore.org.get(egCore.auth.user().ws_ou());
$scope.pickup_ou_changed = function(org) {
- $scope.pickup_ou = org;
- holds = []
- hold_count = 0;
- provider.refresh();
+ if ($scope.pickup_ou && $scope.pickup_ou.id() == org.id()) {
+ // This fires on every component render, even though the
+ // value we already have may match. Avoid duplicate lookups.
+ return;
+ }
+
+ var promise = hold_grid_load_promise || $q.when();
+
+ // Avoid refreshing the grid if it's currently loading data.
+ promise.finally(function() {
+
+ // Previous grid data load complete. Timeout gives the
+ // grid a chance to mark itself as load-completed, which
+ // happens after the data load promise is done.
+ setTimeout(function() {
+ console.debug('Refreshing holds after PU lib change to ', org.id());
+ $scope.pickup_ou = org;
+ holds = []
+ hold_count = 0;
+ provider.refresh();
+ });
+ })
}
function map_prefix_to_subhash (h,pf) {