diff --git a/app/components/container/containerController.js b/app/components/container/containerController.js index 1af934c78..2523c37d2 100644 --- a/app/components/container/containerController.js +++ b/app/components/container/containerController.js @@ -1,6 +1,6 @@ angular.module('container', []) -.controller('ContainerController', ['$scope', '$state','$stateParams', '$filter', 'Container', 'ContainerCommit', 'ContainerHelper', 'ContainerService', 'ImageHelper', 'Network', 'NetworkService', 'Notifications', 'Pagination', 'ModalService', 'ResourceControlService', 'RegistryService', 'ImageService', -function ($scope, $state, $stateParams, $filter, Container, ContainerCommit, ContainerHelper, ContainerService, ImageHelper, Network, NetworkService, Notifications, Pagination, ModalService, ResourceControlService, RegistryService, ImageService) { +.controller('ContainerController', ['$q', '$scope', '$state','$stateParams', '$filter', 'Container', 'ContainerCommit', 'ContainerHelper', 'ContainerService', 'ImageHelper', 'Network', 'NetworkService', 'Notifications', 'Pagination', 'ModalService', 'ResourceControlService', 'RegistryService', 'ImageService', +function ($q, $scope, $state, $stateParams, $filter, Container, ContainerCommit, ContainerHelper, ContainerService, ImageHelper, Network, NetworkService, Notifications, Pagination, ModalService, ResourceControlService, RegistryService, ImageService) { $scope.activityTime = 0; $scope.portBindings = []; $scope.config = { @@ -203,62 +203,78 @@ function ($scope, $state, $stateParams, $filter, Container, ContainerCommit, Con }); }; + $scope.confirmRemove = function () { + var title = 'You are about to remove a container.'; + if ($scope.container.State.Running) { + title = 'You are about to remove a running container.'; + } + ModalService.confirmContainerDeletion( + title, + function (result) { + if(!result) { return; } + var cleanAssociatedVolumes = false; + if (result[0]) { + cleanAssociatedVolumes = true; + } + $scope.remove(cleanAssociatedVolumes); + } + ); + }; + + function recreateContainer(pullImage) { + $('#loadingViewSpinner').show(); + var container = $scope.container; + var config = ContainerHelper.configFromContainer(container.Model); + ContainerService.remove(container, true) + .then(function success() { + return RegistryService.retrieveRegistryFromRepository(container.Config.Image); + }) + .then(function success(data) { + return $q.when(!pullImage || ImageService.pullImage(container.Config.Image, data, true)); + }) + .then(function success() { + return ContainerService.createAndStartContainer(config); + }) + .then(function success(data) { + if (!container.ResourceControl) { + return true; + } else { + var containerIdentifier = data.Id; + var resourceControl = container.ResourceControl; + var users = resourceControl.UserAccesses.map(function(u) { + return u.UserId; + }); + var teams = resourceControl.TeamAccesses.map(function(t) { + return t.TeamId; + }); + return ResourceControlService.createResourceControl(resourceControl.AdministratorsOnly, + users, teams, containerIdentifier, 'container', []); + } + }) + .then(function success(data) { + Notifications.success('Container successfully re-created'); + $state.go('containers', {}, {reload: true}); + }) + .catch(function error(err) { + Notifications.error('Failure', err, 'Unable to re-create container'); + }) + .finally(function final() { + $('#loadingViewSpinner').hide(); + }); + } + $scope.recreate = function() { ModalService.confirmExperimentalFeature(function (experimental) { if(!experimental) { return; } - ModalService.confirm({ - title: 'Are you sure ?', - message: 'You\'re about to re-create this container, any non-persisted data will be lost. This container will be removed and another one will be created using the same configuration.', - buttons: { - confirm: { - label: 'Recreate', - className: 'btn-danger' - } - }, - callback: function onConfirm(confirmed) { - if(!confirmed) { return; } - else { - $('#loadingViewSpinner').show(); - var container = $scope.container; - var config = ContainerHelper.configFromContainer(container.Model); - ContainerService.remove(container, true) - .then(function success() { - return RegistryService.retrieveRegistryFromRepository(container.Config.Image); - }) - .then(function success(data) { - return ImageService.pullImage(container.Config.Image, data, true); - }) - .then(function success() { - return ContainerService.createAndStartContainer(config); - }) - .then(function success(data) { - if (!container.ResourceControl) { - return true; - } else { - var containerIdentifier = data.Id; - var resourceControl = container.ResourceControl; - var users = resourceControl.UserAccesses.map(function(u) { - return u.UserId; - }); - var teams = resourceControl.TeamAccesses.map(function(t) { - return t.TeamId; - }); - return ResourceControlService.createResourceControl(resourceControl.AdministratorsOnly, - users, teams, containerIdentifier, 'container', []); - } - }) - .then(function success(data) { - Notifications.success('Container successfully re-created'); - $state.go('containers', {}, {reload: true}); - }) - .catch(function error(err) { - Notifications.error('Failure', err, 'Unable to re-create container'); - }) - .finally(function final() { - $('#loadingViewSpinner').hide(); - }); - } + + ModalService.confirmContainerRecreation(function (result) { + if(!result) { return; } + console.log(JSON.stringify(result, null, 4)); + var pullImage = false; + if (result[0]) { + pullImage = true; } + recreateContainer(pullImage); }); }); }; diff --git a/app/services/modalService.js b/app/services/modalService.js index aa6481e40..81b0b84a9 100644 --- a/app/services/modalService.js +++ b/app/services/modalService.js @@ -46,6 +46,19 @@ angular.module('portainer.services') applyBoxCSS(box); }; + service.customPrompt = function(options) { + var box = bootbox.prompt({ + title: options.title, + inputType: options.inputType, + inputOptions: options.inputOptions, + buttons: confirmButtons(options), + callback: options.callback + }); + applyBoxCSS(box); + box.find('.bootbox-body').prepend('

' + options.message + '

'); + box.find('.bootbox-input-checkbox').prop('checked', true); + }; + service.confirmAccessControlUpdate = function(callback, msg) { service.confirm({ title: 'Are you sure ?', @@ -108,6 +121,27 @@ angular.module('portainer.services') }); }; + service.confirmContainerRecreation = function(callback) { + service.customPrompt({ + title: 'Are you sure?', + message: 'You\'re about to re-create this container, any non-persisted data will be lost. This container will be removed and another one will be created using the same configuration.', + inputType: 'checkbox', + inputOptions: [ + { + text: 'Pull latest image', + value: '1' + } + ], + buttons: { + confirm: { + label: 'Recreate', + className: 'btn-danger' + } + }, + callback: callback + }); + }; + service.confirmExperimentalFeature = function(callback) { service.confirm({ title: 'Experimental feature',