local_config

Fixed remaining fallout from delay of $AnsibleConfig object.
This commit is contained in:
Chris Houseknecht
2014-07-25 15:29:31 -04:00
parent e19984d6db
commit b3c41c01b8
5 changed files with 32 additions and 14 deletions

View File

@@ -575,8 +575,9 @@ angular.module('Tower', [
setInterval(function() { setInterval(function() {
if (sock.checkStatus() === 'error' || checkCount > 3) { 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; $log.debug('socket status: ' + sock.checkStatus());
$log.debug('attempting new socket connection'); $log.debug('attempting new socket connection');
sock = null;
openSocket(); openSocket();
checkCount = 0; checkCount = 0;
} }

View File

@@ -14,7 +14,7 @@
angular.module('LoadConfigHelper', ['Utilities']) angular.module('LoadConfigHelper', ['Utilities'])
.factory('LoadConfig', ['$log', '$rootScope', '$http', 'ProcessErrors', function($log, $rootScope, $http, ProcessErrors) { .factory('LoadConfig', ['$log', '$rootScope', '$http', 'ProcessErrors', 'Store', function($log, $rootScope, $http, ProcessErrors, Store) {
return function() { return function() {
if ($rootScope.removeLoadConfig) { if ($rootScope.removeLoadConfig) {
@@ -27,6 +27,7 @@ angular.module('LoadConfigHelper', ['Utilities'])
.success(function(data) { .success(function(data) {
$log.info('loaded config.js'); $log.info('loaded config.js');
$AnsibleConfig = eval(data); $AnsibleConfig = eval(data);
Store('AnsibleConfig', $AnsibleConfig);
$rootScope.$emit('ConfigReady'); $rootScope.$emit('ConfigReady');
}) })
.error(function(data, status) { .error(function(data, status) {
@@ -41,6 +42,7 @@ angular.module('LoadConfigHelper', ['Utilities'])
.success(function(data) { .success(function(data) {
$log.info('loaded local_config.js'); $log.info('loaded local_config.js');
$AnsibleConfig = eval(data); $AnsibleConfig = eval(data);
Store('AnsibleConfig', $AnsibleConfig);
$rootScope.$emit('ConfigReady'); $rootScope.$emit('ConfigReady');
}) })
.error(function() { .error(function() {

View File

@@ -12,13 +12,26 @@
angular.module('SocketIO', ['AuthService', 'Utilities']) angular.module('SocketIO', ['AuthService', 'Utilities'])
.factory('Socket', ['$rootScope', '$location', '$log', 'Authorization', function ($rootScope, $location, $log, Authorization) { .factory('Socket', ['$rootScope', '$location', '$log', 'Authorization', 'Store', function ($rootScope, $location, $log, Authorization, Store) {
return function(params) { return function(params) {
var scope = params.scope, var scope = params.scope,
host = $location.host(), host = $location.host(),
endpoint = params.endpoint, endpoint = params.endpoint,
protocol = $location.protocol(), protocol = $location.protocol(),
url = protocol + '://' + host + ':' + $AnsibleConfig.websocket_port + '/socket.io/' + endpoint; config, socketPort, url;
// Since some pages are opened in a new tab, we might get here before AnsibleConfig is available.
// In that case, load from local storage.
if ($AnsibleConfig) {
socketPort = $AnsibleConfig.websocket_port;
}
else {
$log.debug('getting web socket port from local storage');
config = Store('AnsibleConfig');
socketPort = config.websocket_port;
}
url = protocol + '://' + host + ':' + socketPort + '/socket.io/' + endpoint;
$log.debug('opening socket connection to: ' + url);
function getSocketTip(status) { function getSocketTip(status) {
var result = ''; var result = '';
@@ -43,7 +56,7 @@ angular.module('SocketIO', ['AuthService', 'Utilities'])
init: function() { init: function() {
var self = this, var self = this,
token = Authorization.getToken(); token = Authorization.getToken();
if (!$rootScope.sessionTimer.isExpired()) { if (!$rootScope.sessionTimer || ($rootScope.sessionTimer && !$rootScope.sessionTimer.isExpired())) {
// We have a valid session token, so attmempt socket connection // We have a valid session token, so attmempt socket connection
$log.debug('Socket connecting to: ' + url); $log.debug('Socket connecting to: ' + url);
self.scope.socket_url = url; self.scope.socket_url = url;

View File

@@ -41,7 +41,9 @@ angular.module('TimerService', ['ngCookies', 'Utilities'])
}, },
moveForward: function () { moveForward: function () {
var t = new Date().getTime() + ($AnsibleConfig.session_timeout * 1000); var tm, t;
tm = ($AnsibleConfig) ? $AnsibleConfig.session_timeout : 1800;
t = new Date().getTime() + (tm * 1000);
this.sessionTime = t; this.sessionTime = t;
$cookieStore.put('sessionTime', t); $cookieStore.put('sessionTime', t);
$rootScope.sessionExpired = false; $rootScope.sessionExpired = false;

View File

@@ -138,13 +138,11 @@ angular.module('Utilities', ['RestServices', 'Utilities'])
return function (scope, data, status, form, defaultMsg) { return function (scope, data, status, form, defaultMsg) {
var field, fieldErrors, msg, keys; var field, fieldErrors, msg, keys;
Wait('stop'); Wait('stop');
if ($AnsibleConfig.debug_mode) { $log.debug('Debug status: ' + status);
$log.debug('Debug status: ' + status); $log.debug('Debug data: ');
$log.debug('Debug data: '); $log.debug(data);
$log.debug(data); if (defaultMsg.msg) {
if (defaultMsg.msg) { $log.debug('Debug: ' + defaultMsg.msg);
$log.debug('Debug: ' + defaultMsg.msg);
}
} }
if (status === 403) { if (status === 403) {
msg = 'The API responded with a 403 Access Denied error. '; msg = 'The API responded with a 403 Access Denied error. ';
@@ -158,7 +156,9 @@ angular.module('Utilities', ['RestServices', 'Utilities'])
Alert('Deleted Object', 'The requested object was previously deleted and can no longer be accessed.'); Alert('Deleted Object', 'The requested object was previously deleted and can no longer be accessed.');
} else if ((status === 'Token is expired') || (status === 401 && data.detail && data.detail === 'Token is expired') || } else if ((status === 'Token is expired') || (status === 401 && data.detail && data.detail === 'Token is expired') ||
(status === 401 && data.detail && data.detail === 'Invalid token')) { (status === 401 && data.detail && data.detail === 'Invalid token')) {
$rootScope.sessionTimer.expireSession(); if ($rootScope.sessionTimer) {
$rootScope.sessionTimer.expireSession();
}
$location.url('/login'); $location.url('/login');
} else if (data.non_field_errors) { } else if (data.non_field_errors) {
Alert('Error!', data.non_field_errors); Alert('Error!', data.non_field_errors);