From fe6bd467bbf5d5cc14b20056aa8163c55d31121a Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 30 Aug 2018 13:19:03 -0400 Subject: [PATCH] LP#1789747 SharedWorker sanity checks 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 Signed-off-by: Galen Charlton --- Open-ILS/src/templates/staff/navbar.tt2 | 2 +- Open-ILS/web/js/ui/default/staff/app.js | 7 ++++--- Open-ILS/web/js/ui/default/staff/services/env.js | 15 ++++++++++---- .../web/js/ui/default/staff/services/lovefield.js | 6 +++--- .../web/js/ui/default/staff/services/navbar.js | 8 ++++++-- Open-ILS/web/js/ui/default/staff/services/org.js | 23 ++++++++++++++-------- Open-ILS/web/js/ui/default/staff/services/ui.js | 4 ++-- 7 files changed, 42 insertions(+), 23 deletions(-) diff --git a/Open-ILS/src/templates/staff/navbar.tt2 b/Open-ILS/src/templates/staff/navbar.tt2 index 1c47eb008c..99148164ea 100644 --- a/Open-ILS/src/templates/staff/navbar.tt2 +++ b/Open-ILS/src/templates/staff/navbar.tt2 @@ -231,7 +231,7 @@
  • -
  • +
  • [% l('Offline Circulation') %] diff --git a/Open-ILS/web/js/ui/default/staff/app.js b/Open-ILS/web/js/ui/default/staff/app.js index 167e238287..053f4014a6 100644 --- a/Open-ILS/web/js/ui/default/staff/app.js +++ b/Open-ILS/web/js/ui/default/staff/app.js @@ -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 = {}; diff --git a/Open-ILS/web/js/ui/default/staff/services/env.js b/Open-ILS/web/js/ui/default/staff/services/env.js index 1406a19362..cf768b122c 100644 --- a/Open-ILS/web/js/ui/default/staff/services/env.js +++ b/Open-ILS/web/js/ui/default/staff/services/env.js @@ -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 + ); }, }; diff --git a/Open-ILS/web/js/ui/default/staff/services/lovefield.js b/Open-ILS/web/js/ui/default/staff/services/lovefield.js index 561f900af7..707f41a15d 100644 --- a/Open-ILS/web/js/ui/default/staff/services/lovefield.js +++ b/Open-ILS/web/js/ui/default/staff/services/lovefield.js @@ -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 = []; diff --git a/Open-ILS/web/js/ui/default/staff/services/navbar.js b/Open-ILS/web/js/ui/default/staff/services/navbar.js index 52c916fd60..dcc72deaa4 100644 --- a/Open-ILS/web/js/ui/default/staff/services/navbar.js +++ b/Open-ILS/web/js/ui/default/staff/services/navbar.js @@ -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()) { diff --git a/Open-ILS/web/js/ui/default/staff/services/org.js b/Open-ILS/web/js/ui/default/staff/services/org.js index e7467e23e2..36c9ed2e6b 100644 --- a/Open-ILS/web/js/ui/default/staff/services/org.js +++ b/Open-ILS/web/js/ui/default/staff/services/org.js @@ -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; } diff --git a/Open-ILS/web/js/ui/default/staff/services/ui.js b/Open-ILS/web/js/ui/default/staff/services/ui.js index ed5f84f007..59ff1c8414 100644 --- a/Open-ILS/web/js/ui/default/staff/services/ui.js +++ b/Open-ILS/web/js/ui/default/staff/services/ui.js @@ -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_'; -- 2.11.0