2018-06-11 15:13:19 +02:00
|
|
|
angular.module('portainer.app')
|
|
|
|
.controller('StacksController', ['$scope', '$state', 'Notifications', 'StackService', 'ModalService', 'EndpointProvider',
|
|
|
|
function ($scope, $state, Notifications, StackService, ModalService, EndpointProvider) {
|
2017-12-06 12:04:02 +01:00
|
|
|
$scope.removeAction = function(selectedItems) {
|
2017-10-15 19:24:40 +02:00
|
|
|
ModalService.confirmDeletion(
|
|
|
|
'Do you want to remove the selected stack(s)? Associated services will be removed as well.',
|
|
|
|
function onConfirm(confirmed) {
|
|
|
|
if(!confirmed) { return; }
|
2017-12-06 12:04:02 +01:00
|
|
|
deleteSelectedStacks(selectedItems);
|
2017-10-15 19:24:40 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2017-12-06 12:04:02 +01:00
|
|
|
function deleteSelectedStacks(stacks) {
|
2018-06-11 15:13:19 +02:00
|
|
|
var endpointId = EndpointProvider.endpointID();
|
2017-12-06 12:04:02 +01:00
|
|
|
var actionCount = stacks.length;
|
|
|
|
angular.forEach(stacks, function (stack) {
|
2018-06-11 15:13:19 +02:00
|
|
|
StackService.remove(stack, stack.External, endpointId)
|
2017-12-06 12:04:02 +01:00
|
|
|
.then(function success() {
|
|
|
|
Notifications.success('Stack successfully removed', stack.Name);
|
|
|
|
var index = $scope.stacks.indexOf(stack);
|
|
|
|
$scope.stacks.splice(index, 1);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
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
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-10-28 10:27:06 +01:00
|
|
|
$scope.offlineMode = false;
|
|
|
|
|
2019-07-22 12:54:59 +02:00
|
|
|
$scope.getStacks = getStacks;
|
|
|
|
function getStacks() {
|
2018-06-11 15:13:19 +02:00
|
|
|
var endpointMode = $scope.applicationState.endpoint.mode;
|
|
|
|
var endpointId = EndpointProvider.endpointID();
|
|
|
|
|
|
|
|
StackService.stacks(
|
|
|
|
true,
|
|
|
|
endpointMode.provider === 'DOCKER_SWARM_MODE' && endpointMode.role === 'MANAGER',
|
|
|
|
endpointId
|
|
|
|
)
|
2017-10-15 19:24:40 +02:00
|
|
|
.then(function success(data) {
|
|
|
|
var stacks = data;
|
|
|
|
$scope.stacks = stacks;
|
2018-10-28 10:27:06 +01:00
|
|
|
$scope.offlineMode = EndpointProvider.offlineMode();
|
2017-10-15 19:24:40 +02:00
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
$scope.stacks = [];
|
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve stacks');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-07-22 12:54:59 +02:00
|
|
|
function initView() {
|
|
|
|
getStacks();
|
|
|
|
}
|
|
|
|
|
2017-10-15 19:24:40 +02:00
|
|
|
initView();
|
|
|
|
}]);
|