From a48503d821f7611601e60cfc0c814dcfabefb283 Mon Sep 17 00:00:00 2001 From: Anthony Lapenna Date: Thu, 30 Mar 2017 11:22:59 +0200 Subject: [PATCH] feat(services): add a confirmation modal before deleting one or multiple services (#742) --- app/components/service/serviceController.js | 17 +++++++++++++---- app/components/services/servicesController.js | 18 ++++++++++++++++-- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/app/components/service/serviceController.js b/app/components/service/serviceController.js index 438038087..fa2cea01d 100644 --- a/app/components/service/serviceController.js +++ b/app/components/service/serviceController.js @@ -1,6 +1,6 @@ angular.module('service', []) -.controller('ServiceController', ['$scope', '$stateParams', '$state', '$location', '$anchorScroll', 'Service', 'ServiceHelper', 'Task', 'Node', 'Messages', 'Pagination', -function ($scope, $stateParams, $state, $location, $anchorScroll, Service, ServiceHelper, Task, Node, Messages, Pagination) { +.controller('ServiceController', ['$scope', '$stateParams', '$state', '$location', '$anchorScroll', 'Service', 'ServiceHelper', 'Task', 'Node', 'Messages', 'Pagination', 'ModalService', +function ($scope, $stateParams, $state, $location, $anchorScroll, Service, ServiceHelper, Task, Node, Messages, Pagination, ModalService) { $scope.state = {}; $scope.state.pagination_count = Pagination.getPaginationCount('service_tasks'); @@ -213,8 +213,17 @@ function ($scope, $stateParams, $state, $location, $anchorScroll, Service, Servi }); }; + $scope.removeService = function() { + ModalService.confirmDeletion( + 'Do you want to delete this service? All the containers associated to this service will be removed too.', + function onConfirm(confirmed) { + if(!confirmed) { return; } + removeService(); + } + ); + }; - $scope.removeService = function removeService() { + function removeService() { $('#loadingViewSpinner').show(); Service.remove({id: $stateParams.id}, function (d) { if (d.message) { @@ -229,7 +238,7 @@ function ($scope, $stateParams, $state, $location, $anchorScroll, Service, Servi $('#loadingViewSpinner').hide(); Messages.error("Failure", e, "Unable to remove service"); }); - }; + } function translateServiceArrays(service) { service.ServiceSecrets = service.Secrets; diff --git a/app/components/services/servicesController.js b/app/components/services/servicesController.js index 8adf51998..2a0522db6 100644 --- a/app/components/services/servicesController.js +++ b/app/components/services/servicesController.js @@ -68,7 +68,17 @@ function ($q, $scope, $stateParams, $state, Service, ServiceHelper, Messages, Pa }); }; - $scope.removeAction = function () { + $scope.removeAction = function() { + ModalService.confirmDeletion( + 'Do you want to delete the selected service(s)? All the containers associated to the selected service(s) will be removed too.', + function onConfirm(confirmed) { + if(!confirmed) { return; } + removeServices(); + } + ); + }; + + function removeServices() { $('#loadServicesSpinner').show(); var counter = 0; var complete = function () { @@ -108,7 +118,11 @@ function ($q, $scope, $stateParams, $state, Service, ServiceHelper, Messages, Pa }); } }); - }; + } + + // $scope.removeAction = function () { + // + // }; function mapUsersToServices(users) { angular.forEach($scope.services, function (service) {