loca_config

Fixed lingering issues where $AnsibleConfig is referenced when it is not yet defined.
This commit is contained in:
Chris Houseknecht
2014-07-25 13:59:34 -04:00
parent de953ec3ed
commit 7139b5b25a
3 changed files with 59 additions and 59 deletions

View File

@@ -400,7 +400,7 @@ angular.module('Tower', [
var _debug = $delegate.debug; var _debug = $delegate.debug;
$delegate.debug = function(msg) { $delegate.debug = function(msg) {
// only show debug messages when debug_mode set to true in config // only show debug messages when debug_mode set to true in config
if ($AnsibleConfig.debug_mode) { if ($AnsibleConfig && $AnsibleConfig.debug_mode) {
_debug(msg); _debug(msg);
} }
}; };
@@ -415,8 +415,6 @@ angular.module('Tower', [
var e, html, sock, checkCount; var e, html, sock, checkCount;
LoadConfig();
function detectBrowser() { function detectBrowser() {
var ua = window.navigator.userAgent, var ua = window.navigator.userAgent,
browser; browser;
@@ -462,52 +460,6 @@ angular.module('Tower', [
$('#ansible-mobile-menu a[href="#' + base + '"]').addClass('active'); $('#ansible-mobile-menu a[href="#' + base + '"]').addClass('active');
} }
$rootScope.browser = detectBrowser();
$rootScope.$on("$routeChangeStart", function (event, next) {
// Before navigating away from current tab, make sure the primary view is visible
if ($('#stream-container').is(':visible')) {
HideStream();
}
// remove any lingering intervals
if ($rootScope.jobDetailInterval) {
window.clearInterval($rootScope.jobDetailInterval);
}
if ($rootScope.jobStdOutInterval) {
window.clearInterval($rootScope.jobStdOutInterval);
}
if ($rootScope.checkSocketConnectionInterval) {
// use to monitor and restart socket connections
window.clearInterval($rootScope.checkSocketConnectionInterval);
}
// 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();
$cookieStore.put('lastPath', $location.path());
}
if (Authorization.isUserLoggedIn() === false) {
if (next.templateUrl !== (urlPrefix + 'partials/login.html')) {
$location.path('/login');
}
} else if ($rootScope.sessionTimer.isExpired()) {
if (next.templateUrl !== (urlPrefix + 'partials/login.html')) {
$rootScope.sessionTimer.expireSession();
$location.path('/login');
}
} else {
if ($rootScope.current_user === undefined || $rootScope.current_user === null) {
Authorization.restoreUserInfo(); //user must have hit browser refresh
}
CheckLicense();
}
activateTab();
});
if ($rootScope.removeConfigReady) { if ($rootScope.removeConfigReady) {
$rootScope.removeConfigReady(); $rootScope.removeConfigReady();
} }
@@ -518,6 +470,52 @@ angular.module('Tower', [
$rootScope.crumbCache = []; $rootScope.crumbCache = [];
$rootScope.sessionTimer = Timer.init(); $rootScope.sessionTimer = Timer.init();
$rootScope.browser = detectBrowser();
$rootScope.$on("$routeChangeStart", function (event, next) {
// Before navigating away from current tab, make sure the primary view is visible
if ($('#stream-container').is(':visible')) {
HideStream();
}
// remove any lingering intervals
if ($rootScope.jobDetailInterval) {
window.clearInterval($rootScope.jobDetailInterval);
}
if ($rootScope.jobStdOutInterval) {
window.clearInterval($rootScope.jobStdOutInterval);
}
if ($rootScope.checkSocketConnectionInterval) {
// use to monitor and restart socket connections
window.clearInterval($rootScope.checkSocketConnectionInterval);
}
// 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();
$cookieStore.put('lastPath', $location.path());
}
if (Authorization.isUserLoggedIn() === false) {
if (next.templateUrl !== (urlPrefix + 'partials/login.html')) {
$location.path('/login');
}
} else if ($rootScope.sessionTimer.isExpired()) {
if (next.templateUrl !== (urlPrefix + 'partials/login.html')) {
$rootScope.sessionTimer.expireSession();
$location.path('/login');
}
} else {
if ($rootScope.current_user === undefined || $rootScope.current_user === null) {
Authorization.restoreUserInfo(); //user must have hit browser refresh
}
CheckLicense();
}
activateTab();
});
if (!Authorization.getToken()) { if (!Authorization.getToken()) {
// When the app first loads, redirect to login page // When the app first loads, redirect to login page
$rootScope.sessionExpired = false; $rootScope.sessionExpired = false;
@@ -575,7 +573,7 @@ angular.module('Tower', [
// monitor socket status // monitor socket status
checkCount = 0; checkCount = 0;
setInterval(function() { setInterval(function() {
if (sock.checkStatus() === 'error' || checkCount > 2) { if (sock.checkStatus() === 'error' || checkCount > 3) {
// there's an error or we're stuck in a 'connecting' state. attempt to reconnect // there's an error or we're stuck in a 'connecting' state. attempt to reconnect
sock = null; sock = null;
$log.debug('attempting new socket connection'); $log.debug('attempting new socket connection');
@@ -590,5 +588,7 @@ angular.module('Tower', [
} }
}, 3000); }, 3000);
}); });
LoadConfig();
} }
]); ]);

View File

@@ -8,11 +8,9 @@
* *
*/ */
/* globals console:false */
'use strict'; 'use strict';
function Authenticate($cookieStore, $compile, $window, $scope, $rootScope, $location, Authorization, ToggleClass, Alert, Wait, function Authenticate($log, $cookieStore, $compile, $window, $scope, $rootScope, $location, Authorization, ToggleClass, Alert, Wait,
Timer, Empty) { Timer, Empty) {
var setLoginFocus, lastPath, sessionExpired, var setLoginFocus, lastPath, sessionExpired,
@@ -28,10 +26,8 @@ function Authenticate($cookieStore, $compile, $window, $scope, $rootScope, $loca
return (Empty($rootScope.lastPath)) ? $cookieStore.get('lastPath') : $rootScope.lastPath; return (Empty($rootScope.lastPath)) ? $cookieStore.get('lastPath') : $rootScope.lastPath;
}; };
if ($AnsibleConfig.debug_mode && console) { $log.debug('User session expired: ' + sessionExpired);
console.log('User session expired: ' + sessionExpired); $log.debug('Last URL: ' + lastPath());
console.log('Last URL: ' + lastPath());
}
// Hide any lingering modal dialogs // Hide any lingering modal dialogs
$('.modal[aria-hidden=false]').each(function () { $('.modal[aria-hidden=false]').each(function () {
@@ -166,6 +162,6 @@ function Authenticate($cookieStore, $compile, $window, $scope, $rootScope, $loca
}; };
} }
Authenticate.$inject = ['$cookieStore', '$compile', '$window', '$scope', '$rootScope', '$location', 'Authorization', 'ToggleClass', 'Alert', 'Wait', Authenticate.$inject = ['$log', '$cookieStore', '$compile', '$window', '$scope', '$rootScope', '$location', 'Authorization', 'ToggleClass', 'Alert', 'Wait',
'Timer', 'Empty' 'Timer', 'Empty'
]; ];

View File

@@ -14,7 +14,7 @@
angular.module('LoadConfigHelper', ['Utilities']) angular.module('LoadConfigHelper', ['Utilities'])
.factory('LoadConfig', ['$rootScope', '$http', 'ProcessErrors', function($rootScope, $http, ProcessErrors) { .factory('LoadConfig', ['$log', '$rootScope', '$http', 'ProcessErrors', function($log, $rootScope, $http, ProcessErrors) {
return function() { return function() {
if ($rootScope.removeLoadConfig) { if ($rootScope.removeLoadConfig) {
@@ -22,8 +22,10 @@ angular.module('LoadConfigHelper', ['Utilities'])
} }
$rootScope.removeLoadConfig = $rootScope.$on('LoadConfig', function() { $rootScope.removeLoadConfig = $rootScope.$on('LoadConfig', function() {
// local_config.js not found, so we'll load config.js // local_config.js not found, so we'll load config.js
$log.info('attempting to load config.js');
$http({ method:'GET', url: $basePath + 'js/config.js' }) $http({ method:'GET', url: $basePath + 'js/config.js' })
.success(function(data) { .success(function(data) {
$log.info('loaded config.js');
$AnsibleConfig = eval(data); $AnsibleConfig = eval(data);
$rootScope.$emit('ConfigReady'); $rootScope.$emit('ConfigReady');
}) })
@@ -37,11 +39,13 @@ angular.module('LoadConfigHelper', ['Utilities'])
// Load js/local_config.js // Load js/local_config.js
$http({ method:'GET', url: $basePath + 'js/local_config.js' }) $http({ method:'GET', url: $basePath + 'js/local_config.js' })
.success(function(data) { .success(function(data) {
$log.info('loaded local_config.js');
$AnsibleConfig = eval(data); $AnsibleConfig = eval(data);
$rootScope.$emit('ConfigReady'); $rootScope.$emit('ConfigReady');
}) })
.error(function() { .error(function() {
//local_config.js not found //local_config.js not found
$log.info('local_config.js not found');
$rootScope.$emit('LoadConfig'); $rootScope.$emit('LoadConfig');
}); });
}; };