2023-02-14 13:49:41 +05:30
|
|
|
import { confirmDelete } from '@@/modals/confirm';
|
|
|
|
|
2020-07-27 10:11:32 +03:00
|
|
|
angular.module('portainer.app').controller('StacksController', StacksController);
|
2018-10-28 10:27:06 +01:00
|
|
|
|
2020-07-27 10:11:32 +03:00
|
|
|
/* @ngInject */
|
2023-02-14 13:49:41 +05:30
|
|
|
function StacksController($scope, $state, Notifications, StackService, Authentication, endpoint) {
|
2020-07-27 10:11:32 +03:00
|
|
|
$scope.removeAction = function (selectedItems) {
|
2023-02-14 13:49:41 +05:30
|
|
|
confirmDelete('Do you want to remove the selected stack(s)? Associated services will be removed as well.').then((confirmed) => {
|
2020-07-27 10:11:32 +03:00
|
|
|
if (!confirmed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
deleteSelectedStacks(selectedItems);
|
|
|
|
});
|
|
|
|
};
|
2018-06-11 15:13:19 +02:00
|
|
|
|
2020-07-27 10:11:32 +03:00
|
|
|
function deleteSelectedStacks(stacks) {
|
2021-12-14 09:34:54 +02:00
|
|
|
const endpointId = endpoint.Id;
|
|
|
|
let actionCount = stacks.length;
|
2020-07-27 10:11:32 +03:00
|
|
|
angular.forEach(stacks, function (stack) {
|
|
|
|
StackService.remove(stack, stack.External, endpointId)
|
|
|
|
.then(function success() {
|
|
|
|
Notifications.success('Stack successfully removed', stack.Name);
|
|
|
|
var index = $scope.stacks.indexOf(stack);
|
|
|
|
$scope.stacks.splice(index, 1);
|
2017-10-15 19:24:40 +02:00
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
2020-07-27 10:11:32 +03:00
|
|
|
Notifications.error('Failure', err, 'Unable to remove stack ' + stack.Name);
|
|
|
|
})
|
|
|
|
.finally(function final() {
|
|
|
|
--actionCount;
|
|
|
|
if (actionCount === 0) {
|
|
|
|
$state.reload();
|
|
|
|
}
|
2017-10-15 19:24:40 +02:00
|
|
|
});
|
2020-07-27 10:11:32 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.createEnabled = false;
|
|
|
|
|
|
|
|
$scope.getStacks = getStacks;
|
|
|
|
|
|
|
|
function getStacks() {
|
2021-12-14 09:34:54 +02:00
|
|
|
const endpointMode = $scope.applicationState.endpoint.mode;
|
|
|
|
const endpointId = endpoint.Id;
|
2020-07-27 10:11:32 +03:00
|
|
|
|
2021-06-10 14:52:33 +12:00
|
|
|
const includeOrphanedStacks = Authentication.isAdmin();
|
|
|
|
StackService.stacks(true, endpointMode.provider === 'DOCKER_SWARM_MODE' && endpointMode.role === 'MANAGER', endpointId, includeOrphanedStacks)
|
2021-12-14 09:34:54 +02:00
|
|
|
.then(function success(stacks) {
|
2020-07-27 10:11:32 +03:00
|
|
|
$scope.stacks = stacks;
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
$scope.stacks = [];
|
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve stacks');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-08-03 22:19:27 +12:00
|
|
|
async function canManageStacks() {
|
2021-02-09 10:09:06 +02:00
|
|
|
return endpoint.SecuritySettings.allowStackManagementForRegularUsers || Authentication.isAdmin();
|
2020-07-27 10:11:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
async function initView() {
|
2022-08-03 22:19:27 +12:00
|
|
|
// if the user is not an admin, and stack management is disabled for non admins, then take the user to the dashboard
|
|
|
|
$scope.createEnabled = await canManageStacks();
|
|
|
|
if (!$scope.createEnabled) {
|
|
|
|
$state.go('docker.dashboard');
|
|
|
|
}
|
2020-07-27 10:11:32 +03:00
|
|
|
getStacks();
|
|
|
|
}
|
|
|
|
|
|
|
|
initView();
|
|
|
|
}
|