diff --git a/awx/ui/client/src/app.js b/awx/ui/client/src/app.js index d903776765..3d23bdcf8f 100644 --- a/awx/ui/client/src/app.js +++ b/awx/ui/client/src/app.js @@ -385,6 +385,10 @@ var tower = angular.module('Tower', [ }; $rootScope.$stateParams = $stateParams; + $state.defaultErrorHandler(function(error) { + $log.debug(`$state.defaultErrorHandler: ${error}`); + }); + I18NInit(); $stateExtender.addState({ name: 'dashboard', @@ -681,9 +685,52 @@ var tower = angular.module('Tower', [ $rootScope.crumbCache = []; - // $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState) { - // SocketService.subscribe(toState, toParams); - // }); + $rootScope.$on("$stateChangeStart", function (event, next) { + // Remove any lingering intervals + // except on jobDetails.* states + var jobDetailStates = [ + 'jobDetail', + 'jobDetail.host-summary', + 'jobDetail.host-event.details', + 'jobDetail.host-event.json', + 'jobDetail.host-events', + 'jobDetail.host-event.stdout' + ]; + if ($rootScope.jobDetailInterval && !_.includes(jobDetailStates, next.name) ) { + window.clearInterval($rootScope.jobDetailInterval); + } + if ($rootScope.jobStdOutInterval && !_.includes(jobDetailStates, next.name) ) { + window.clearInterval($rootScope.jobStdOutInterval); + } + + // On each navigation request, check that the user is logged in + if (!/^\/(login|logout)/.test($location.path())) { + // capture most recent URL, excluding login/logout + $rootScope.lastPath = $location.path(); + $rootScope.enteredPath = $location.path(); + $cookieStore.put('lastPath', $location.path()); + } + + if (Authorization.isUserLoggedIn() === false) { + if (next.name !== "signIn") { + $state.go('signIn'); + } + } else if ($rootScope && $rootScope.sessionTimer && $rootScope.sessionTimer.isExpired()) { + // gets here on timeout + if (next.name !== "signIn") { + $state.go('signIn'); + } + } else { + if ($rootScope.current_user === undefined || $rootScope.current_user === null) { + Authorization.restoreUserInfo(); //user must have hit browser refresh + } + if (next && (next.name !== "signIn" && next.name !== "signOut" && next.name !== "license")) { + // if not headed to /login or /logout, then check the license + CheckLicense.test(event); + } + } + activateTab(); + }); $rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState) { diff --git a/awx/ui/client/src/license/checkLicense.factory.js b/awx/ui/client/src/license/checkLicense.factory.js index d68358cd29..c104ce091c 100644 --- a/awx/ui/client/src/license/checkLicense.factory.js +++ b/awx/ui/client/src/license/checkLicense.factory.js @@ -42,10 +42,10 @@ export default if(license === null || !$rootScope.license_tested){ if(this.valid(license) === false) { $rootScope.licenseMissing = true; + $state.go('license'); if(event){ event.preventDefault(); } - $state.go('license'); } else { $rootScope.licenseMissing = false; @@ -53,7 +53,7 @@ export default } else if(this.valid(license) === false) { $rootScope.licenseMissing = true; - $state.transitionTo('license'); + $state.go('license'); if(event){ event.preventDefault(); }