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