AC-715 make sure we load api resources immediately upon application start.

This commit is contained in:
Chris Houseknecht
2013-11-21 22:36:53 +00:00
parent 2f0615d8c1
commit a1ff025488

View File

@@ -11,38 +11,28 @@ angular.module('ApiLoader', ['ngCookies'])
.factory('LoadBasePaths', ['$http', '$rootScope', '$cookieStore', 'ProcessErrors', .factory('LoadBasePaths', ['$http', '$rootScope', '$cookieStore', 'ProcessErrors',
function($http, $rootScope, $cookieStore, ProcessErrors) { function($http, $rootScope, $cookieStore, ProcessErrors) {
return function() { return function() {
if (!$rootScope['defaultUrls']) $http.get('/api/')
// if 'defaultUrls', the data used by GetBasePath(), is not in $rootScope, then we need to .success( function(data, status, headers, config) {
// restore it from cookieStore or by querying the API. it goes missing from $rootScope var base = data.current_version;
// when user hits browser refresh $http.get(base)
if (!$cookieStore.get('api')) { .success( function(data, status, headers, config) {
// if it's not in cookieStore, then we need to retrieve it from the API data['base'] = base;
$http.get('/api/') $rootScope['defaultUrls'] = data;
.success( function(data, status, headers, config) { $cookieStore.remove('api');
var base = data.current_version; $cookieStore.put('api',data); //Preserve in cookie to prevent against
$http.get(base) //loss during browser refresh
.success( function(data, status, headers, config) { })
data['base'] = base; .error ( function(data, status, headers, config) {
$rootScope['defaultUrls'] = data; $rootScope['defaultUrls'] = { status: 'error' };
$cookieStore.remove('api'); ProcessErrors(null, data, status, null,
$cookieStore.put('api',data); //Preserve in cookie to prevent against { hdr: 'Error', msg: 'Failed to read ' + base + '. GET status: ' + status });
//loss during browser refresh });
}) })
.error ( function(data, status, headers, config) { .error( function(data, status, headers, config) {
$rootScope['defaultUrls'] = { status: 'error' }; $rootScope['defaultUrls'] = { status: 'error' };
ProcessErrors(null, data, status, null, ProcessErrors(null, data, status, null,
{ hdr: 'Error', msg: 'Failed to read ' + base + '. GET status: ' + status }); { hdr: 'Error', msg: 'Failed to read /api. 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');
}
} }
}]) }])