offline: WebSockets + no network = chaos
authorMike Rylander <mrylander@gmail.com>
Fri, 7 Jul 2017 15:49:55 +0000 (11:49 -0400)
committerMike Rylander <mrylander@gmail.com>
Fri, 7 Jul 2017 15:53:08 +0000 (11:53 -0400)
Check for specific network and UI conditions and avoid using WebSockets when
they would freeze the offline interface.

Also, correct a typo in file loading.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/templates/staff/index.tt2
Open-ILS/web/js/ui/default/staff/offline.js
Open-ILS/web/js/ui/default/staff/services/auth.js

index bcb7a14..cd65d7a 100644 (file)
@@ -6,7 +6,7 @@
 
 [% BLOCK APP_JS %]
 <!-- splash / login page app -->
-<script src="[% ctx.media_prefix %]/js/ui/default/staff/services/egLovefield.js"></script>
+<script src="[% ctx.media_prefix %]/js/ui/default/staff/services/lovefield.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/app.js"></script>
 [% END %]
 
index a4eef87..dab4065 100644 (file)
@@ -254,6 +254,14 @@ function($routeProvider , $locationProvider , $compileProvider) {
     function($q , $scope , $window , $location , $rootScope , egCore , egLovefield , $routeParams , $timeout , $http , ngToast , egConfirmDialog , egUnloadPrompt) {
         $scope.active_tab = $routeParams.tab || 'checkout';
 
+        // Immediately redirect if we're really offline
+        if (!$window.navigator.onLine) {
+            if ($location.path().match(/session$/)) {
+                var path = $location.path();
+                return $location.path(path.replace('session','checkout'));
+            }
+        }
+
         var today = new Date();
         today.setHours(0);
         today.setMinutes(0);
index 4e98956..3ee2296 100644 (file)
@@ -61,23 +61,33 @@ function($q , $timeout , $rootScope , $window , $location , egNet , egHatch) {
 
         if (token) {
 
-            egNet.request(
-                'open-ils.auth',
-                'open-ils.auth.session.retrieve', token)
-
-            .then(function(user) {
-                if (user && user.classname) {
-                    // authtoken test succeeded
-                    service.user(user);
-                    service.poll();
-                    service.check_workstation(deferred);
-
-                } else {
-                    // authtoken test failed
-                    egHatch.clearLoginSessionItems();
-                    deferred.reject(); 
-                }
-            });
+            if (lf.isOffline && !$location.path().match(/\/session/) ) {
+                // Just stop here if we're in the offline interface but not on the session tab
+                $timeout(function(){deferred.resolve()});
+            } else if (lf.isOffline && $location.path().match(/\/session/) && !$window.navigator.onLine) {
+                // Likewise, if we're in the offline interface on the session tab and the network is down.
+                // The session tab itself will redirect appropriately due to no network.
+                $timeout(function(){deferred.resolve()});
+            } else {
+                // Otherwise, check the token.  This will freeze all other interfaces, which is what we want.
+                egNet.request(
+                    'open-ils.auth',
+                    'open-ils.auth.session.retrieve', token)
+    
+                .then(function(user) {
+                    if (user && user.classname) {
+                        // authtoken test succeeded
+                        service.user(user);
+                        service.poll();
+                        service.check_workstation(deferred);
+    
+                    } else {
+                        // authtoken test failed
+                        egHatch.clearLoginSessionItems();
+                        deferred.reject(); 
+                    }
+                });
+            }
 
         } else {
             // no authtoken to test