LP#1789747 SharedWorker sanity checks
authorBill Erickson <berickxx@gmail.com>
Thu, 30 Aug 2018 17:19:03 +0000 (13:19 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Mon, 5 Nov 2018 21:15:16 +0000 (16:15 -0500)
Avoid page load failures when SharedWorkers (for offline mode) are
not supported.  Additionally, disable the Offline Circulation menu
option when SharedWorkers are not supported.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/templates/staff/navbar.tt2
Open-ILS/web/js/ui/default/staff/app.js
Open-ILS/web/js/ui/default/staff/services/env.js
Open-ILS/web/js/ui/default/staff/services/lovefield.js
Open-ILS/web/js/ui/default/staff/services/navbar.js
Open-ILS/web/js/ui/default/staff/services/org.js
Open-ILS/web/js/ui/default/staff/services/ui.js

index 1c47eb0..9914816 100644 (file)
             </a>
           </li>
           <li class="divider"></li>
-          <li>
+          <li ng-class="{disabled : offlineDisabled()}">
             <a href="./offline-interface" target="_self">
               <span class="glyphicon glyphicon-alert"></span>
               <span>[% l('Offline Circulation') %]</span>
index 167e238..053f401 100644 (file)
@@ -48,9 +48,10 @@ function($routeProvider , $locationProvider) {
      * even if the code has been minified */
            ['$scope','$location','$window','egCore','egLovefield',
     function($scope , $location , $window , egCore , egLovefield) {
-        egLovefield.havePendingOfflineXacts() .then(function(eh){
-            $scope.pendingXacts = eh;
-        });
+        egLovefield.havePendingOfflineXacts() .then(
+            function(eh){ $scope.pendingXacts = eh; },
+            function() {} // SharedWorker not supported
+        );
 
         $scope.focusMe = true;
         $scope.args = {};
index 1406a19..cf768b1 100644 (file)
@@ -135,9 +135,14 @@ function($q,  $window , $injector , egAuth,  egPCRUD,  egIDL) {
                 egLovefield = $injector.get('egLovefield');
             }
             //console.debug('About to cache a list of ' + class_ + ' objects...');
-            egLovefield.isCacheGood(class_).then(function(good) {
-                if (!good) egLovefield.setListInOfflineCache(class_, blob.list);
-            });
+            egLovefield.isCacheGood(class_).then(
+                function(good) {
+                    if (!good) {
+                        egLovefield.setListInOfflineCache(class_, blob.list); 
+                    }
+                },
+                function() {} // Not Supported
+            );
         }
 
         angular.forEach(list, function(item) {blob.map[item[pkey]()] = item});
@@ -198,7 +203,9 @@ function($q,  $window , $injector , egAuth,  egPCRUD,  egIDL) {
                         return $q.when();
                     }
                 );
-            });
+            },
+            function() {return $q.when()} // Not Supported, exit gracefully
+            );
         },
     };
 
index 561f900..707f41a 100644 (file)
@@ -27,7 +27,7 @@ angular.module('egCoreMod')
             // relative path would be better...
             service.worker = new SharedWorker(service.workerUrl);
         } catch (E) {
-            console.error('SharedWorker() not supported', E);
+            console.warn('SharedWorker() not supported', E);
             service.cannotConnect = true;
             return;
         }
@@ -65,12 +65,12 @@ angular.module('egCoreMod')
 
     service.connectToSchemas = function() {
 
+        service.connectToWorker(); // no-op if already connected
+
         if (service.cannotConnect) { 
             // This can happen in certain environments
             return $q.reject();
         }
-        
-        service.connectToWorker(); // no-op if already connected
 
         var promises = [];
 
index 52c916f..dcc72de 100644 (file)
@@ -6,9 +6,9 @@ angular.module('egCoreMod')
         transclude : true,
         templateUrl : 'eg-navbar-template',
         controller:['$scope','$window','$location','$timeout','hotkeys','$rootScope',
-                    'egCore','$uibModal','ngToast','egOpChange','$element',
+                    'egCore','$uibModal','ngToast','egOpChange','$element','egLovefield',
             function($scope , $window , $location , $timeout , hotkeys , $rootScope ,
-                     egCore , $uibModal , ngToast , egOpChange , $element) {
+                     egCore , $uibModal , ngToast , egOpChange , $element , egLovefield) {
 
                 $scope.rs = $rootScope;
 
@@ -102,6 +102,10 @@ angular.module('egCoreMod')
                     return true;
                 };
 
+                $scope.offlineDisabled = function() {
+                    return egLovefield.cannotConnect;
+                }
+
                 egCore.startup.go().then(
                     function() {
                         if (egCore.auth.user()) {
index e7467e2..36c9ed2 100644 (file)
@@ -111,14 +111,16 @@ function($q,  egEnv,  egAuth,  egNet , $injector) {
         if (!angular.isArray(names)) names = [names];
 
         if (lf.isOffline) {
-            return egLovefield.getSettingsCache(names)
-                .then(function(settings) {
+            return egLovefield.getSettingsCache(names).then(
+                function(settings) {
                     var hash = {};
                     angular.forEach(settings, function (s) {
                         hash[s.name] = s.value;
                     });
                     return $q.when(hash);
-                });
+                },
+                function() {return $q.when({})} // Not Supported
+            );
         }
 
 
@@ -156,11 +158,16 @@ function($q,  egEnv,  egAuth,  egNet , $injector) {
                 if (here) service.cachedSettings[key] = settings[key];
             });
 
-            return egLovefield.setSettingsCache(settings).then(function() {
-                // resolve with cached settings if 'here', since 'settings'
-                // will only contain settings we had to retrieve
-                deferred.resolve(here ? service.cachedSettings : settings);
-            });
+            return egLovefield.setSettingsCache(settings).then(
+                function() {
+                    // resolve with cached settings if 'here', since 'settings'
+                    // will only contain settings we had to retrieve
+                    deferred.resolve(here ? service.cachedSettings : settings);
+                },
+                function() {
+                    deferred.resolve(here ? service.cachedSettings : settings);
+                }
+            );
         });
         return deferred.promise;
     }
index ed5f84f..59ff1c8 100644 (file)
@@ -1086,8 +1086,8 @@ function($uibModal , $interpolate , egCore) {
 
         templateUrl : './share/t_org_select',
 
-        controller : ['$scope','$timeout','egCore','egStartup','egLovefield','$q',
-              function($scope , $timeout , egCore , egStartup , egLovefield , $q) {
+        controller : ['$scope','$timeout','egCore','egStartup','$q',
+              function($scope , $timeout , egCore , egStartup , $q) {
 
             // See emptyTypeahead directive below.
             var secretEmptyKey = '_INTERNAL_';