From e494dbc57c9771a56c337466132fc05fab5ab7ee Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Thu, 28 Jun 2018 15:44:12 -0400 Subject: [PATCH] (js) Changes for ui-router v1.0 $urlRouterProvider is deprecated. --- .../js/Administration/Administration.app.js | 26 ++++++++------ .../js/Contacts/Contacts.app.js | 26 ++++++++------ UI/WebServerResources/js/Mailer/Mailer.app.js | 8 ++--- .../js/Preferences/Preferences.app.js | 22 ++++++++---- .../js/Scheduler/Scheduler.app.js | 36 ++++++++++--------- 5 files changed, 69 insertions(+), 49 deletions(-) diff --git a/UI/WebServerResources/js/Administration/Administration.app.js b/UI/WebServerResources/js/Administration/Administration.app.js index fd5bec2da..4b0b79867 100644 --- a/UI/WebServerResources/js/Administration/Administration.app.js +++ b/UI/WebServerResources/js/Administration/Administration.app.js @@ -11,8 +11,8 @@ /** * @ngInject */ - configure.$inject = ['$stateProvider', '$urlRouterProvider']; - function configure($stateProvider, $urlRouterProvider) { + configure.$inject = ['$stateProvider', '$urlServiceProvider']; + function configure($stateProvider, $urlServiceProvider) { $stateProvider .state('administration', { abstract: true, @@ -48,7 +48,7 @@ }); // if none of the above states are matched, use this as the fallback - $urlRouterProvider.otherwise('/rights'); + $urlServiceProvider.rules.otherwise('/rights'); } /** @@ -113,14 +113,18 @@ /** * @ngInject */ - runBlock.$inject = ['$log', '$rootScope', '$state']; - function runBlock($log, $rootScope, $state) { - $rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) { - $log.error(error); - $state.go('administration.rights'); - }); - $rootScope.$on('$routeChangeError', function(event, current, previous, rejection) { - $log.error(event, current, previous, rejection); + runBlock.$inject = ['$window', '$log', '$transitions', '$state']; + function runBlock($window, $log, $transitions, $state) { + if (!$window.DebugEnabled) + $state.defaultErrorHandler(function() { + // Don't report any state error + }); + $transitions.onError({ to: 'administration.**' }, function(transition) { + if (transition.to().name != 'administration' && + !transition.ignored()) { + $log.error('transition error to ' + transition.to().name + ': ' + transition.error().detail); + $state.go({ state: 'administration.rights' }); + } }); } diff --git a/UI/WebServerResources/js/Contacts/Contacts.app.js b/UI/WebServerResources/js/Contacts/Contacts.app.js index 33d2fefe6..51263aaa4 100644 --- a/UI/WebServerResources/js/Contacts/Contacts.app.js +++ b/UI/WebServerResources/js/Contacts/Contacts.app.js @@ -11,8 +11,8 @@ /** * @ngInject */ - configure.$inject = ['$stateProvider', '$urlRouterProvider']; - function configure($stateProvider, $urlRouterProvider) { + configure.$inject = ['$stateProvider', '$urlServiceProvider']; + function configure($stateProvider, $urlServiceProvider) { $stateProvider .state('app', { url: '/addressbooks', @@ -93,7 +93,7 @@ }); // if none of the above states are matched, use this as the fallback - $urlRouterProvider.otherwise('/addressbooks/personal'); + $urlServiceProvider.rules.otherwise({ state: 'app.addressbook', params: { addressbookId: 'personal' } }); } /** @@ -170,14 +170,18 @@ /** * @ngInject */ - runBlock.$inject = ['$rootScope', '$log', '$state']; - function runBlock($rootScope, $log, $state) { - $rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) { - $log.error(error); - $state.go('app.addressbook', { addressbookId: 'personal' }); - }); - $rootScope.$on('$routeChangeError', function(event, current, previous, rejection) { - $log.error(event, current, previous, rejection); + runBlock.$inject = ['$window', '$log', '$transitions', '$state']; + function runBlock($window, $log, $transitions, $state) { + if (!$window.DebugEnabled) + $state.defaultErrorHandler(function() { + // Don't report any state error + }); + $transitions.onError({ to: 'app.**' }, function(transition) { + if (transition.to().name != 'app' && + !transition.ignored()) { + $log.error('transition error to ' + transition.to().name + ': ' + transition.error().detail); + $state.go('app.addressbook', { addressbookId: 'personal' }); + } }); } diff --git a/UI/WebServerResources/js/Mailer/Mailer.app.js b/UI/WebServerResources/js/Mailer/Mailer.app.js index efed1cb6d..d1e7aa14a 100644 --- a/UI/WebServerResources/js/Mailer/Mailer.app.js +++ b/UI/WebServerResources/js/Mailer/Mailer.app.js @@ -11,8 +11,8 @@ /** * @ngInject */ - configure.$inject = ['$stateProvider', '$urlRouterProvider']; - function configure($stateProvider, $urlRouterProvider) { + configure.$inject = ['$stateProvider', '$urlServiceProvider']; + function configure($stateProvider, $urlServiceProvider) { $stateProvider .state('mail', { url: '/Mail', @@ -140,7 +140,7 @@ // }); // if none of the above states are matched, use this as the fallback - $urlRouterProvider.otherwise('/Mail/0/inbox'); + $urlServiceProvider.rules.otherwise('/Mail/0/inbox'); // Try to register SOGo has an handler for mailto: links if (navigator && navigator.registerProtocolHandler) { @@ -348,7 +348,7 @@ if (transition.to().name != 'mail' && !transition.ignored() && transition.error().message.indexOf('superseded') < 0) { - $log.error('transition error to ' + transition.to().name); + $log.error('transition error to ' + transition.to().name + ': ' + transition.error().detail); // Unselect everything Mailbox.selectedFolder = false; $state.go('mail'); diff --git a/UI/WebServerResources/js/Preferences/Preferences.app.js b/UI/WebServerResources/js/Preferences/Preferences.app.js index 2126e8322..098e6115e 100644 --- a/UI/WebServerResources/js/Preferences/Preferences.app.js +++ b/UI/WebServerResources/js/Preferences/Preferences.app.js @@ -11,8 +11,8 @@ /** * @ngInject */ - configure.$inject = ['$stateProvider', '$urlRouterProvider']; - function configure($stateProvider, $urlRouterProvider) { + configure.$inject = ['$stateProvider', '$urlServiceProvider']; + function configure($stateProvider, $urlServiceProvider) { $stateProvider .state('preferences', { abstract: true, @@ -58,17 +58,25 @@ }); // if none of the above states are matched, use this as the fallback - $urlRouterProvider.otherwise('/general'); + $urlServiceProvider.rules.otherwise('/general'); } /** * @ngInject */ - runBlock.$inject = ['$rootScope']; - function runBlock($rootScope) { - $rootScope.$on('$routeChangeError', function(event, current, previous, rejection) { - console.error(event, current, previous, rejection); + runBlock.$inject = ['$window', '$log', '$transitions', '$state']; + function runBlock($window, $log, $transitions, $state) { + if (!$window.DebugEnabled) + $state.defaultErrorHandler(function() { + // Don't report any state error + }); + $transitions.onError({ to: 'preferences.**' }, function(transition) { + if (transition.to().name != 'preferences' && + !transition.ignored()) { + $log.error('transition error to ' + transition.to().name + ': ' + transition.error().detail); + $state.go({ state: 'preferences' }); + } }); } diff --git a/UI/WebServerResources/js/Scheduler/Scheduler.app.js b/UI/WebServerResources/js/Scheduler/Scheduler.app.js index 8b7015fca..bd51a03e8 100644 --- a/UI/WebServerResources/js/Scheduler/Scheduler.app.js +++ b/UI/WebServerResources/js/Scheduler/Scheduler.app.js @@ -11,8 +11,8 @@ /** * @ngInject */ - configure.$inject = ['$stateProvider', '$urlRouterProvider']; - function configure($stateProvider, $urlRouterProvider) { + configure.$inject = ['$stateProvider', '$urlServiceProvider']; + function configure($stateProvider, $urlServiceProvider) { $stateProvider .state('calendars', { url: '/calendar', @@ -28,7 +28,7 @@ } }) .state('calendars.view', { - url: '/{view:(?:day|week|month|multicolumnday)}/:day', + url: '/{view:(?:day|week|month|multicolumnday)}/{day:[0-9]{8}}', //sticky: true, //deepStateRedirect: true, views: { @@ -49,22 +49,22 @@ } }); - $urlRouterProvider.when('/calendar/day', function() { + $urlServiceProvider.rules.when('/calendar/day', function() { // If no date is specified, show today var now = new Date(); return '/calendar/day/' + now.getDayString(); }); - $urlRouterProvider.when('/calendar/multicolumnday', function() { + $urlServiceProvider.rules.when('/calendar/multicolumnday', function() { // If no date is specified, show today var now = new Date(); return '/calendar/multicolumnday/' + now.getDayString(); }); - $urlRouterProvider.when('/calendar/week', function() { + $urlServiceProvider.rules.when('/calendar/week', function() { // If no date is specified, show today's week var now = new Date(); return '/calendar/week/' + now.getDayString(); }); - $urlRouterProvider.when('/calendar/month', function() { + $urlServiceProvider.rules.when('/calendar/month', function() { // If no date is specified, show today's month var now = new Date(); return '/calendar/month/' + now.getDayString(); @@ -72,7 +72,7 @@ // If none of the above states are matched, use this as the fallback. // runBlock will also act as a fallback by looking at user's settings - $urlRouterProvider.otherwise('/calendar'); + $urlServiceProvider.rules.otherwise('/calendar/week'); } /** @@ -105,14 +105,18 @@ /** * @ngInject */ - runBlock.$inject = ['$rootScope', '$log', '$location', '$state', 'Preferences']; - function runBlock($rootScope, $log, $location, $state, Preferences) { - $rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) { - $log.error(error); - $state.go('calendar'); - }); - $rootScope.$on('$routeChangeError', function(event, current, previous, rejection) { - $log.error(event, current, previous, rejection); + runBlock.$inject = ['$window', '$log', '$transitions', '$location', '$state', 'Preferences']; + function runBlock($window, $log, $transitions, $location, $state, Preferences) { + if (!$window.DebugEnabled) + $state.defaultErrorHandler(function() { + // Don't report any state error + }); + $transitions.onError({ to: 'calendars.**' }, function(transition) { + if (transition.to().name != 'calendars' && + !transition.ignored()) { + $log.error('transition error to ' + transition.to().name + ': ' + transition.error().detail); + $state.go({ state: 'calendars' }); + } }); if ($location.url().length === 0) { // Restore user's last view