AC-331 Delete one or many hosts now working.

This commit is contained in:
chouseknecht 2013-08-16 17:01:18 -04:00
parent 09a40fa087
commit 707f98237b
5 changed files with 85 additions and 41 deletions

View File

@ -205,7 +205,7 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
scope['inventory_id'] = id;
scope['inventoryFailureFilter'] = false;
// Retrieve each related set and any lookups
// Retrieve each related sets and any lookups
if (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 });
$('#inventory-tabs a[href="#inventory-hosts"]').on('show.bs.tab', function() {
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 });
});
}
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
scope.$on('refreshHost', function(e, group, title) {

View File

@ -105,22 +105,6 @@ angular.module('InventoryFormDefinition', [])
title: "groupTitle",
iterator: 'host',
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: {
@ -129,6 +113,10 @@ angular.module('InventoryFormDefinition', [])
label: 'Host Name',
ngClick: "editHost(\{\{ host.id \}\}, '\{\{ host.name \}\}')"
},
description: {
label: 'Description',
ngClick: "editHost(\{\{ host.id \}\}, '\{\{ host.name \}\}')"
},
has_active_failures: {
label: 'Failed jobs?',
showValue: false,

View File

@ -98,6 +98,7 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
scope.removeHostsReload();
}
scope.removeHostsReload = scope.$on('hostsReload', function() {
console.log('here!');
HostsReload(params);
});
@ -345,7 +346,7 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
function($rootScope, $location, $log, $routeParams, Rest, Alert, Prompt, ProcessErrors, GetBasePath, HostsReload) {
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 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/' :
GetBasePath('groups') + scope.group_id + '/hosts/';
if (scope.removeHostsReload) {
scope.removeHostsReload();
}
scope.removeHostsReload = scope.$on('hostsReload', function() {
HostsReload(params);
});
var action_to_take = function() {
if (scope.removeHostsReload) {
scope.removeHostsReload();
var errors = false;
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');
HostsReload(params);
});
function emit(i) {
// 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.post({ id: host_id, disassociate: 1 })
.success( function(data, status, headers, config) {
scope.$emit('hostsReload');
})
.error( function(data, status, headers, config) {
scope.$emit('hostsReload');
ProcessErrors(scope, data, status, null,
{ hdr: 'Error!', msg: 'Call to ' + url + ' failed. POST returned status: ' + status });
});
for (var i=0; i < scope.hosts.length && !errors; i++) {
if (scope.hosts[i].selected) {
Rest.post({ id: scope.hosts[i].id, disassociate: 1 })
.success( function(data, status, headers, config) {
// if this is the last selected host, clean up and exit
emit(i);
})
.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') {
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';
}
else {
/*else {
scope['promptHeader'] = 'Remove Host from 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.';
scope['promptActionBtnClass'] = 'btn-success';
}
}*/
scope.promptAction = action_to_take;
@ -414,6 +440,8 @@ angular.module('HostsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'H
var group_id = params.group_id;
var scope = params.scope;
scope['hosts'] = null;
scope['toggleAllFlag'] = false;
scope['hostDeleteHide'] = true;
var url = (group_id !== null && group_id !== undefined) ? GetBasePath('groups') + group_id + '/all_hosts/' :
GetBasePath('inventory') + params.inventory_id + '/hosts/';

View File

@ -33,6 +33,7 @@ angular.module('RefreshRelatedHelper', ['RestServices', 'Utilities'])
scope[iterator + 'PageCount'] = Math.ceil((data.count / scope[iterator + 'PageSize']));
scope[iterator + 'SearchSpin'] = false;
scope[iterator + 'Loading'] = false;
scope.$emit('related' + set);
if (!params.scope.$$phase) {
params.scope.$digest();
}

View File

@ -989,7 +989,7 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies'])
html += "<thead>\n";
html += "<tr>\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) {
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";
// Select checkbox
html += "<td><input type=\"checkbox\" ng-model=\"" + form.related[itm].iterator + ".checked\" name=\"check_{{" +
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>";
html += "<td><input type=\"checkbox\" ng-model=\"" + form.related[itm].iterator + ".selected\" ng-change=\"toggleOneHost()\" ></td>";
var cnt = 1;
var rfield;