(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
*/
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' });
}
});
}

View File

@ -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' });
}
});
}

View File

@ -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');

View File

@ -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' });
}
});
}

View File

@ -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