From b8eb7c51b672291c28ceb4474b734614062cebc7 Mon Sep 17 00:00:00 2001 From: Chris Houseknecht Date: Wed, 5 Mar 2014 00:28:37 -0500 Subject: [PATCH] AC-1024 Hosts deletes now work as described in the ticket. Removing a host from a group removes it from the selected group and its children. Removing a host from a group does still leave it in All Hosts, and this is explained in the dialog prompt. Removing it from All Hosts permanently deletes it, again explained in the dialog prompt. --- awx/ui/static/js/controllers/Inventories.js | 3 + awx/ui/static/js/helpers/Hosts.js | 75 +++++++++++++++------ awx/ui/static/lib/ansible/InventoryTree.js | 1 + 3 files changed, 59 insertions(+), 20 deletions(-) diff --git a/awx/ui/static/js/controllers/Inventories.js b/awx/ui/static/js/controllers/Inventories.js index 62ef547bf9..8f21e36a06 100644 --- a/awx/ui/static/js/controllers/Inventories.js +++ b/awx/ui/static/js/controllers/Inventories.js @@ -484,6 +484,9 @@ function InventoriesEdit($scope, $location, $routeParams, $compile, GenerateList $scope.groups[i].active_class = ''; } } + if (Empty($scope.inventory_id)) { + $scope.inventory_id = $scope.groups[0].inentory_id; + } HostsReload({ scope: $scope, group_id: group_id, diff --git a/awx/ui/static/js/helpers/Hosts.js b/awx/ui/static/js/helpers/Hosts.js index eb0c5587bc..9cbf93eee1 100644 --- a/awx/ui/static/js/helpers/Hosts.js +++ b/awx/ui/static/js/helpers/Hosts.js @@ -633,8 +633,8 @@ function($rootScope, $location, $log, $routeParams, Rest, Alert, HostForm, Gener .factory('HostsDelete', ['$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'Prompt', 'ProcessErrors', 'GetBasePath', - 'HostsReload', 'Wait', 'Find', -function($rootScope, $location, $log, $routeParams, Rest, Alert, Prompt, ProcessErrors, GetBasePath, HostsReload, Wait, Find) { + 'HostsReload', 'Wait', 'Find', 'Empty', +function($rootScope, $location, $log, $routeParams, Rest, Alert, Prompt, ProcessErrors, GetBasePath, HostsReload, Wait, Find, Empty) { return function(params) { // Remove the selected host from the current group by disassociating @@ -642,12 +642,33 @@ function($rootScope, $location, $log, $routeParams, Rest, Alert, Prompt, Process scope = params.scope, host_id = params.host_id, host_name = params.host_name, - - url = (scope.selected_group_id === null) ? GetBasePath('inventory') + scope.inventory_id + '/hosts/' : - GetBasePath('groups') + scope.selected_group_id + '/hosts/', - - group = (scope.selected_tree_id) ? Find({ list: scope.groups, key: 'id', val: scope.selected_tree_id }) : null; - + group, + url_list = []; + + function getChildren(tree_id) { + var parent, found, j; + for (j = 0; j < scope.groups.length; j++) { + if (scope.groups[j].id === tree_id || scope.groups[j].parent === parent) { + found = true; + url_list.push(GetBasePath('groups') + scope.groups[j].group_id + '/hosts/'); + parent = scope.groups[j].id; + } + else { + if (found) { + break; + } + } + } + } + + if (!Empty(scope.selected_group_id)) { + group = Find({ list: scope.groups, key: 'id', val: scope.selected_tree_id }); + getChildren(group.id); + } + else { + url_list.push(GetBasePath('inventory') + scope.inventory_id + '/hosts/'); + } + if (scope.removeHostsReload) { scope.removeHostsReload(); } @@ -656,23 +677,37 @@ function($rootScope, $location, $log, $routeParams, Rest, Alert, Prompt, Process }); action_to_take = function() { + var count=0, i; + $('#prompt-modal').on('hidden.bs.modal', function(){ Wait('start'); }); $('#prompt-modal').modal('hide'); - Rest.setUrl(url); - Rest.post({ id: host_id, disassociate: 1 }) - .success( function() { + + if (scope.removeHostRemoved) { + scope.removeHostRemoved(); + } + scope.removeHostRemoved = scope.$on('hostRemoved', function(){ + count++; + if (count === url_list.length) { scope.$emit('hostsReload'); - }) - .error( function(data, status) { - Wait('stop'); - ProcessErrors(scope, data, status, null, - { hdr: 'Error!', msg: 'Attempt to delete ' + host_name + ' failed. POST returned status: ' + status }); - }); + } + }); + + for(i=0; i < url_list.length; i++) { + Rest.setUrl(url_list[i]); + Rest.post({ id: host_id, disassociate: 1 }) + .success( function() { + scope.$emit('hostRemoved'); + }) + .error( function(data, status) { + ProcessErrors(scope, data, status, null, + { hdr: 'Error!', msg: 'Attempt to delete ' + host_name + ' failed. DELETE returned status: ' + status }); + }); + } }; - body = (group) ? '

Are you sure you want to delete host ' + host_name + ' from group ' + group.name + '?

' : - '

Are you sure you want to delete host ' + host_name + '?

'; - + body = (group) ? '

Are you sure you want to remove host ' + host_name + ' from group ' + group.name + '?' + + ' It will still be part of the inventory and available in All Hosts.

' : + '

Are you sure you want to permanently delete host ' + host_name + ' from the inventory?

'; Prompt({ hdr: 'Delete Host', body: body, action: action_to_take, 'class': 'btn-danger' }); }; diff --git a/awx/ui/static/lib/ansible/InventoryTree.js b/awx/ui/static/lib/ansible/InventoryTree.js index 471cba8d78..60c5a2cb56 100644 --- a/awx/ui/static/lib/ansible/InventoryTree.js +++ b/awx/ui/static/lib/ansible/InventoryTree.js @@ -125,6 +125,7 @@ angular.module('InventoryTree', ['Utilities', 'RestServices', 'GroupsHelper', 'P hosts_status_tip: hosts_status.tooltip, show_failures: hosts_status.failures, hosts_status_class: hosts_status['class'], + inventory_id: inventory_id, selected_class: '', show: true, isDraggable: true,