(js) Changes for ui-router v1.0

$urlRouterProvider is deprecated.
pull/229/merge
Francis Lachapelle 2018-06-28 15:44:12 -04:00
parent a25e0f73be
commit e494dbc57c
5 changed files with 69 additions and 49 deletions

View File

@ -11,8 +11,8 @@
/** /**
* @ngInject * @ngInject
*/ */
configure.$inject = ['$stateProvider', '$urlRouterProvider']; configure.$inject = ['$stateProvider', '$urlServiceProvider'];
function configure($stateProvider, $urlRouterProvider) { function configure($stateProvider, $urlServiceProvider) {
$stateProvider $stateProvider
.state('administration', { .state('administration', {
abstract: true, abstract: true,
@ -48,7 +48,7 @@
}); });
// if none of the above states are matched, use this as the fallback // 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 * @ngInject
*/ */
runBlock.$inject = ['$log', '$rootScope', '$state']; runBlock.$inject = ['$window', '$log', '$transitions', '$state'];
function runBlock($log, $rootScope, $state) { function runBlock($window, $log, $transitions, $state) {
$rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) { if (!$window.DebugEnabled)
$log.error(error); $state.defaultErrorHandler(function() {
$state.go('administration.rights'); // Don't report any state error
}); });
$rootScope.$on('$routeChangeError', function(event, current, previous, rejection) { $transitions.onError({ to: 'administration.**' }, function(transition) {
$log.error(event, current, previous, rejection); if (transition.to().name != 'administration' &&
!transition.ignored()) {
$log.error('transition error to ' + transition.to().name + ': ' + transition.error().detail);
$state.go({ state: 'administration.rights' });
}
}); });
} }

View File

@ -11,8 +11,8 @@
/** /**
* @ngInject * @ngInject
*/ */
configure.$inject = ['$stateProvider', '$urlRouterProvider']; configure.$inject = ['$stateProvider', '$urlServiceProvider'];
function configure($stateProvider, $urlRouterProvider) { function configure($stateProvider, $urlServiceProvider) {
$stateProvider $stateProvider
.state('app', { .state('app', {
url: '/addressbooks', url: '/addressbooks',
@ -93,7 +93,7 @@
}); });
// if none of the above states are matched, use this as the fallback // 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 * @ngInject
*/ */
runBlock.$inject = ['$rootScope', '$log', '$state']; runBlock.$inject = ['$window', '$log', '$transitions', '$state'];
function runBlock($rootScope, $log, $state) { function runBlock($window, $log, $transitions, $state) {
$rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) { if (!$window.DebugEnabled)
$log.error(error); $state.defaultErrorHandler(function() {
$state.go('app.addressbook', { addressbookId: 'personal' }); // Don't report any state error
}); });
$rootScope.$on('$routeChangeError', function(event, current, previous, rejection) { $transitions.onError({ to: 'app.**' }, function(transition) {
$log.error(event, current, previous, rejection); if (transition.to().name != 'app' &&
!transition.ignored()) {
$log.error('transition error to ' + transition.to().name + ': ' + transition.error().detail);
$state.go('app.addressbook', { addressbookId: 'personal' });
}
}); });
} }

View File

@ -11,8 +11,8 @@
/** /**
* @ngInject * @ngInject
*/ */
configure.$inject = ['$stateProvider', '$urlRouterProvider']; configure.$inject = ['$stateProvider', '$urlServiceProvider'];
function configure($stateProvider, $urlRouterProvider) { function configure($stateProvider, $urlServiceProvider) {
$stateProvider $stateProvider
.state('mail', { .state('mail', {
url: '/Mail', url: '/Mail',
@ -140,7 +140,7 @@
// }); // });
// if none of the above states are matched, use this as the fallback // 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 // Try to register SOGo has an handler for mailto: links
if (navigator && navigator.registerProtocolHandler) { if (navigator && navigator.registerProtocolHandler) {
@ -348,7 +348,7 @@
if (transition.to().name != 'mail' && if (transition.to().name != 'mail' &&
!transition.ignored() && !transition.ignored() &&
transition.error().message.indexOf('superseded') < 0) { 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 // Unselect everything
Mailbox.selectedFolder = false; Mailbox.selectedFolder = false;
$state.go('mail'); $state.go('mail');

View File

@ -11,8 +11,8 @@
/** /**
* @ngInject * @ngInject
*/ */
configure.$inject = ['$stateProvider', '$urlRouterProvider']; configure.$inject = ['$stateProvider', '$urlServiceProvider'];
function configure($stateProvider, $urlRouterProvider) { function configure($stateProvider, $urlServiceProvider) {
$stateProvider $stateProvider
.state('preferences', { .state('preferences', {
abstract: true, abstract: true,
@ -58,17 +58,25 @@
}); });
// if none of the above states are matched, use this as the fallback // if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/general'); $urlServiceProvider.rules.otherwise('/general');
} }
/** /**
* @ngInject * @ngInject
*/ */
runBlock.$inject = ['$rootScope']; runBlock.$inject = ['$window', '$log', '$transitions', '$state'];
function runBlock($rootScope) { function runBlock($window, $log, $transitions, $state) {
$rootScope.$on('$routeChangeError', function(event, current, previous, rejection) { if (!$window.DebugEnabled)
console.error(event, current, previous, rejection); $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' });
}
}); });
} }

View File

@ -11,8 +11,8 @@
/** /**
* @ngInject * @ngInject
*/ */
configure.$inject = ['$stateProvider', '$urlRouterProvider']; configure.$inject = ['$stateProvider', '$urlServiceProvider'];
function configure($stateProvider, $urlRouterProvider) { function configure($stateProvider, $urlServiceProvider) {
$stateProvider $stateProvider
.state('calendars', { .state('calendars', {
url: '/calendar', url: '/calendar',
@ -28,7 +28,7 @@
} }
}) })
.state('calendars.view', { .state('calendars.view', {
url: '/{view:(?:day|week|month|multicolumnday)}/:day', url: '/{view:(?:day|week|month|multicolumnday)}/{day:[0-9]{8}}',
//sticky: true, //sticky: true,
//deepStateRedirect: true, //deepStateRedirect: true,
views: { views: {
@ -49,22 +49,22 @@
} }
}); });
$urlRouterProvider.when('/calendar/day', function() { $urlServiceProvider.rules.when('/calendar/day', function() {
// If no date is specified, show today // If no date is specified, show today
var now = new Date(); var now = new Date();
return '/calendar/day/' + now.getDayString(); return '/calendar/day/' + now.getDayString();
}); });
$urlRouterProvider.when('/calendar/multicolumnday', function() { $urlServiceProvider.rules.when('/calendar/multicolumnday', function() {
// If no date is specified, show today // If no date is specified, show today
var now = new Date(); var now = new Date();
return '/calendar/multicolumnday/' + now.getDayString(); 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 // If no date is specified, show today's week
var now = new Date(); var now = new Date();
return '/calendar/week/' + now.getDayString(); 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 // If no date is specified, show today's month
var now = new Date(); var now = new Date();
return '/calendar/month/' + now.getDayString(); return '/calendar/month/' + now.getDayString();
@ -72,7 +72,7 @@
// If none of the above states are matched, use this as the fallback. // 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 // 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 * @ngInject
*/ */
runBlock.$inject = ['$rootScope', '$log', '$location', '$state', 'Preferences']; runBlock.$inject = ['$window', '$log', '$transitions', '$location', '$state', 'Preferences'];
function runBlock($rootScope, $log, $location, $state, Preferences) { function runBlock($window, $log, $transitions, $location, $state, Preferences) {
$rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) { if (!$window.DebugEnabled)
$log.error(error); $state.defaultErrorHandler(function() {
$state.go('calendar'); // Don't report any state error
}); });
$rootScope.$on('$routeChangeError', function(event, current, previous, rejection) { $transitions.onError({ to: 'calendars.**' }, function(transition) {
$log.error(event, current, previous, rejection); 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) { if ($location.url().length === 0) {
// Restore user's last view // Restore user's last view