mirror of https://github.com/portainer/portainer
refactor(docker/configs): remove EndpointProvider [EE-5746] (#9198)
parent
cd3c6e3089
commit
1b0fd60115
|
@ -1,13 +1,12 @@
|
||||||
angular.module('portainer.docker').factory('Config', [
|
angular.module('portainer.docker').factory('Config', [
|
||||||
'$resource',
|
'$resource',
|
||||||
'API_ENDPOINT_ENDPOINTS',
|
'API_ENDPOINT_ENDPOINTS',
|
||||||
'EndpointProvider',
|
function ConfigFactory($resource, API_ENDPOINT_ENDPOINTS) {
|
||||||
function ConfigFactory($resource, API_ENDPOINT_ENDPOINTS, EndpointProvider) {
|
|
||||||
'use strict';
|
'use strict';
|
||||||
return $resource(
|
return $resource(
|
||||||
API_ENDPOINT_ENDPOINTS + '/:endpointId/docker/configs/:id/:action',
|
API_ENDPOINT_ENDPOINTS + '/:environmentId/docker/configs/:id/:action',
|
||||||
{
|
{
|
||||||
endpointId: EndpointProvider.endpointID,
|
environmentId: '@environmentId',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
get: { method: 'GET', params: { id: '@id' } },
|
get: { method: 'GET', params: { id: '@id' } },
|
||||||
|
|
|
@ -7,10 +7,10 @@ angular.module('portainer.docker').factory('ConfigService', [
|
||||||
'use strict';
|
'use strict';
|
||||||
var service = {};
|
var service = {};
|
||||||
|
|
||||||
service.config = function (configId) {
|
service.config = function (environmentId, configId) {
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
|
|
||||||
Config.get({ id: configId })
|
Config.get({ id: configId, environmentId })
|
||||||
.$promise.then(function success(data) {
|
.$promise.then(function success(data) {
|
||||||
var config = new ConfigViewModel(data);
|
var config = new ConfigViewModel(data);
|
||||||
deferred.resolve(config);
|
deferred.resolve(config);
|
||||||
|
@ -22,10 +22,10 @@ angular.module('portainer.docker').factory('ConfigService', [
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
service.configs = function () {
|
service.configs = function (environmentId) {
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
|
|
||||||
Config.query({})
|
Config.query({ environmentId })
|
||||||
.$promise.then(function success(data) {
|
.$promise.then(function success(data) {
|
||||||
var configs = data.map(function (item) {
|
var configs = data.map(function (item) {
|
||||||
return new ConfigViewModel(item);
|
return new ConfigViewModel(item);
|
||||||
|
@ -39,10 +39,10 @@ angular.module('portainer.docker').factory('ConfigService', [
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
service.remove = function (configId) {
|
service.remove = function (environmentId, configId) {
|
||||||
var deferred = $q.defer();
|
var deferred = $q.defer();
|
||||||
|
|
||||||
Config.remove({ id: configId })
|
Config.remove({ environmentId, id: configId })
|
||||||
.$promise.then(function success(data) {
|
.$promise.then(function success(data) {
|
||||||
if (data.message) {
|
if (data.message) {
|
||||||
deferred.reject({ msg: data.message });
|
deferred.reject({ msg: data.message });
|
||||||
|
@ -57,8 +57,8 @@ angular.module('portainer.docker').factory('ConfigService', [
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
service.create = function (config) {
|
service.create = function (environmentId, config) {
|
||||||
return Config.create(config).$promise;
|
return Config.create({ environmentId }, config).$promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
return service;
|
return service;
|
||||||
|
|
|
@ -3,11 +3,12 @@ import { confirmDelete } from '@@/modals/confirm';
|
||||||
|
|
||||||
class ConfigsController {
|
class ConfigsController {
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
constructor($state, ConfigService, Notifications, $async) {
|
constructor($state, ConfigService, Notifications, $async, endpoint) {
|
||||||
this.$state = $state;
|
this.$state = $state;
|
||||||
this.ConfigService = ConfigService;
|
this.ConfigService = ConfigService;
|
||||||
this.Notifications = Notifications;
|
this.Notifications = Notifications;
|
||||||
this.$async = $async;
|
this.$async = $async;
|
||||||
|
this.endpoint = endpoint;
|
||||||
|
|
||||||
this.removeAction = this.removeAction.bind(this);
|
this.removeAction = this.removeAction.bind(this);
|
||||||
this.removeActionAsync = this.removeActionAsync.bind(this);
|
this.removeActionAsync = this.removeActionAsync.bind(this);
|
||||||
|
@ -21,7 +22,7 @@ class ConfigsController {
|
||||||
|
|
||||||
async getConfigsAsync() {
|
async getConfigsAsync() {
|
||||||
try {
|
try {
|
||||||
this.configs = await this.ConfigService.configs();
|
this.configs = await this.ConfigService.configs(this.endpoint.Id);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.Notifications.error('Failure', err, 'Unable to retrieve configs');
|
this.Notifications.error('Failure', err, 'Unable to retrieve configs');
|
||||||
}
|
}
|
||||||
|
@ -44,7 +45,7 @@ class ConfigsController {
|
||||||
let actionCount = selectedItems.length;
|
let actionCount = selectedItems.length;
|
||||||
for (const config of selectedItems) {
|
for (const config of selectedItems) {
|
||||||
try {
|
try {
|
||||||
await this.ConfigService.remove(config.Id);
|
await this.ConfigService.remove(this.endpoint.Id, config.Id);
|
||||||
this.Notifications.success('Config successfully removed', config.Name);
|
this.Notifications.success('Config successfully removed', config.Name);
|
||||||
const index = this.configs.indexOf(config);
|
const index = this.configs.indexOf(config);
|
||||||
this.configs.splice(index, 1);
|
this.configs.splice(index, 1);
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { confirmWebEditorDiscard } from '@@/modals/confirm';
|
||||||
|
|
||||||
class CreateConfigController {
|
class CreateConfigController {
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
constructor($async, $state, $transition$, $window, Notifications, ConfigService, Authentication, FormValidator, ResourceControlService) {
|
constructor($async, $state, $transition$, $window, Notifications, ConfigService, Authentication, FormValidator, ResourceControlService, endpoint) {
|
||||||
this.$state = $state;
|
this.$state = $state;
|
||||||
this.$transition$ = $transition$;
|
this.$transition$ = $transition$;
|
||||||
this.$window = $window;
|
this.$window = $window;
|
||||||
|
@ -15,6 +15,7 @@ class CreateConfigController {
|
||||||
this.FormValidator = FormValidator;
|
this.FormValidator = FormValidator;
|
||||||
this.ResourceControlService = ResourceControlService;
|
this.ResourceControlService = ResourceControlService;
|
||||||
this.$async = $async;
|
this.$async = $async;
|
||||||
|
this.endpoint = endpoint;
|
||||||
|
|
||||||
this.formValues = {
|
this.formValues = {
|
||||||
Name: '',
|
Name: '',
|
||||||
|
@ -45,7 +46,7 @@ class CreateConfigController {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let data = await this.ConfigService.config(this.$transition$.params().id);
|
let data = await this.ConfigService.config(this.endpoint.Id, this.$transition$.params().id);
|
||||||
this.formValues.Name = data.Name + '_copy';
|
this.formValues.Name = data.Name + '_copy';
|
||||||
this.formValues.ConfigContent = data.Data;
|
this.formValues.ConfigContent = data.Data;
|
||||||
let labels = _.keys(data.Labels);
|
let labels = _.keys(data.Labels);
|
||||||
|
@ -135,7 +136,7 @@ class CreateConfigController {
|
||||||
const config = this.prepareConfiguration();
|
const config = this.prepareConfiguration();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await this.ConfigService.create(config);
|
const data = await this.ConfigService.create(this.endpoint.Id, config);
|
||||||
const resourceControl = data.Portainer.ResourceControl;
|
const resourceControl = data.Portainer.ResourceControl;
|
||||||
const userId = userDetails.ID;
|
const userId = userDetails.ID;
|
||||||
await this.ResourceControlService.applyResourceControl(userId, accessControlData, resourceControl);
|
await this.ResourceControlService.applyResourceControl(userId, accessControlData, resourceControl);
|
||||||
|
|
|
@ -6,7 +6,8 @@ angular.module('portainer.docker').controller('ConfigController', [
|
||||||
'$state',
|
'$state',
|
||||||
'ConfigService',
|
'ConfigService',
|
||||||
'Notifications',
|
'Notifications',
|
||||||
function ($scope, $transition$, $state, ConfigService, Notifications) {
|
'endpoint',
|
||||||
|
function ($scope, $transition$, $state, ConfigService, Notifications, endpoint) {
|
||||||
$scope.resourceType = ResourceControlType.Config;
|
$scope.resourceType = ResourceControlType.Config;
|
||||||
|
|
||||||
$scope.onUpdateResourceControlSuccess = function () {
|
$scope.onUpdateResourceControlSuccess = function () {
|
||||||
|
@ -14,7 +15,7 @@ angular.module('portainer.docker').controller('ConfigController', [
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.removeConfig = function removeConfig(configId) {
|
$scope.removeConfig = function removeConfig(configId) {
|
||||||
ConfigService.remove(configId)
|
ConfigService.remove(endpoint.Id, configId)
|
||||||
.then(function success() {
|
.then(function success() {
|
||||||
Notifications.success('Success', 'Configuration successfully removed');
|
Notifications.success('Success', 'Configuration successfully removed');
|
||||||
$state.go('docker.configs', {});
|
$state.go('docker.configs', {});
|
||||||
|
@ -25,7 +26,7 @@ angular.module('portainer.docker').controller('ConfigController', [
|
||||||
};
|
};
|
||||||
|
|
||||||
function initView() {
|
function initView() {
|
||||||
ConfigService.config($transition$.params().id)
|
ConfigService.config(endpoint.Id, $transition$.params().id)
|
||||||
.then(function success(data) {
|
.then(function success(data) {
|
||||||
$scope.config = data;
|
$scope.config = data;
|
||||||
})
|
})
|
||||||
|
|
|
@ -608,7 +608,7 @@ angular.module('portainer.docker').controller('CreateServiceController', [
|
||||||
volumes: VolumeService.volumes(),
|
volumes: VolumeService.volumes(),
|
||||||
networks: NetworkService.networks(true, true, false),
|
networks: NetworkService.networks(true, true, false),
|
||||||
secrets: apiVersion >= 1.25 ? SecretService.secrets() : [],
|
secrets: apiVersion >= 1.25 ? SecretService.secrets() : [],
|
||||||
configs: apiVersion >= 1.3 ? ConfigService.configs() : [],
|
configs: apiVersion >= 1.3 ? ConfigService.configs(endpoint.Id) : [],
|
||||||
nodes: NodeService.nodes(),
|
nodes: NodeService.nodes(),
|
||||||
availableLoggingDrivers: PluginService.loggingPlugins(apiVersion < 1.25),
|
availableLoggingDrivers: PluginService.loggingPlugins(apiVersion < 1.25),
|
||||||
allowBindMounts: checkIfAllowedBindMounts(),
|
allowBindMounts: checkIfAllowedBindMounts(),
|
||||||
|
|
|
@ -717,7 +717,7 @@ angular.module('portainer.docker').controller('ServiceController', [
|
||||||
containers: agentProxy ? ContainerService.containers() : [],
|
containers: agentProxy ? ContainerService.containers() : [],
|
||||||
nodes: NodeService.nodes(),
|
nodes: NodeService.nodes(),
|
||||||
secrets: apiVersion >= 1.25 ? SecretService.secrets() : [],
|
secrets: apiVersion >= 1.25 ? SecretService.secrets() : [],
|
||||||
configs: apiVersion >= 1.3 ? ConfigService.configs() : [],
|
configs: apiVersion >= 1.3 ? ConfigService.configs(endpoint.Id) : [],
|
||||||
availableImages: ImageService.images(),
|
availableImages: ImageService.images(),
|
||||||
availableLoggingDrivers: PluginService.loggingPlugins(apiVersion < 1.25),
|
availableLoggingDrivers: PluginService.loggingPlugins(apiVersion < 1.25),
|
||||||
availableNetworks: NetworkService.networks(true, true, apiVersion >= 1.25),
|
availableNetworks: NetworkService.networks(true, true, apiVersion >= 1.25),
|
||||||
|
|
Loading…
Reference in New Issue