mirror of
https://github.com/portainer/portainer.git
synced 2025-08-02 04:15:28 +02:00
feat(settings): add settings management (#906)
This commit is contained in:
parent
5e74a3993b
commit
c7e306841a
93 changed files with 1086 additions and 457 deletions
|
@ -1,67 +1,95 @@
|
|||
angular.module('portainer.services')
|
||||
.factory('StateManager', ['$q', 'Config', 'Info', 'InfoHelper', 'Version', 'LocalStorage', function StateManagerFactory($q, Config, Info, InfoHelper, Version, LocalStorage) {
|
||||
.factory('StateManager', ['$q', 'Info', 'InfoHelper', 'Version', 'LocalStorage', 'SettingsService', 'StatusService', function StateManagerFactory($q, Info, InfoHelper, Version, LocalStorage, SettingsService, StatusService) {
|
||||
'use strict';
|
||||
|
||||
var manager = {};
|
||||
|
||||
var state = {
|
||||
loading: true,
|
||||
application: {},
|
||||
endpoint: {}
|
||||
endpoint: {},
|
||||
UI: {}
|
||||
};
|
||||
|
||||
return {
|
||||
initialize: function() {
|
||||
var endpointState = LocalStorage.getEndpointState();
|
||||
if (endpointState) {
|
||||
state.endpoint = endpointState;
|
||||
}
|
||||
manager.getState = function() {
|
||||
return state;
|
||||
};
|
||||
|
||||
var deferred = $q.defer();
|
||||
var applicationState = LocalStorage.getApplicationState();
|
||||
if (applicationState) {
|
||||
state.application = applicationState;
|
||||
state.loading = false;
|
||||
deferred.resolve(state);
|
||||
} else {
|
||||
Config.$promise.then(function success(data) {
|
||||
state.application.authentication = data.authentication;
|
||||
state.application.analytics = data.analytics;
|
||||
state.application.endpointManagement = data.endpointManagement;
|
||||
state.application.logo = data.logo;
|
||||
LocalStorage.storeApplicationState(state.application);
|
||||
state.loading = false;
|
||||
deferred.resolve(state);
|
||||
}, function error(err) {
|
||||
state.loading = false;
|
||||
deferred.reject({msg: 'Unable to retrieve server configuration', err: err});
|
||||
});
|
||||
}
|
||||
return deferred.promise;
|
||||
},
|
||||
clean: function() {
|
||||
state.endpoint = {};
|
||||
},
|
||||
updateEndpointState: function(loading) {
|
||||
var deferred = $q.defer();
|
||||
if (loading) {
|
||||
state.loading = true;
|
||||
}
|
||||
$q.all([Info.get({}).$promise, Version.get({}).$promise])
|
||||
.then(function success(data) {
|
||||
var endpointMode = InfoHelper.determineEndpointMode(data[0]);
|
||||
var endpointAPIVersion = parseFloat(data[1].ApiVersion);
|
||||
state.endpoint.mode = endpointMode;
|
||||
state.endpoint.apiVersion = endpointAPIVersion;
|
||||
LocalStorage.storeEndpointState(state.endpoint);
|
||||
state.loading = false;
|
||||
deferred.resolve();
|
||||
}, function error(err) {
|
||||
state.loading = false;
|
||||
deferred.reject({msg: 'Unable to connect to the Docker endpoint', err: err});
|
||||
});
|
||||
return deferred.promise;
|
||||
},
|
||||
getState: function() {
|
||||
return state;
|
||||
manager.clean = function () {
|
||||
state.endpoint = {};
|
||||
};
|
||||
|
||||
manager.updateLogo = function(logoURL) {
|
||||
state.application.logo = logoURL;
|
||||
LocalStorage.storeApplicationState(state.application);
|
||||
};
|
||||
|
||||
manager.updateExternalContributions = function(displayExternalContributors) {
|
||||
state.application.displayExternalContributors = displayExternalContributors;
|
||||
LocalStorage.storeApplicationState(state.application);
|
||||
};
|
||||
|
||||
manager.initialize = function () {
|
||||
var deferred = $q.defer();
|
||||
|
||||
var endpointState = LocalStorage.getEndpointState();
|
||||
if (endpointState) {
|
||||
state.endpoint = endpointState;
|
||||
}
|
||||
|
||||
var applicationState = LocalStorage.getApplicationState();
|
||||
if (applicationState) {
|
||||
state.application = applicationState;
|
||||
state.loading = false;
|
||||
deferred.resolve(state);
|
||||
} else {
|
||||
$q.all({
|
||||
settings: SettingsService.settings(),
|
||||
status: StatusService.status()
|
||||
})
|
||||
.then(function success(data) {
|
||||
var status = data.status;
|
||||
var settings = data.settings;
|
||||
state.application.authentication = status.Authentication;
|
||||
state.application.analytics = status.Analytics;
|
||||
state.application.endpointManagement = status.EndpointManagement;
|
||||
state.application.version = status.Version;
|
||||
state.application.logo = settings.LogoURL;
|
||||
state.application.displayExternalContributors = settings.DisplayExternalContributors;
|
||||
LocalStorage.storeApplicationState(state.application);
|
||||
deferred.resolve(state);
|
||||
})
|
||||
.catch(function error(err) {
|
||||
deferred.reject({msg: 'Unable to retrieve server settings and status', err: err});
|
||||
})
|
||||
.finally(function final() {
|
||||
state.loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
manager.updateEndpointState = function(loading) {
|
||||
var deferred = $q.defer();
|
||||
if (loading) {
|
||||
state.loading = true;
|
||||
}
|
||||
$q.all([Info.get({}).$promise, Version.get({}).$promise])
|
||||
.then(function success(data) {
|
||||
var endpointMode = InfoHelper.determineEndpointMode(data[0]);
|
||||
var endpointAPIVersion = parseFloat(data[1].ApiVersion);
|
||||
state.endpoint.mode = endpointMode;
|
||||
state.endpoint.apiVersion = endpointAPIVersion;
|
||||
LocalStorage.storeEndpointState(state.endpoint);
|
||||
state.loading = false;
|
||||
deferred.resolve();
|
||||
}, function error(err) {
|
||||
state.loading = false;
|
||||
deferred.reject({msg: 'Unable to connect to the Docker endpoint', err: err});
|
||||
});
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
return manager;
|
||||
}]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue