|
|
@ -1,5 +1,5 @@
|
|
|
|
angular.module('portainer.services')
|
|
|
|
angular.module('portainer.services')
|
|
|
|
.factory('StateManager', ['$q', 'SystemService', 'InfoHelper', 'LocalStorage', 'SettingsService', 'StatusService', function StateManagerFactory($q, SystemService, InfoHelper, LocalStorage, SettingsService, StatusService) {
|
|
|
|
.factory('StateManager', ['$q', 'SystemService', 'InfoHelper', 'LocalStorage', 'SettingsService', 'StatusService', 'APPLICATION_CACHE_VALIDITY', function StateManagerFactory($q, SystemService, InfoHelper, LocalStorage, SettingsService, StatusService, APPLICATION_CACHE_VALIDITY) {
|
|
|
|
'use strict';
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
var manager = {};
|
|
|
|
var manager = {};
|
|
|
@ -34,20 +34,21 @@ angular.module('portainer.services')
|
|
|
|
LocalStorage.storeApplicationState(state.application);
|
|
|
|
LocalStorage.storeApplicationState(state.application);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
manager.initialize = function () {
|
|
|
|
|
|
|
|
var deferred = $q.defer();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var endpointState = LocalStorage.getEndpointState();
|
|
|
|
function assignStateFromStatusAndSettings(status, settings) {
|
|
|
|
if (endpointState) {
|
|
|
|
state.application.authentication = status.Authentication;
|
|
|
|
state.endpoint = endpointState;
|
|
|
|
state.application.analytics = status.Analytics;
|
|
|
|
|
|
|
|
state.application.endpointManagement = status.EndpointManagement;
|
|
|
|
|
|
|
|
state.application.version = status.Version;
|
|
|
|
|
|
|
|
state.application.logo = settings.LogoURL;
|
|
|
|
|
|
|
|
state.application.displayDonationHeader = settings.DisplayDonationHeader;
|
|
|
|
|
|
|
|
state.application.displayExternalContributors = settings.DisplayExternalContributors;
|
|
|
|
|
|
|
|
state.application.validity = moment().unix();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var applicationState = LocalStorage.getApplicationState();
|
|
|
|
function loadApplicationState() {
|
|
|
|
if (applicationState) {
|
|
|
|
var deferred = $q.defer();
|
|
|
|
state.application = applicationState;
|
|
|
|
|
|
|
|
state.loading = false;
|
|
|
|
|
|
|
|
deferred.resolve(state);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$q.all({
|
|
|
|
$q.all({
|
|
|
|
settings: SettingsService.publicSettings(),
|
|
|
|
settings: SettingsService.publicSettings(),
|
|
|
|
status: StatusService.status()
|
|
|
|
status: StatusService.status()
|
|
|
@ -55,13 +56,7 @@ angular.module('portainer.services')
|
|
|
|
.then(function success(data) {
|
|
|
|
.then(function success(data) {
|
|
|
|
var status = data.status;
|
|
|
|
var status = data.status;
|
|
|
|
var settings = data.settings;
|
|
|
|
var settings = data.settings;
|
|
|
|
state.application.authentication = status.Authentication;
|
|
|
|
assignStateFromStatusAndSettings(status, settings);
|
|
|
|
state.application.analytics = status.Analytics;
|
|
|
|
|
|
|
|
state.application.endpointManagement = status.EndpointManagement;
|
|
|
|
|
|
|
|
state.application.version = status.Version;
|
|
|
|
|
|
|
|
state.application.logo = settings.LogoURL;
|
|
|
|
|
|
|
|
state.application.displayDonationHeader = settings.DisplayDonationHeader;
|
|
|
|
|
|
|
|
state.application.displayExternalContributors = settings.DisplayExternalContributors;
|
|
|
|
|
|
|
|
LocalStorage.storeApplicationState(state.application);
|
|
|
|
LocalStorage.storeApplicationState(state.application);
|
|
|
|
deferred.resolve(state);
|
|
|
|
deferred.resolve(state);
|
|
|
|
})
|
|
|
|
})
|
|
|
@ -71,6 +66,43 @@ angular.module('portainer.services')
|
|
|
|
.finally(function final() {
|
|
|
|
.finally(function final() {
|
|
|
|
state.loading = false;
|
|
|
|
state.loading = false;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
manager.initialize = function () {
|
|
|
|
|
|
|
|
var deferred = $q.defer();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var endpointState = LocalStorage.getEndpointState();
|
|
|
|
|
|
|
|
if (endpointState) {
|
|
|
|
|
|
|
|
state.endpoint = endpointState;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var applicationState = LocalStorage.getApplicationState();
|
|
|
|
|
|
|
|
if (applicationState) {
|
|
|
|
|
|
|
|
var now = moment().unix();
|
|
|
|
|
|
|
|
var cacheValidity = now - applicationState.validity;
|
|
|
|
|
|
|
|
if (cacheValidity > APPLICATION_CACHE_VALIDITY) {
|
|
|
|
|
|
|
|
loadApplicationState()
|
|
|
|
|
|
|
|
.then(function success(data) {
|
|
|
|
|
|
|
|
deferred.resolve(state);
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.catch(function error(err) {
|
|
|
|
|
|
|
|
deferred.reject(err);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
state.application = applicationState;
|
|
|
|
|
|
|
|
state.loading = false;
|
|
|
|
|
|
|
|
deferred.resolve(state);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
loadApplicationState()
|
|
|
|
|
|
|
|
.then(function success(data) {
|
|
|
|
|
|
|
|
deferred.resolve(state);
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.catch(function error(err) {
|
|
|
|
|
|
|
|
deferred.reject(err);
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
return deferred.promise;
|
|
|
|