From a1ff025488b2bf41a1573c3790d36ee0993a4bbe Mon Sep 17 00:00:00 2001 From: Chris Houseknecht Date: Thu, 21 Nov 2013 22:36:53 +0000 Subject: [PATCH] AC-715 make sure we load api resources immediately upon application start. --- awx/ui/static/lib/ansible/api-loader.js | 54 ++++++++++--------------- 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/awx/ui/static/lib/ansible/api-loader.js b/awx/ui/static/lib/ansible/api-loader.js index af81c21859..0a3980782a 100644 --- a/awx/ui/static/lib/ansible/api-loader.js +++ b/awx/ui/static/lib/ansible/api-loader.js @@ -11,38 +11,28 @@ angular.module('ApiLoader', ['ngCookies']) .factory('LoadBasePaths', ['$http', '$rootScope', '$cookieStore', 'ProcessErrors', function($http, $rootScope, $cookieStore, ProcessErrors) { return function() { - if (!$rootScope['defaultUrls']) - // if 'defaultUrls', the data used by GetBasePath(), is not in $rootScope, then we need to - // restore it from cookieStore or by querying the API. it goes missing from $rootScope - // when user hits browser refresh - if (!$cookieStore.get('api')) { - // if it's not in cookieStore, then we need to retrieve it from the API - $http.get('/api/') - .success( function(data, status, headers, config) { - var base = data.current_version; - $http.get(base) - .success( function(data, status, headers, config) { - data['base'] = base; - $rootScope['defaultUrls'] = data; - $cookieStore.remove('api'); - $cookieStore.put('api',data); //Preserve in cookie to prevent against - //loss during browser refresh - }) - .error ( function(data, status, headers, config) { - $rootScope['defaultUrls'] = { status: 'error' }; - ProcessErrors(null, data, status, null, - { hdr: 'Error', msg: 'Failed to read ' + base + '. GET status: ' + status }); - }); - }) - .error( function(data, status, headers, config) { - $rootScope['defaultUrls'] = { status: 'error' }; - ProcessErrors(null, data, status, null, - { hdr: 'Error', msg: 'Failed to read /api. GET status: ' + status }); - }); - } - else { - $rootScope['defaultUrls'] = $cookieStore.get('api'); - } + $http.get('/api/') + .success( function(data, status, headers, config) { + var base = data.current_version; + $http.get(base) + .success( function(data, status, headers, config) { + data['base'] = base; + $rootScope['defaultUrls'] = data; + $cookieStore.remove('api'); + $cookieStore.put('api',data); //Preserve in cookie to prevent against + //loss during browser refresh + }) + .error ( function(data, status, headers, config) { + $rootScope['defaultUrls'] = { status: 'error' }; + ProcessErrors(null, data, status, null, + { hdr: 'Error', msg: 'Failed to read ' + base + '. GET status: ' + status }); + }); + }) + .error( function(data, status, headers, config) { + $rootScope['defaultUrls'] = { status: 'error' }; + ProcessErrors(null, data, status, null, + { hdr: 'Error', msg: 'Failed to read /api. GET status: ' + status }); + }); } }])