get checking for refresh-needed working
authorGalen Charlton <gmc@equinoxinitiative.org>
Thu, 28 May 2020 14:15:02 +0000 (10:15 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Thu, 28 May 2020 14:15:02 +0000 (10:15 -0400)
This cleans up using of the component lifecycle hooks,
but the key to this is using ng-if to conditionally
embed the to-be-staged manager directive, as all that uib-tab
does for inactive tabs is slap a display:none on them.

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/templates/staff/circ/curbside/t_main.tt2
Open-ILS/web/js/ui/default/staff/circ/curbside/directives/to_be_staged_manager.js

index bb1ddb9..5f7eb3b 100644 (file)
@@ -11,7 +11,7 @@
            otherwise selecting the active table won't work cleanly -->
       <uib-tab index="'to-be-staged'" heading="[% l('To Be Staged') %]">
         <div class="container-fluid">
-           <eg-curbside-to-be-staged-manager></eg-curbside-to-be-staged-manager>
+           <eg-curbside-to-be-staged-manager ng-if="active_tab === 'to-be-staged'"></eg-curbside-to-be-staged-manager>
         </div>
       </uib-tab>
       <uib-tab index="'staged'" heading="[% l('Staged And Ready') %]">
index ce101dc..94cca76 100644 (file)
@@ -16,29 +16,42 @@ function($scope , $q , egCurbsideCoreSvc , egCore , egGridDataProvider ,
 
     $scope.wasHandled = {};
     $scope.refreshNeeded = false;
+
     latestTime = undefined;
-    var checkRefresh;
-    checkRefresh = $interval(function() {
-        egCurbsideCoreSvc.get_latest_to_be_staged().then(function(latest) {
-            if (angular.isDefined(latest)) {
-                if (angular.isDefined(latestTime) && latestTime != latest) {
-                    $scope.refreshNeeded = true;
-                }
-                latestTime = latest;
-            }
-        });
-    }, 10000);
-    $scope.$on('$destroy', function() {
+    var checkRefresh = undefined;
+    function startRefreshCheck() {
+        if (!angular.isDefined(checkRefresh)) {
+            checkRefresh = $interval(function() {
+                egCurbsideCoreSvc.get_latest_to_be_staged().then(function(latest) {
+                    if (angular.isDefined(latest)) {
+                        if (angular.isDefined(latestTime) && latestTime != latest) {
+                            $scope.refreshNeeded = true;
+                            stopRefreshCheck();
+                        }
+                        latestTime = latest;
+                    }
+                });
+            }, 1000);
+        }
+    }
+    function stopRefreshCheck() {
         if (angular.isDefined(checkRefresh)) {
             $interval.cancel(checkRefresh);
             checkRefresh = undefined;
-        };
-    });
+        }
+    }
+    this.$onInit = function() {
+        startRefreshCheck();
+    }
+    this.$onDestroy = function() {
+        stopRefreshCheck();
+    }
 
     $scope.gridDataProvider = egGridDataProvider.instance({
         get : function(offset, count) {
             $scope.wasHandled = {};
             $scope.refreshNeeded = false;
+            startRefreshCheck();
             return egCurbsideCoreSvc.get_to_be_staged(offset, count);
         }
     });
@@ -57,7 +70,7 @@ function($scope , $q , egCurbsideCoreSvc , egCore , egGridDataProvider ,
                 ));
                 return;
             } 
-            if (typeof resp == 'undefined') {
+            if (!angular.isDefined(resp)) {
                 ngToast.warning(egCore.strings.$replace(
                     egCore.strings.NOTFOUND_CURBSIDE_MARK_STAGED,
                     { slot_id : id }