feat(app/volumes): add confirmation modal before deleting volumes in volumes view and volume view (#4597)

pull/4516/head
Alice Groux 2020-12-16 07:57:31 +01:00 committed by GitHub
parent bd98b8956a
commit 58bf76a58f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 26 deletions

View File

@ -51,14 +51,18 @@ angular.module('portainer.docker').controller('VolumeController', [
}; };
$scope.removeVolume = function removeVolume() { $scope.removeVolume = function removeVolume() {
VolumeService.remove($scope.volume) ModalService.confirmDeletion('Do you want to remove this volume?', (confirmed) => {
.then(function success() { if (confirmed) {
Notifications.success('Volume successfully removed', $transition$.params().id); VolumeService.remove($scope.volume)
$state.go('docker.volumes', {}); .then(function success() {
}) Notifications.success('Volume successfully removed', $transition$.params().id);
.catch(function error(err) { $state.go('docker.volumes', {});
Notifications.error('Failure', err, 'Unable to remove volume'); })
}); .catch(function error(err) {
Notifications.error('Failure', err, 'Unable to remove volume');
});
}
});
}; };
function getVolumeDataFromContainer(container, volumeId) { function getVolumeDataFromContainer(container, volumeId) {

View File

@ -9,26 +9,31 @@ angular.module('portainer.docker').controller('VolumesController', [
'HttpRequestHelper', 'HttpRequestHelper',
'EndpointProvider', 'EndpointProvider',
'Authentication', 'Authentication',
function ($q, $scope, $state, VolumeService, ServiceService, VolumeHelper, Notifications, HttpRequestHelper, EndpointProvider, Authentication) { 'ModalService',
function ($q, $scope, $state, VolumeService, ServiceService, VolumeHelper, Notifications, HttpRequestHelper, EndpointProvider, Authentication, ModalService) {
$scope.removeAction = function (selectedItems) { $scope.removeAction = function (selectedItems) {
var actionCount = selectedItems.length; ModalService.confirmDeletion('Do you want to remove the selected volume(s)?', (confirmed) => {
angular.forEach(selectedItems, function (volume) { if (confirmed) {
HttpRequestHelper.setPortainerAgentTargetHeader(volume.NodeName); var actionCount = selectedItems.length;
VolumeService.remove(volume) angular.forEach(selectedItems, function (volume) {
.then(function success() { HttpRequestHelper.setPortainerAgentTargetHeader(volume.NodeName);
Notifications.success('Volume successfully removed', volume.Id); VolumeService.remove(volume)
var index = $scope.volumes.indexOf(volume); .then(function success() {
$scope.volumes.splice(index, 1); Notifications.success('Volume successfully removed', volume.Id);
}) var index = $scope.volumes.indexOf(volume);
.catch(function error(err) { $scope.volumes.splice(index, 1);
Notifications.error('Failure', err, 'Unable to remove volume'); })
}) .catch(function error(err) {
.finally(function final() { Notifications.error('Failure', err, 'Unable to remove volume');
--actionCount; })
if (actionCount === 0) { .finally(function final() {
$state.reload(); --actionCount;
} if (actionCount === 0) {
$state.reload();
}
});
}); });
}
}); });
}; };