2017-09-21 08:23:51 +00:00
|
|
|
angular.module('portainer')
|
2017-11-12 19:27:28 +00:00
|
|
|
.run(['$rootScope', '$state', 'Authentication', 'authManager', 'StateManager', 'EndpointProvider', 'Notifications', 'Analytics', 'cfpLoadingBar', function ($rootScope, $state, Authentication, authManager, StateManager, EndpointProvider, Notifications, Analytics, cfpLoadingBar) {
|
2017-09-21 08:23:51 +00:00
|
|
|
'use strict';
|
2017-02-25 11:21:55 +00:00
|
|
|
|
2017-09-21 08:23:51 +00:00
|
|
|
EndpointProvider.initialize();
|
2017-02-25 11:21:55 +00:00
|
|
|
|
2017-09-21 08:23:51 +00:00
|
|
|
StateManager.initialize()
|
|
|
|
.then(function success(state) {
|
|
|
|
if (state.application.authentication) {
|
2018-01-09 19:06:19 +00:00
|
|
|
initAuthentication(authManager, Authentication, $rootScope, $state);
|
2017-09-21 08:23:51 +00:00
|
|
|
}
|
|
|
|
if (state.application.analytics) {
|
|
|
|
initAnalytics(Analytics, $rootScope);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve application settings');
|
|
|
|
});
|
|
|
|
|
|
|
|
$rootScope.$state = $state;
|
2017-11-12 19:27:28 +00:00
|
|
|
|
|
|
|
// Workaround to prevent the loading bar from going backward
|
|
|
|
// https://github.com/chieffancypants/angular-loading-bar/issues/273
|
|
|
|
var originalSet = cfpLoadingBar.set;
|
|
|
|
cfpLoadingBar.set = function overrideSet(n) {
|
|
|
|
if (n > cfpLoadingBar.status()) {
|
|
|
|
originalSet.apply(cfpLoadingBar, arguments);
|
|
|
|
}
|
|
|
|
};
|
2017-09-21 08:23:51 +00:00
|
|
|
}]);
|
|
|
|
|
|
|
|
|
2018-01-09 19:06:19 +00:00
|
|
|
function initAuthentication(authManager, Authentication, $rootScope, $state) {
|
2017-09-21 08:23:51 +00:00
|
|
|
authManager.checkAuthOnRefresh();
|
|
|
|
authManager.redirectWhenUnauthenticated();
|
|
|
|
Authentication.init();
|
|
|
|
$rootScope.$on('tokenHasExpired', function() {
|
2018-02-01 12:27:52 +00:00
|
|
|
$state.go('portainer.auth', {error: 'Your session has expired'});
|
2017-09-21 08:23:51 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function initAnalytics(Analytics, $rootScope) {
|
|
|
|
Analytics.offline(false);
|
|
|
|
Analytics.registerScriptTags();
|
|
|
|
Analytics.registerTrackers();
|
|
|
|
$rootScope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState, fromParams) {
|
|
|
|
Analytics.trackPage(toState.url);
|
|
|
|
Analytics.pageView();
|
|
|
|
});
|
|
|
|
}
|