mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 07:49:41 +02:00
feat(containers) - clean non-persistent volumes when removing a container (#824)
This commit is contained in:
parent
5a07638f4d
commit
3d8eec2557
5 changed files with 103 additions and 40 deletions
|
@ -119,22 +119,26 @@ function ($scope, $state, $stateParams, $filter, Container, ContainerCommit, Ima
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.confirmRemove = function () {
|
$scope.confirmRemove = function () {
|
||||||
|
var title = 'You are about to remove a container.';
|
||||||
if ($scope.container.State.Running) {
|
if ($scope.container.State.Running) {
|
||||||
ModalService.confirmDeletion(
|
title = 'You are about to remove a running container.';
|
||||||
'You are about to remove a running container.',
|
|
||||||
function (confirmed) {
|
|
||||||
if(!confirmed) { return; }
|
|
||||||
$scope.remove();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$scope.remove();
|
|
||||||
}
|
}
|
||||||
|
ModalService.confirmContainerDeletion(
|
||||||
|
title,
|
||||||
|
function (result) {
|
||||||
|
if(!result) { return; }
|
||||||
|
var cleanAssociatedVolumes = false;
|
||||||
|
if (result[0]) {
|
||||||
|
cleanAssociatedVolumes = true;
|
||||||
|
}
|
||||||
|
$scope.remove(cleanAssociatedVolumes);
|
||||||
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.remove = function() {
|
$scope.remove = function(cleanAssociatedVolumes) {
|
||||||
$('#loadingViewSpinner').show();
|
$('#loadingViewSpinner').show();
|
||||||
Container.remove({id: $stateParams.id, force: true}, function (d) {
|
Container.remove({id: $stateParams.id, v: (cleanAssociatedVolumes) ? 1 : 0, 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");
|
||||||
|
|
|
@ -17,6 +17,8 @@ angular.module('containers', [])
|
||||||
Pagination.setPaginationCount('containers', $scope.state.pagination_count);
|
Pagination.setPaginationCount('containers', $scope.state.pagination_count);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.cleanAssociatedVolumes = false;
|
||||||
|
|
||||||
function removeContainerResourceControl(container) {
|
function removeContainerResourceControl(container) {
|
||||||
volumeResourceControlQueries = [];
|
volumeResourceControlQueries = [];
|
||||||
angular.forEach(container.Mounts, function (volume) {
|
angular.forEach(container.Mounts, function (volume) {
|
||||||
|
@ -128,7 +130,7 @@ angular.module('containers', [])
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (action === Container.remove) {
|
else if (action === Container.remove) {
|
||||||
action({id: c.Id, force: true}, function (d) {
|
action({id: c.Id, v: ($scope.cleanAssociatedVolumes) ? 1 : 0, 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");
|
||||||
}
|
}
|
||||||
|
@ -239,17 +241,21 @@ angular.module('containers', [])
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
var title = 'You are about to remove one or more container.';
|
||||||
if (isOneContainerRunning) {
|
if (isOneContainerRunning) {
|
||||||
ModalService.confirmDeletion(
|
title = 'You are about to remove one or more running containers.';
|
||||||
'You are about to remove one or more running containers.',
|
|
||||||
function (confirmed) {
|
|
||||||
if(!confirmed) { return; }
|
|
||||||
$scope.removeAction();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$scope.removeAction();
|
|
||||||
}
|
}
|
||||||
|
ModalService.confirmContainerDeletion(
|
||||||
|
title,
|
||||||
|
function (result) {
|
||||||
|
if(!result) { return; }
|
||||||
|
$scope.cleanAssociatedVolumes = false;
|
||||||
|
if (result[0]) {
|
||||||
|
$scope.cleanAssociatedVolumes = true;
|
||||||
|
}
|
||||||
|
$scope.removeAction();
|
||||||
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
function retrieveSwarmHostsInfo(data) {
|
function retrieveSwarmHostsInfo(data) {
|
||||||
|
|
|
@ -23,7 +23,7 @@ angular.module('portainer.rest')
|
||||||
transformResponse: genericHandler
|
transformResponse: genericHandler
|
||||||
},
|
},
|
||||||
remove: {
|
remove: {
|
||||||
method: 'DELETE', params: {id: '@id', v: 0, force: '@force'},
|
method: 'DELETE', params: {id: '@id', v: '@v', force: '@force'},
|
||||||
transformResponse: genericHandler
|
transformResponse: genericHandler
|
||||||
},
|
},
|
||||||
rename: {
|
rename: {
|
||||||
|
|
|
@ -3,21 +3,7 @@ angular.module('portainer.services')
|
||||||
'use strict';
|
'use strict';
|
||||||
var service = {};
|
var service = {};
|
||||||
|
|
||||||
service.confirm = function(options){
|
var applyBoxCSS = function(box) {
|
||||||
var box = bootbox.confirm({
|
|
||||||
title: options.title,
|
|
||||||
message: options.message,
|
|
||||||
buttons: {
|
|
||||||
confirm: {
|
|
||||||
label: options.buttons.confirm.label,
|
|
||||||
className: options.buttons.confirm.className
|
|
||||||
},
|
|
||||||
cancel: {
|
|
||||||
label: options.buttons.cancel && options.buttons.cancel.label ? options.buttons.cancel.label : 'Cancel'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
callback: options.callback
|
|
||||||
});
|
|
||||||
box.css({
|
box.css({
|
||||||
'top': '50%',
|
'top': '50%',
|
||||||
'margin-top': function () {
|
'margin-top': function () {
|
||||||
|
@ -26,6 +12,40 @@ angular.module('portainer.services')
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var confirmButtons = function(options) {
|
||||||
|
var buttons = {
|
||||||
|
confirm: {
|
||||||
|
label: options.buttons.confirm.label,
|
||||||
|
className: options.buttons.confirm.className
|
||||||
|
},
|
||||||
|
cancel: {
|
||||||
|
label: options.buttons.cancel && options.buttons.cancel.label ? options.buttons.cancel.label : 'Cancel'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return buttons;
|
||||||
|
};
|
||||||
|
|
||||||
|
service.confirm = function(options){
|
||||||
|
var box = bootbox.confirm({
|
||||||
|
title: options.title,
|
||||||
|
message: options.message,
|
||||||
|
buttons: confirmButtons(options),
|
||||||
|
callback: options.callback
|
||||||
|
});
|
||||||
|
applyBoxCSS(box);
|
||||||
|
};
|
||||||
|
|
||||||
|
service.prompt = function(options){
|
||||||
|
var box = bootbox.prompt({
|
||||||
|
title: options.title,
|
||||||
|
inputType: options.inputType,
|
||||||
|
inputOptions: options.inputOptions,
|
||||||
|
buttons: confirmButtons(options),
|
||||||
|
callback: options.callback
|
||||||
|
});
|
||||||
|
applyBoxCSS(box);
|
||||||
|
};
|
||||||
|
|
||||||
service.confirmOwnershipChange = function(callback, msg) {
|
service.confirmOwnershipChange = function(callback, msg) {
|
||||||
service.confirm({
|
service.confirm({
|
||||||
title: 'Are you sure ?',
|
title: 'Are you sure ?',
|
||||||
|
@ -82,5 +102,26 @@ angular.module('portainer.services')
|
||||||
callback: callback,
|
callback: callback,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
service.confirmContainerDeletion = function(title, callback) {
|
||||||
|
service.prompt({
|
||||||
|
title: title,
|
||||||
|
inputType: 'checkbox',
|
||||||
|
inputOptions: [
|
||||||
|
{
|
||||||
|
text: 'Automatically remove non-persistent volumes<i></i>',
|
||||||
|
value: '1'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
buttons: {
|
||||||
|
confirm: {
|
||||||
|
label: 'Remove',
|
||||||
|
className: 'btn-danger'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
callback: callback
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return service;
|
return service;
|
||||||
}]);
|
}]);
|
||||||
|
|
|
@ -371,11 +371,23 @@ ul.sidebar .sidebar-list .sidebar-sublist a.active {
|
||||||
float: none !important;
|
float: none !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.bootbox-form .bootbox-input-checkbox {
|
||||||
|
display: none
|
||||||
|
}
|
||||||
|
|
||||||
|
.bootbox-form label {
|
||||||
|
padding-left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.switch input {
|
.switch input {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.switch i {
|
.bootbox-form .checkbox i {
|
||||||
|
margin-left: 21px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.switch i, .bootbox-form .checkbox i {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
@ -386,7 +398,7 @@ ul.sidebar .sidebar-list .sidebar-sublist a.active {
|
||||||
box-shadow: inset 0 0 1px 1px rgba(0,0,0,.5);
|
box-shadow: inset 0 0 1px 1px rgba(0,0,0,.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
.switch i:before {
|
.switch i:before, .bootbox-form .checkbox i:before {
|
||||||
display: block;
|
display: block;
|
||||||
content: '';
|
content: '';
|
||||||
width: 24px;
|
width: 24px;
|
||||||
|
@ -396,7 +408,7 @@ ul.sidebar .sidebar-list .sidebar-sublist a.active {
|
||||||
box-shadow: 0 0 1px 1px rgba(0,0,0,.5);
|
box-shadow: 0 0 1px 1px rgba(0,0,0,.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
.switch :checked + i {
|
.switch :checked + i, .bootbox-form .checkbox :checked ~ i {
|
||||||
padding-right: 0;
|
padding-right: 0;
|
||||||
padding-left: 24px;
|
padding-left: 24px;
|
||||||
-webkit-box-shadow: inset 0 0 1px rgba(0,0,0,.5), inset 0 0 40px #337ab7;
|
-webkit-box-shadow: inset 0 0 1px rgba(0,0,0,.5), inset 0 0 40px #337ab7;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue