2019-03-21 05:46:49 +00:00
|
|
|
import { ConfigViewModel } from '../models/config';
|
|
|
|
|
2018-02-01 12:27:52 +00:00
|
|
|
angular.module('portainer.docker')
|
2017-11-06 08:47:31 +00:00
|
|
|
.factory('ConfigService', ['$q', 'Config', function ConfigServiceFactory($q, Config) {
|
|
|
|
'use strict';
|
|
|
|
var service = {};
|
|
|
|
|
|
|
|
service.config = function(configId) {
|
|
|
|
var deferred = $q.defer();
|
|
|
|
|
|
|
|
Config.get({id: configId}).$promise
|
|
|
|
.then(function success(data) {
|
|
|
|
var config = new ConfigViewModel(data);
|
|
|
|
deferred.resolve(config);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
deferred.reject({ msg: 'Unable to retrieve config details', err: err });
|
|
|
|
});
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
};
|
|
|
|
|
|
|
|
service.configs = function() {
|
|
|
|
var deferred = $q.defer();
|
|
|
|
|
|
|
|
Config.query({}).$promise
|
|
|
|
.then(function success(data) {
|
|
|
|
var configs = data.map(function (item) {
|
|
|
|
return new ConfigViewModel(item);
|
|
|
|
});
|
|
|
|
deferred.resolve(configs);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
deferred.reject({ msg: 'Unable to retrieve configs', err: err });
|
|
|
|
});
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
};
|
|
|
|
|
|
|
|
service.remove = function(configId) {
|
|
|
|
var deferred = $q.defer();
|
|
|
|
|
|
|
|
Config.remove({ id: configId }).$promise
|
|
|
|
.then(function success(data) {
|
|
|
|
if (data.message) {
|
|
|
|
deferred.reject({ msg: data.message });
|
|
|
|
} else {
|
|
|
|
deferred.resolve();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
deferred.reject({ msg: 'Unable to remove config', err: err });
|
|
|
|
});
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
};
|
|
|
|
|
|
|
|
service.create = function(config) {
|
|
|
|
return Config.create(config).$promise;
|
|
|
|
};
|
|
|
|
|
|
|
|
return service;
|
|
|
|
}]);
|