1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-21 22:39:41 +02:00

feat(containers) - Add the ability to force remove a container with confirmation (#814)

This commit is contained in:
Thomas Krzero 2017-04-25 10:20:57 +02:00 committed by Anthony Lapenna
parent 2761959f93
commit ac872b577a
10 changed files with 48 additions and 13 deletions

View file

@ -19,7 +19,7 @@
<button class="btn btn-primary" ng-click="restart()" ng-disabled="!container.State.Running"><i class="fa fa-refresh space-right" aria-hidden="true"></i>Restart</button> <button class="btn btn-primary" ng-click="restart()" ng-disabled="!container.State.Running"><i class="fa fa-refresh space-right" aria-hidden="true"></i>Restart</button>
<button class="btn btn-primary" ng-click="pause()" ng-disabled="!container.State.Running || container.State.Paused"><i class="fa fa-pause space-right" aria-hidden="true"></i>Pause</button> <button class="btn btn-primary" ng-click="pause()" ng-disabled="!container.State.Running || container.State.Paused"><i class="fa fa-pause space-right" aria-hidden="true"></i>Pause</button>
<button class="btn btn-primary" ng-click="unpause()" ng-disabled="!container.State.Paused"><i class="fa fa-play space-right" aria-hidden="true"></i>Resume</button> <button class="btn btn-primary" ng-click="unpause()" ng-disabled="!container.State.Paused"><i class="fa fa-play space-right" aria-hidden="true"></i>Resume</button>
<button class="btn btn-danger" ng-click="remove()" ng-disabled="container.State.Running"><i class="fa fa-trash space-right" aria-hidden="true"></i>Remove</button> <button class="btn btn-danger" ng-click="confirmRemove()"><i class="fa fa-trash space-right" aria-hidden="true"></i>Remove</button>
</div> </div>
</rd-widget-body> </rd-widget-body>
</rd-widget> </rd-widget>

View file

@ -1,6 +1,6 @@
angular.module('container', []) angular.module('container', [])
.controller('ContainerController', ['$scope', '$state','$stateParams', '$filter', 'Container', 'ContainerCommit', 'ImageHelper', 'Network', 'Notifications', 'Pagination', .controller('ContainerController', ['$scope', '$state','$stateParams', '$filter', 'Container', 'ContainerCommit', 'ImageHelper', 'Network', 'Notifications', 'Pagination', 'ModalService',
function ($scope, $state, $stateParams, $filter, Container, ContainerCommit, ImageHelper, Network, Notifications, Pagination) { function ($scope, $state, $stateParams, $filter, Container, ContainerCommit, ImageHelper, Network, Notifications, Pagination, ModalService) {
$scope.activityTime = 0; $scope.activityTime = 0;
$scope.portBindings = []; $scope.portBindings = [];
$scope.config = { $scope.config = {
@ -116,9 +116,23 @@ function ($scope, $state, $stateParams, $filter, Container, ContainerCommit, Ima
}); });
}; };
$scope.remove = function () { $scope.confirmRemove = function () {
if ($scope.container.State.Running) {
ModalService.confirmDeletion(
'You are about to remove a running container.',
function (confirmed) {
if(!confirmed) { return; }
$scope.remove();
}
);
} else {
$scope.remove();
}
};
$scope.remove = function() {
$('#loadingViewSpinner').show(); $('#loadingViewSpinner').show();
Container.remove({id: $stateParams.id}, function (d) { Container.remove({id: $stateParams.id, force: true}, function (d) {
if (d.message) { if (d.message) {
$('#loadingViewSpinner').hide(); $('#loadingViewSpinner').hide();
Notifications.error("Failure", d, "Unable to remove container"); Notifications.error("Failure", d, "Unable to remove container");

View file

@ -31,7 +31,7 @@
<button type="button" class="btn btn-primary btn-responsive" ng-click="restartAction()" ng-disabled="!state.selectedItemCount"><i class="fa fa-refresh space-right" aria-hidden="true"></i>Restart</button> <button type="button" class="btn btn-primary btn-responsive" ng-click="restartAction()" ng-disabled="!state.selectedItemCount"><i class="fa fa-refresh space-right" aria-hidden="true"></i>Restart</button>
<button type="button" class="btn btn-primary btn-responsive" ng-click="pauseAction()" ng-disabled="!state.selectedItemCount"><i class="fa fa-pause space-right" aria-hidden="true"></i>Pause</button> <button type="button" class="btn btn-primary btn-responsive" ng-click="pauseAction()" ng-disabled="!state.selectedItemCount"><i class="fa fa-pause space-right" aria-hidden="true"></i>Pause</button>
<button type="button" class="btn btn-primary btn-responsive" ng-click="unpauseAction()" ng-disabled="!state.selectedItemCount"><i class="fa fa-play space-right" aria-hidden="true"></i>Resume</button> <button type="button" class="btn btn-primary btn-responsive" ng-click="unpauseAction()" ng-disabled="!state.selectedItemCount"><i class="fa fa-play space-right" aria-hidden="true"></i>Resume</button>
<button type="button" class="btn btn-danger btn-responsive" ng-click="removeAction()" ng-disabled="!state.selectedItemCount"><i class="fa fa-trash space-right" aria-hidden="true"></i>Remove</button> <button type="button" class="btn btn-danger btn-responsive" ng-click="confirmRemoveAction()" ng-disabled="!state.selectedItemCount"><i class="fa fa-trash space-right" aria-hidden="true"></i>Remove</button>
</div> </div>
<a class="btn btn-primary" type="button" ui-sref="actions.create.container"><i class="fa fa-plus space-right" aria-hidden="true"></i>Add container</a> <a class="btn btn-primary" type="button" ui-sref="actions.create.container"><i class="fa fa-plus space-right" aria-hidden="true"></i>Add container</a>
</div> </div>

View file

@ -128,7 +128,7 @@ angular.module('containers', [])
}); });
} }
else if (action === Container.remove) { else if (action === Container.remove) {
action({id: c.Id}, function (d) { action({id: c.Id, force: true}, function (d) {
if (d.message) { if (d.message) {
Notifications.error("Error", d, "Unable to remove container"); Notifications.error("Error", d, "Unable to remove container");
} }
@ -231,6 +231,27 @@ angular.module('containers', [])
batch($scope.containers, Container.remove, "Removed"); batch($scope.containers, Container.remove, "Removed");
}; };
$scope.confirmRemoveAction = function () {
var isOneContainerRunning = false;
angular.forEach($scope.containers, function (c) {
if (c.Checked && c.State === 'running') {
isOneContainerRunning = true;
return;
}
});
if (isOneContainerRunning) {
ModalService.confirmDeletion(
'You are about to remove one or more running containers.',
function (confirmed) {
if(!confirmed) { return; }
$scope.removeAction();
}
);
} else {
$scope.removeAction();
}
};
function retrieveSwarmHostsInfo(data) { function retrieveSwarmHostsInfo(data) {
var swarm_hosts = {}; var swarm_hosts = {};
var systemStatus = data.SystemStatus; var systemStatus = data.SystemStatus;

View file

@ -224,7 +224,7 @@ function ($scope, $stateParams, $state, $location, $anchorScroll, Service, Servi
$scope.removeService = function() { $scope.removeService = function() {
ModalService.confirmDeletion( ModalService.confirmDeletion(
'Do you want to delete this service? All the containers associated to this service will be removed too.', 'Do you want to remove this service? All the containers associated to this service will be removed too.',
function onConfirm(confirmed) { function onConfirm(confirmed) {
if(!confirmed) { return; } if(!confirmed) { return; }
removeService(); removeService();

View file

@ -70,7 +70,7 @@ function ($q, $scope, $stateParams, $state, Service, ServiceHelper, Notification
$scope.removeAction = function() { $scope.removeAction = function() {
ModalService.confirmDeletion( ModalService.confirmDeletion(
'Do you want to delete the selected service(s)? All the containers associated to the selected service(s) will be removed too.', 'Do you want to remove the selected service(s)? All the containers associated to the selected service(s) will be removed too.',
function onConfirm(confirmed) { function onConfirm(confirmed) {
if(!confirmed) { return; } if(!confirmed) { return; }
removeServices(); removeServices();

View file

@ -14,7 +14,7 @@ function ($scope, $state, $stateParams, UserService, ModalService, Notifications
$scope.deleteUser = function() { $scope.deleteUser = function() {
ModalService.confirmDeletion( ModalService.confirmDeletion(
'Do you want to delete this user? This user will not be able to login into Portainer anymore.', 'Do you want to remove this user? This user will not be able to login into Portainer anymore.',
function onConfirm(confirmed) { function onConfirm(confirmed) {
if(!confirmed) { return; } if(!confirmed) { return; }
deleteUser(); deleteUser();

View file

@ -103,7 +103,7 @@ function ($scope, $state, UserService, ModalService, Notifications, Pagination)
$scope.removeAction = function () { $scope.removeAction = function () {
ModalService.confirmDeletion( ModalService.confirmDeletion(
'Do you want to delete the selected users? They will not be able to login into Portainer anymore.', 'Do you want to remove the selected users? They will not be able to login into Portainer anymore.',
function onConfirm(confirmed) { function onConfirm(confirmed) {
if(!confirmed) { return; } if(!confirmed) { return; }
deleteSelectedUsers(); deleteSelectedUsers();

View file

@ -23,7 +23,7 @@ angular.module('portainer.rest')
transformResponse: genericHandler transformResponse: genericHandler
}, },
remove: { remove: {
method: 'DELETE', params: {id: '@id', v: 0}, method: 'DELETE', params: {id: '@id', v: 0, force: '@force'},
transformResponse: genericHandler transformResponse: genericHandler
}, },
rename: { rename: {

View file

@ -75,7 +75,7 @@ angular.module('portainer.services')
message: message, message: message,
buttons: { buttons: {
confirm: { confirm: {
label: 'Delete', label: 'Remove',
className: 'btn-danger' className: 'btn-danger'
} }
}, },