LP#1522638 Bib holds egProgressDialog API updates
authorBill Erickson <berickxx@gmail.com>
Fri, 3 Mar 2017 15:34:26 +0000 (10:34 -0500)
committerKathy Lussier <klussier@masslnc.org>
Mon, 6 Mar 2017 18:46:41 +0000 (13:46 -0500)
1. Use the new egProgressDialog name and the new increment() function.
2. Open the dialog before data retrieval starts to better indicate work
   is happening.
3. Close the dialog in promise.finally() to ensure it always closes.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Terran McCanna <tmccanna@georgialibraries.org>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/web/js/ui/default/staff/cat/catalog/app.js

index 4fadbb4..54f6396 100644 (file)
@@ -245,10 +245,10 @@ function($scope , $routeParams , $location , $window , $q , egCore) {
 }])
 .controller('CatalogCtrl',
        ['$scope','$routeParams','$location','$window','$q','egCore','egHolds','egCirc','egConfirmDialog','ngToast',
-        'egGridDataProvider','egHoldGridActions','egProgressModal','$timeout','$uibModal','holdingsSvc','egUser','conjoinedSvc',
+        'egGridDataProvider','egHoldGridActions','egProgressDialog','$timeout','$uibModal','holdingsSvc','egUser','conjoinedSvc',
         '$cookies',
 function($scope , $routeParams , $location , $window , $q , egCore , egHolds , egCirc , egConfirmDialog , ngToast ,
-         egGridDataProvider , egHoldGridActions ,egProgressModal, $timeout , $uibModal , holdingsSvc , egUser , conjoinedSvc,
+         egGridDataProvider , egHoldGridActions , egProgressDialog , $timeout , $uibModal , holdingsSvc , egUser , conjoinedSvc,
          $cookies
 ) {
 
@@ -1364,6 +1364,10 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
         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});
+
         // fetch the IDs
         egCore.net.request(
             'open-ils.circ',
@@ -1372,15 +1376,25 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
             {pickup_lib : egCore.org.descendants($scope.pickup_ou.id(), true)}
         ).then(
             function(hold_data) {
-                if(hold_data.title_holds.length){
-                    egProgressModal.open().result;};
                 angular.forEach(hold_data, function(list, type) {
                     hold_ids = hold_ids.concat(list);
                 });
-                fetchHolds(offset, count).then(
-                    deferred.resolve, null, deferred.notify).then(function(){
-                    egProgressModal.close();
-                    });
+
+                // 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'](egProgressDialog.close);
             }
         );