mirror of
https://github.com/ansible/awx.git
synced 2026-03-09 13:39:27 -02:30
AC-536 fixing inventory group copy, move, delete functions.
This commit is contained in:
@@ -97,6 +97,8 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
|
|||||||
|
|
||||||
SelectionInit({ scope: scope, list: list, url: url });
|
SelectionInit({ scope: scope, list: list, url: url });
|
||||||
|
|
||||||
|
//var finish = scope.finishSelection;
|
||||||
|
|
||||||
scope.formModalAction = function() {
|
scope.formModalAction = function() {
|
||||||
var groups = [];
|
var groups = [];
|
||||||
for (var j=0; j < scope.selected.length; j++) {
|
for (var j=0; j < scope.selected.length; j++) {
|
||||||
@@ -108,8 +110,8 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
|
|||||||
if (groups.length > 0) {
|
if (groups.length > 0) {
|
||||||
var action = function() {
|
var action = function() {
|
||||||
$('#prompt-modal').modal('hide');
|
$('#prompt-modal').modal('hide');
|
||||||
finish();
|
scope.finishSelection();
|
||||||
}
|
}
|
||||||
if (groups.length == 1) {
|
if (groups.length == 1) {
|
||||||
Prompt({ hdr: 'Warning', body: 'Be aware that ' + groups[0] +
|
Prompt({ hdr: 'Warning', body: 'Be aware that ' + groups[0] +
|
||||||
' is a top level group. Adding it to ' + scope.selectedNodeName + ' will remove it from the top level. Do you ' +
|
' is a top level group. Adding it to ' + scope.selectedNodeName + ' will remove it from the top level. Do you ' +
|
||||||
@@ -132,9 +134,10 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
|
|||||||
action: action });
|
action: action });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
scope.finishSelection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var finish = scope.formModalAction;
|
|
||||||
|
|
||||||
if (scope.PostRefreshRemove) {
|
if (scope.PostRefreshRemove) {
|
||||||
scope.PostRefreshRemove();
|
scope.PostRefreshRemove();
|
||||||
@@ -902,7 +905,8 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
|
|||||||
};
|
};
|
||||||
//Force binds to work. Not working usual way.
|
//Force binds to work. Not working usual way.
|
||||||
$('#prompt-header').text('Delete Group');
|
$('#prompt-header').text('Delete Group');
|
||||||
$('#prompt-body').html('<p>Are you sure you want to permanently delete group <em>' + $(obj).attr('name') + '</em>?</p>');
|
$('#prompt-body').html('<p>Are you sure you want to remove group <em>' + $(obj).attr('name') + '</em> from group <em>' +
|
||||||
|
parent.attr('name') + '</em>?</p>');
|
||||||
$('#prompt-action-btn').addClass('btn-danger');
|
$('#prompt-action-btn').addClass('btn-danger');
|
||||||
scope.promptAction = action_to_take; // for some reason this binds?
|
scope.promptAction = action_to_take; // for some reason this binds?
|
||||||
$('#prompt-modal').modal({
|
$('#prompt-modal').modal({
|
||||||
|
|||||||
@@ -184,60 +184,6 @@ angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationLi
|
|||||||
Wait('stop');
|
Wait('stop');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scope.removeCopyVariables) {
|
|
||||||
scope.removeCopyVariables();
|
|
||||||
}
|
|
||||||
scope.removeCopyVariables = scope.$on('copyVariables', function(e, id, url) {
|
|
||||||
if (variables) {
|
|
||||||
Rest.setUrl(url);
|
|
||||||
Rest.put(variables)
|
|
||||||
.success(function(data, status, headers, config) {
|
|
||||||
cleanUp();
|
|
||||||
})
|
|
||||||
.error(function(data, status, headers, config) {
|
|
||||||
cleanUp();
|
|
||||||
ProcessErrors(scope, data, status, null,
|
|
||||||
{ hdr: 'Error!', msg: 'Failed to update variables. PUT returned status: ' + status });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
cleanUp();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (scope['addToTargetRemove']) {
|
|
||||||
scope.addToTargetRemove();
|
|
||||||
}
|
|
||||||
scope.addToTargetRemove = scope.$on('addToTarget', function() {
|
|
||||||
// add the new group to the target parent
|
|
||||||
var url = (target.attr('type') == 'group') ? GetBasePath('base') + 'groups/' + target.attr('group_id') + '/children/' :
|
|
||||||
GetBasePath('inventory') + inv_id + '/groups/';
|
|
||||||
var group = {
|
|
||||||
name: node.attr('name'),
|
|
||||||
description: node.attr('description'),
|
|
||||||
inventory: node.attr('inventory')
|
|
||||||
}
|
|
||||||
Rest.setUrl(url);
|
|
||||||
Rest.post(group)
|
|
||||||
.success( function(data, status, headers, config) {
|
|
||||||
//Update the node with new attributes
|
|
||||||
var filter = (scope.inventoryFailureFilter) ? "has_active_failures=true&" : "";
|
|
||||||
node.attr('group_id', data.id);
|
|
||||||
node.attr('variable', data.related.variable_data);
|
|
||||||
node.attr('all', data.related.all_hosts);
|
|
||||||
node.attr('children', data.related.children + '?' + filter + 'order_by=name');
|
|
||||||
node.attr('hosts', data.related.hosts);
|
|
||||||
node.attr('data-failures', data.has_active_failures);
|
|
||||||
scope.$emit('copyVariables', data.id, data.related.variable_data);
|
|
||||||
})
|
|
||||||
.error( function(data, status, headers, config) {
|
|
||||||
cleanUp();
|
|
||||||
ProcessErrors(scope, data, status, null,
|
|
||||||
{ hdr: 'Error!', msg: 'Failed to add ' + node.attr('name') + ' to ' +
|
|
||||||
target.attr('name') + '. POST returned status: ' + status });
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// disassociate the group from the original parent
|
// disassociate the group from the original parent
|
||||||
if (scope.removeGroupRemove) {
|
if (scope.removeGroupRemove) {
|
||||||
scope.removeGroupRemove();
|
scope.removeGroupRemove();
|
||||||
@@ -248,7 +194,7 @@ angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationLi
|
|||||||
Rest.setUrl(url);
|
Rest.setUrl(url);
|
||||||
Rest.post({ id: node.attr('group_id'), disassociate: 1 })
|
Rest.post({ id: node.attr('group_id'), disassociate: 1 })
|
||||||
.success( function(data, status, headers, config) {
|
.success( function(data, status, headers, config) {
|
||||||
scope.$emit('addToTarget');
|
cleanUp();
|
||||||
})
|
})
|
||||||
.error( function(data, status, headers, config) {
|
.error( function(data, status, headers, config) {
|
||||||
cleanUp();
|
cleanUp();
|
||||||
@@ -257,13 +203,40 @@ angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationLi
|
|||||||
parent.attr('name') + '. POST returned status: ' + status });
|
parent.attr('name') + '. POST returned status: ' + status });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (scope['addToTargetRemove']) {
|
||||||
|
scope.addToTargetRemove();
|
||||||
|
}
|
||||||
|
scope.addToTargetRemove = scope.$on('addToTarget', function() {
|
||||||
|
// add the new group to the target parent
|
||||||
|
var url = (target.attr('type') == 'group') ? GetBasePath('base') + 'groups/' + target.attr('group_id') + '/children/' :
|
||||||
|
GetBasePath('inventory') + inv_id + '/groups/';
|
||||||
|
var group = {
|
||||||
|
id: node.attr('group_id'),
|
||||||
|
name: node.attr('name'),
|
||||||
|
description: node.attr('description'),
|
||||||
|
inventory: node.attr('inventory')
|
||||||
|
}
|
||||||
|
Rest.setUrl(url);
|
||||||
|
Rest.post(group)
|
||||||
|
.success( function(data, status, headers, config) {
|
||||||
|
scope.$emit('removeGroup');
|
||||||
|
})
|
||||||
|
.error( function(data, status, headers, config) {
|
||||||
|
cleanUp();
|
||||||
|
ProcessErrors(scope, data, status, null,
|
||||||
|
{ hdr: 'Error!', msg: 'Failed to add ' + node.attr('name') + ' to ' +
|
||||||
|
target.attr('name') + '. POST returned status: ' + status });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// Lookup the inventory. We already have what we need except for variables.
|
// Lookup the inventory. We already have what we need except for variables.
|
||||||
Rest.setUrl(GetBasePath('base') + 'groups/' + node.attr('group_id') + '/');
|
Rest.setUrl(GetBasePath('base') + 'groups/' + node.attr('group_id') + '/');
|
||||||
Rest.get()
|
Rest.get()
|
||||||
.success( function(data, status, headers, config) {
|
.success( function(data, status, headers, config) {
|
||||||
variables = (data.variables) ? JSON.parse(data.variables) : "";
|
variables = (data.variables) ? JSON.parse(data.variables) : "";
|
||||||
scope.$emit('removeGroup');
|
scope.$emit('addToTarget');
|
||||||
})
|
})
|
||||||
.error( function(data, status, headers, config) {
|
.error( function(data, status, headers, config) {
|
||||||
cleanUp();
|
cleanUp();
|
||||||
|
|||||||
Reference in New Issue
Block a user