1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

local_config

Don't start the app until the config file is loaded and $AnsibleConfig is defined.
This commit is contained in:
Chris Houseknecht 2014-07-25 10:43:05 -04:00
parent d872aa1985
commit 623ac5804e
2 changed files with 80 additions and 72 deletions

View File

@ -416,11 +416,6 @@ angular.module('Tower', [
var e, html, sock, checkCount;
LoadConfig();
LoadBasePaths();
$rootScope.breadcrumbs = [];
$rootScope.crumbCache = [];
$rootScope.sessionTimer = Timer.init();
function detectBrowser() {
var ua = window.navigator.userAgent,
@ -513,76 +508,87 @@ angular.module('Tower', [
activateTab();
});
if (!Authorization.getToken()) {
// When the app first loads, redirect to login page
$rootScope.sessionExpired = false;
$cookieStore.put('sessionExpired', false);
$location.path('/login');
} else {
// If browser refresh, set the user_is_superuser value
$rootScope.user_is_superuser = Authorization.getUserInfo('is_superuser');
if ($rootScope.removeConfigReady) {
$rootScope.removeConfigReady();
}
$rootScope.removeConfigReady = $rootScope.$on('ConfigReady', function() {
LoadBasePaths();
activateTab();
$rootScope.breadcrumbs = [];
$rootScope.crumbCache = [];
$rootScope.sessionTimer = Timer.init();
$rootScope.viewCurrentUser = function () {
$location.path('/users/' + $rootScope.current_user.id);
};
$rootScope.viewLicense = function () {
ViewLicense();
};
$rootScope.toggleTab = function(e, tab, tabs) {
e.preventDefault();
$('#' + tabs + ' #' + tab).tab('show');
};
html = "<a href=\"\" aw-pop-over=\"{{ socketTip }}\" aw-pop-over-watch=\"socketTip\" data-placement=\"bottom\" data-trigger=\"hover\" " +
"data-popover-title=\"Live Updates\" data-container=\"body\" style=\"font-size: 10px;\"><i class=\"fa icon-socket-{{ socketStatus }}\"></i></a>";
e = angular.element(document.getElementById('socket-beacon-div'));
e.empty().append(html);
$compile(e)($rootScope);
e = angular.element(document.getElementById('socket-beacon-li'));
e.empty().append(html);
$compile(e)($rootScope);
// Listen for job changes and issue callbacks to initiate
// DOM updates
function openSocket() {
sock = Socket({ scope: $rootScope, endpoint: "jobs" });
sock.init();
sock.on("status_changed", function(data) {
$log.debug('Job ' + data.unified_job_id + ' status changed to ' + data.status);
$rootScope.$emit('JobStatusChange', data);
});
}
openSocket();
setTimeout(function() {
$rootScope.$apply(function() {
sock.checkStatus();
$log.debug('socket status: ' + $rootScope.socketStatus);
});
},2000);
// monitor socket status
checkCount = 0;
setInterval(function() {
if (sock.checkStatus() === 'error' || checkCount > 2) {
// there's an error or we're stuck in a 'connecting' state. attempt to reconnect
sock = null;
$log.debug('attempting new socket connection');
openSocket();
checkCount = 0;
if (!Authorization.getToken()) {
// When the app first loads, redirect to login page
$rootScope.sessionExpired = false;
$cookieStore.put('sessionExpired', false);
$location.path('/login');
} else {
// If browser refresh, set the user_is_superuser value
$rootScope.user_is_superuser = Authorization.getUserInfo('is_superuser');
}
else if (sock.checkStatus() === 'connecting') {
checkCount++;
activateTab();
$rootScope.viewCurrentUser = function () {
$location.path('/users/' + $rootScope.current_user.id);
};
$rootScope.viewLicense = function () {
ViewLicense();
};
$rootScope.toggleTab = function(e, tab, tabs) {
e.preventDefault();
$('#' + tabs + ' #' + tab).tab('show');
};
html = "<a href=\"\" aw-pop-over=\"{{ socketTip }}\" aw-pop-over-watch=\"socketTip\" data-placement=\"bottom\" data-trigger=\"hover\" " +
"data-popover-title=\"Live Updates\" data-container=\"body\" style=\"font-size: 10px;\"><i class=\"fa icon-socket-{{ socketStatus }}\"></i></a>";
e = angular.element(document.getElementById('socket-beacon-div'));
e.empty().append(html);
$compile(e)($rootScope);
e = angular.element(document.getElementById('socket-beacon-li'));
e.empty().append(html);
$compile(e)($rootScope);
// Listen for job changes and issue callbacks to initiate
// DOM updates
function openSocket() {
sock = Socket({ scope: $rootScope, endpoint: "jobs" });
sock.init();
sock.on("status_changed", function(data) {
$log.debug('Job ' + data.unified_job_id + ' status changed to ' + data.status);
$rootScope.$emit('JobStatusChange', data);
});
}
else {
checkCount = 0;
}
}, 3000);
openSocket();
setTimeout(function() {
$rootScope.$apply(function() {
sock.checkStatus();
$log.debug('socket status: ' + $rootScope.socketStatus);
});
},2000);
// monitor socket status
checkCount = 0;
setInterval(function() {
if (sock.checkStatus() === 'error' || checkCount > 2) {
// there's an error or we're stuck in a 'connecting' state. attempt to reconnect
sock = null;
$log.debug('attempting new socket connection');
openSocket();
checkCount = 0;
}
else if (sock.checkStatus() === 'connecting') {
checkCount++;
}
else {
checkCount = 0;
}
}, 3000);
});
}
]);

View File

@ -25,6 +25,7 @@ angular.module('LoadConfigHelper', ['Utilities'])
$http({ method:'GET', url: $basePath + 'js/config.js' })
.success(function(data) {
$AnsibleConfig = eval(data);
$rootScope.$emit('ConfigReady');
})
.error(function(data, status) {
ProcessErrors($rootScope, data, status, null, { hdr: 'Error!',
@ -37,10 +38,11 @@ angular.module('LoadConfigHelper', ['Utilities'])
$http({ method:'GET', url: $basePath + 'js/local_config.js' })
.success(function(data) {
$AnsibleConfig = eval(data);
$rootScope.$emit('ConfigReady');
})
.error(function() {
//local_config.js not found
$rootScope.$emit('LoadConfig');
});
};
}
}]);