mirror of
https://github.com/ansible/awx.git
synced 2026-03-23 11:55:04 -02:30
AC-331 Delete one or many hosts now working.
This commit is contained in:
@@ -205,7 +205,7 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
|
|||||||
scope['inventory_id'] = id;
|
scope['inventory_id'] = id;
|
||||||
scope['inventoryFailureFilter'] = false;
|
scope['inventoryFailureFilter'] = false;
|
||||||
|
|
||||||
// Retrieve each related set and any lookups
|
// Retrieve each related sets and any lookups
|
||||||
if (scope.inventoryLoadedRemove) {
|
if (scope.inventoryLoadedRemove) {
|
||||||
scope.inventoryLoadedRemove();
|
scope.inventoryLoadedRemove();
|
||||||
}
|
}
|
||||||
@@ -217,6 +217,17 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Add the selected flag to the hosts set.
|
||||||
|
if (scope.relatedHostsRemove) {
|
||||||
|
scope.relatedHostsRemove();
|
||||||
|
}
|
||||||
|
scope.relatedHostsRemove = scope.$on('relatedhosts', function() {
|
||||||
|
scope.toggleAllFlag = false;
|
||||||
|
for (var i=0; i < scope.hosts.length; i++) {
|
||||||
|
scope.hosts[i].selected = 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
LoadInventory({ scope: scope, doPostSteps: true });
|
LoadInventory({ scope: scope, doPostSteps: true });
|
||||||
$('#inventory-tabs a[href="#inventory-hosts"]').on('show.bs.tab', function() {
|
$('#inventory-tabs a[href="#inventory-hosts"]').on('show.bs.tab', function() {
|
||||||
scope['hosts'] = null;
|
scope['hosts'] = null;
|
||||||
@@ -460,6 +471,24 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
|
|||||||
{ hdr: 'Error!', msg: 'Failed to lookup last job: ' + last_job + '. GET status: ' + status });
|
{ hdr: 'Error!', msg: 'Failed to lookup last job: ' + last_job + '. GET status: ' + status });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scope.toggleAllHosts = function() {
|
||||||
|
scope.hostDeleteHide = (scope.toggleAllFlag) ? false : true;
|
||||||
|
for (var i=0; i < scope.hosts.length; i++) {
|
||||||
|
scope.hosts[i].selected = scope.toggleAllFlag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
scope.toggleOneHost = function() {
|
||||||
|
var result = true;
|
||||||
|
for (var i=0; i < scope.hosts.length; i++) {
|
||||||
|
if (scope.hosts[i].selected) {
|
||||||
|
result = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
scope.hostDeleteHide = result;
|
||||||
|
}
|
||||||
|
|
||||||
// Respond to the scope.$emit from awTree directive
|
// Respond to the scope.$emit from awTree directive
|
||||||
scope.$on('refreshHost', function(e, group, title) {
|
scope.$on('refreshHost', function(e, group, title) {
|
||||||
|
|||||||
@@ -105,22 +105,6 @@ angular.module('InventoryFormDefinition', [])
|
|||||||
title: "groupTitle",
|
title: "groupTitle",
|
||||||
iterator: 'host',
|
iterator: 'host',
|
||||||
actions: {
|
actions: {
|
||||||
select: {
|
|
||||||
ngClick: "selectHost()",
|
|
||||||
icon: 'icon-check',
|
|
||||||
label: 'Add Existing',
|
|
||||||
awToolTip: 'Select existing host',
|
|
||||||
ngHide: 'createButtonShow == false',
|
|
||||||
"class": 'btn btn-default'
|
|
||||||
},
|
|
||||||
create: {
|
|
||||||
ngClick: "createHost()",
|
|
||||||
icon: 'icon-plus',
|
|
||||||
label: 'Create New',
|
|
||||||
awToolTip: 'Create a new host',
|
|
||||||
ngHide: 'createButtonShow == false',
|
|
||||||
"class": 'btn-success'
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
fields: {
|
fields: {
|
||||||
@@ -129,6 +113,10 @@ angular.module('InventoryFormDefinition', [])
|
|||||||
label: 'Host Name',
|
label: 'Host Name',
|
||||||
ngClick: "editHost(\{\{ host.id \}\}, '\{\{ host.name \}\}')"
|
ngClick: "editHost(\{\{ host.id \}\}, '\{\{ host.name \}\}')"
|
||||||
},
|
},
|
||||||
|
description: {
|
||||||
|
label: 'Description',
|
||||||
|
ngClick: "editHost(\{\{ host.id \}\}, '\{\{ host.name \}\}')"
|
||||||
|
},
|
||||||
has_active_failures: {
|
has_active_failures: {
|
||||||
label: 'Failed jobs?',
|
label: 'Failed jobs?',
|
||||||
showValue: false,
|
showValue: false,
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
|
|||||||
scope.removeHostsReload();
|
scope.removeHostsReload();
|
||||||
}
|
}
|
||||||
scope.removeHostsReload = scope.$on('hostsReload', function() {
|
scope.removeHostsReload = scope.$on('hostsReload', function() {
|
||||||
|
console.log('here!');
|
||||||
HostsReload(params);
|
HostsReload(params);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -345,7 +346,7 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
|
|||||||
function($rootScope, $location, $log, $routeParams, Rest, Alert, Prompt, ProcessErrors, GetBasePath, HostsReload) {
|
function($rootScope, $location, $log, $routeParams, Rest, Alert, Prompt, ProcessErrors, GetBasePath, HostsReload) {
|
||||||
return function(params) {
|
return function(params) {
|
||||||
|
|
||||||
// Remove the selected host from the current group by dissaciating
|
// Remove the selected host from the current group by disassociating
|
||||||
|
|
||||||
var scope = params.scope;
|
var scope = params.scope;
|
||||||
var group_id = scope.group_id;
|
var group_id = scope.group_id;
|
||||||
@@ -356,39 +357,64 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
|
|||||||
|
|
||||||
var url = (scope.group_id == null || req == 'delete') ? GetBasePath('inventory') + inventory_id + '/hosts/' :
|
var url = (scope.group_id == null || req == 'delete') ? GetBasePath('inventory') + inventory_id + '/hosts/' :
|
||||||
GetBasePath('groups') + scope.group_id + '/hosts/';
|
GetBasePath('groups') + scope.group_id + '/hosts/';
|
||||||
|
|
||||||
|
if (scope.removeHostsReload) {
|
||||||
|
scope.removeHostsReload();
|
||||||
|
}
|
||||||
|
scope.removeHostsReload = scope.$on('hostsReload', function() {
|
||||||
|
HostsReload(params);
|
||||||
|
});
|
||||||
|
|
||||||
var action_to_take = function() {
|
var action_to_take = function() {
|
||||||
if (scope.removeHostsReload) {
|
var errors = false;
|
||||||
scope.removeHostsReload();
|
var maxI;
|
||||||
|
|
||||||
|
// Find index pointing to the last selected host
|
||||||
|
for (var i=0; i < scope.hosts.length; i++) {
|
||||||
|
if (scope.hosts[i].selected) {
|
||||||
|
maxI = i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
scope.removeHostsReload = scope.$on('hostsReload', function() {
|
|
||||||
$('#prompt-modal').modal('hide');
|
function emit(i) {
|
||||||
HostsReload(params);
|
// After we process the last selected host or after we hit a problem, refresh the host list
|
||||||
});
|
if (i >= maxI || errors) {
|
||||||
|
$('#prompt-modal').modal('hide');
|
||||||
|
scope.$emit('hostsReload');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Rest.setUrl(url);
|
Rest.setUrl(url);
|
||||||
Rest.post({ id: host_id, disassociate: 1 })
|
for (var i=0; i < scope.hosts.length && !errors; i++) {
|
||||||
.success( function(data, status, headers, config) {
|
if (scope.hosts[i].selected) {
|
||||||
scope.$emit('hostsReload');
|
Rest.post({ id: scope.hosts[i].id, disassociate: 1 })
|
||||||
})
|
.success( function(data, status, headers, config) {
|
||||||
.error( function(data, status, headers, config) {
|
// if this is the last selected host, clean up and exit
|
||||||
scope.$emit('hostsReload');
|
emit(i);
|
||||||
ProcessErrors(scope, data, status, null,
|
})
|
||||||
{ hdr: 'Error!', msg: 'Call to ' + url + ' failed. POST returned status: ' + status });
|
.error( function(data, status, headers, config) {
|
||||||
});
|
errors = true;
|
||||||
|
emit(i);
|
||||||
|
ProcessErrors(scope, data, status, null,
|
||||||
|
{ hdr: 'Error!', msg: 'Attempt to delete ' + scope.hosts[i].name + ' failed. POST returned status: ' + status });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Force binds to work. Not working usual way.
|
//Force binds to work (not working usual way), and launch the confirmation prompt
|
||||||
if (scope.group_id == null || req == 'delete') {
|
if (scope.group_id == null || req == 'delete') {
|
||||||
scope['promptHeader'] = 'Delete Host';
|
scope['promptHeader'] = 'Delete Host';
|
||||||
scope['promptBody'] = 'Are you sure you want to permanently delete ' + host_name + ' from the inventory?';
|
scope['promptBody'] = 'Are you sure you want to permanently delete the selected hosts?';
|
||||||
scope['promptActionBtnClass'] = 'btn-danger';
|
scope['promptActionBtnClass'] = 'btn-danger';
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
|
/*else {
|
||||||
scope['promptHeader'] = 'Remove Host from Group';
|
scope['promptHeader'] = 'Remove Host from Group';
|
||||||
scope['promptBody'] = 'Are you sure you want to remove ' + host_name + ' from the group? ' +
|
scope['promptBody'] = 'Are you sure you want to remove ' + host_name + ' from the group? ' +
|
||||||
host_name + ' will continue to be part of the inventory under All Hosts.';
|
host_name + ' will continue to be part of the inventory under All Hosts.';
|
||||||
scope['promptActionBtnClass'] = 'btn-success';
|
scope['promptActionBtnClass'] = 'btn-success';
|
||||||
}
|
}*/
|
||||||
|
|
||||||
scope.promptAction = action_to_take;
|
scope.promptAction = action_to_take;
|
||||||
|
|
||||||
@@ -414,6 +440,8 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
|
|||||||
var group_id = params.group_id;
|
var group_id = params.group_id;
|
||||||
var scope = params.scope;
|
var scope = params.scope;
|
||||||
scope['hosts'] = null;
|
scope['hosts'] = null;
|
||||||
|
scope['toggleAllFlag'] = false;
|
||||||
|
scope['hostDeleteHide'] = true;
|
||||||
|
|
||||||
var url = (group_id !== null && group_id !== undefined) ? GetBasePath('groups') + group_id + '/all_hosts/' :
|
var url = (group_id !== null && group_id !== undefined) ? GetBasePath('groups') + group_id + '/all_hosts/' :
|
||||||
GetBasePath('inventory') + params.inventory_id + '/hosts/';
|
GetBasePath('inventory') + params.inventory_id + '/hosts/';
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ angular.module('RefreshRelatedHelper', ['RestServices', 'Utilities'])
|
|||||||
scope[iterator + 'PageCount'] = Math.ceil((data.count / scope[iterator + 'PageSize']));
|
scope[iterator + 'PageCount'] = Math.ceil((data.count / scope[iterator + 'PageSize']));
|
||||||
scope[iterator + 'SearchSpin'] = false;
|
scope[iterator + 'SearchSpin'] = false;
|
||||||
scope[iterator + 'Loading'] = false;
|
scope[iterator + 'Loading'] = false;
|
||||||
|
scope.$emit('related' + set);
|
||||||
if (!params.scope.$$phase) {
|
if (!params.scope.$$phase) {
|
||||||
params.scope.$digest();
|
params.scope.$digest();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -989,7 +989,7 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies'])
|
|||||||
html += "<thead>\n";
|
html += "<thead>\n";
|
||||||
html += "<tr>\n";
|
html += "<tr>\n";
|
||||||
html += "<th>#</th>\n";
|
html += "<th>#</th>\n";
|
||||||
html += "<th><input type=\"checkbox\" ng-click=\"toggle_all()\" aw-tool-tip=\"Select all hosts\" data-placement=\"top\"></th>\n";
|
html += "<th><input type=\"checkbox\" ng-model=\"toggleAllFlag\" ng-change=\"toggleAllHosts()\" aw-tool-tip=\"Select all hosts\" data-placement=\"top\"></th>\n";
|
||||||
|
|
||||||
for (var fld in form.related[itm].fields) {
|
for (var fld in form.related[itm].fields) {
|
||||||
html += "<th class=\"list-header\" id=\"" + form.related[itm].iterator + '-' + fld + "-header\" " +
|
html += "<th class=\"list-header\" id=\"" + form.related[itm].iterator + '-' + fld + "-header\" " +
|
||||||
@@ -1022,9 +1022,7 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies'])
|
|||||||
form.related[itm].iterator + "PageSize) + 1 }}.</td>\n";
|
form.related[itm].iterator + "PageSize) + 1 }}.</td>\n";
|
||||||
|
|
||||||
// Select checkbox
|
// Select checkbox
|
||||||
html += "<td><input type=\"checkbox\" ng-model=\"" + form.related[itm].iterator + ".checked\" name=\"check_{{" +
|
html += "<td><input type=\"checkbox\" ng-model=\"" + form.related[itm].iterator + ".selected\" ng-change=\"toggleOneHost()\" ></td>";
|
||||||
form.related[itm].iterator + ".id }}\" ng-click=\"toggle_" + form.related[itm].iterator +"({{ " + form.related[itm].iterator + ".id }}, true)\" ng-true-value=\"1\" " +
|
|
||||||
"ng-false-value=\"0\" id=\"check_{{" + form.related[itm].iterator + ".id}}\" /></td>";
|
|
||||||
|
|
||||||
var cnt = 1;
|
var cnt = 1;
|
||||||
var rfield;
|
var rfield;
|
||||||
|
|||||||
Reference in New Issue
Block a user