mirror of
https://github.com/ansible/awx.git
synced 2026-05-16 13:57:39 -02:30
Latest inventory detail page modifications.
This commit is contained in:
@@ -19,7 +19,7 @@ function GroupsList ($scope, $rootScope, $location, $log, $routeParams, Rest,
|
|||||||
|
|
||||||
var list = GroupList;
|
var list = GroupList;
|
||||||
var base = $location.path().replace(/^\//,'').split('/')[0];
|
var base = $location.path().replace(/^\//,'').split('/')[0];
|
||||||
var defaultUrl = GetBasePath('groups');
|
var defaultUrl = GetBasePath('inventory') + $routeParams.inventory_id + '/groups/';
|
||||||
var view = GenerateList;
|
var view = GenerateList;
|
||||||
|
|
||||||
var scope = view.inject(GroupList, { mode: 'select' }); // Inject our view
|
var scope = view.inject(GroupList, { mode: 'select' }); // Inject our view
|
||||||
@@ -29,6 +29,10 @@ function GroupsList ($scope, $rootScope, $location, $log, $routeParams, Rest,
|
|||||||
scope.PostRefreshRemove();
|
scope.PostRefreshRemove();
|
||||||
}
|
}
|
||||||
scope.PostRefresRemove = scope.$on('PostRefresh', function() {
|
scope.PostRefresRemove = scope.$on('PostRefresh', function() {
|
||||||
|
$("tr.success").each(function(index) {
|
||||||
|
var ngc = $(this).attr('ng-class');
|
||||||
|
scope[ngc] = "";
|
||||||
|
});
|
||||||
if ($routeParams.group_id) {
|
if ($routeParams.group_id) {
|
||||||
// Remove the current group from the list of available groups, thus
|
// Remove the current group from the list of available groups, thus
|
||||||
// preventing a group from being added to itself
|
// preventing a group from being added to itself
|
||||||
@@ -38,6 +42,7 @@ function GroupsList ($scope, $rootScope, $location, $log, $routeParams, Rest,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//scope.$digest();
|
||||||
});
|
});
|
||||||
|
|
||||||
SearchInit({ scope: scope, set: 'groups', list: list, url: defaultUrl });
|
SearchInit({ scope: scope, set: 'groups', list: list, url: defaultUrl });
|
||||||
|
|||||||
@@ -20,12 +20,11 @@ function HostsList ($scope, $rootScope, $location, $log, $routeParams, Rest,
|
|||||||
var list = HostList
|
var list = HostList
|
||||||
var base = $location.path().replace(/^\//,'').split('/')[0];
|
var base = $location.path().replace(/^\//,'').split('/')[0];
|
||||||
var base2 = $location.path().replace(/^\//,'').split('/')[2];
|
var base2 = $location.path().replace(/^\//,'').split('/')[2];
|
||||||
var defaultUrl = GetBasePath('hosts');
|
var defaultUrl = GetBasePath('inventory') + $routeParams.inventory_id + '/hosts/';
|
||||||
var view = GenerateList;
|
var view = GenerateList;
|
||||||
var mode = (base == 'hosts' || base2 == 'hosts') ? 'edit' : 'select';
|
var mode = (base == 'hosts' || base2 == 'hosts') ? 'edit' : 'select';
|
||||||
var scope = view.inject(list, { mode: mode }); // Inject our view
|
var scope = view.inject(list, { mode: mode }); // Inject our view
|
||||||
scope.selected = [];
|
scope.selected = [];
|
||||||
|
|
||||||
scope['inventory_id'] = $routeParams.inventory_id;
|
scope['inventory_id'] = $routeParams.inventory_id;
|
||||||
|
|
||||||
if (base == 'hosts' || base2 == 'hosts') {
|
if (base == 'hosts' || base2 == 'hosts') {
|
||||||
@@ -34,7 +33,17 @@ function HostsList ($scope, $rootScope, $location, $log, $routeParams, Rest,
|
|||||||
else {
|
else {
|
||||||
scope['showAddButton'] = true;
|
scope['showAddButton'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if (scope.PostRefreshRemove) {
|
||||||
|
// scope.PostRefreshRemove();
|
||||||
|
// }
|
||||||
|
// scope.PostRefresRemove = scope.$on('PostRefresh', function() {
|
||||||
|
// $("tr.success").each(function(index) {
|
||||||
|
// var ngc = $(this).attr('ng-class');
|
||||||
|
// scope[ngc] = "";
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
|
||||||
SearchInit({ scope: scope, set: 'hosts', list: list, url: defaultUrl });
|
SearchInit({ scope: scope, set: 'hosts', list: list, url: defaultUrl });
|
||||||
PaginateInit({ scope: scope, list: list, url: defaultUrl });
|
PaginateInit({ scope: scope, list: list, url: defaultUrl });
|
||||||
scope.search(list.iterator);
|
scope.search(list.iterator);
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
|
|||||||
scope.inventoryLoadedRemove();
|
scope.inventoryLoadedRemove();
|
||||||
}
|
}
|
||||||
scope.inventoryLoadedRemove = scope.$on('inventoryLoaded', function() {
|
scope.inventoryLoadedRemove = scope.$on('inventoryLoaded', function() {
|
||||||
scope.groupName = 'All Hosts';
|
scope.groupTitle = 'All Hosts';
|
||||||
scope.createButtonShow = false;
|
scope.createButtonShow = false;
|
||||||
scope.search(relatedSets['hosts'].iterator);
|
scope.search(relatedSets['hosts'].iterator);
|
||||||
});
|
});
|
||||||
@@ -342,44 +342,7 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
|
|||||||
|
|
||||||
scope.treeController = function($node) {
|
scope.treeController = function($node) {
|
||||||
var nodeType = $($node).attr('type');
|
var nodeType = $($node).attr('type');
|
||||||
if (nodeType == 'host') {
|
if (nodeType == 'inventory') {
|
||||||
return {
|
|
||||||
edit: {
|
|
||||||
label: 'Edit Host',
|
|
||||||
action: function(obj) { changePath($location.path() + '/hosts/' + $(obj).attr('id')); }
|
|
||||||
},
|
|
||||||
delete: {
|
|
||||||
label: 'Delete Host',
|
|
||||||
action: function(obj) {
|
|
||||||
var action_to_take = function() {
|
|
||||||
var url = defaultUrl + $routeParams.id + '/hosts/';
|
|
||||||
Rest.setUrl(url);
|
|
||||||
Rest.post({ id: $(obj).attr('id'), disassociate: 1 })
|
|
||||||
.success( function(data, status, headers, config) {
|
|
||||||
$('#prompt-modal').modal('hide');
|
|
||||||
$('#tree-view').jstree("delete_node",obj);
|
|
||||||
})
|
|
||||||
.error( function(data, status, headers, config) {
|
|
||||||
$('#prompt-modal').modal('hide');
|
|
||||||
ProcessErrors(scope, data, status, null,
|
|
||||||
{ hdr: 'Error!', msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status });
|
|
||||||
});
|
|
||||||
};
|
|
||||||
//Force binds to work. Not working usual way.
|
|
||||||
$('#prompt-header').text('Delete');
|
|
||||||
$('#prompt-body').text('Are you sure you want to delete host ' + $(obj).attr('name') + '?');
|
|
||||||
$('#prompt-action-btn').addClass('btn-danger');
|
|
||||||
scope.promptAction = action_to_take; // for some reason this binds?
|
|
||||||
$('#prompt-modal').modal({
|
|
||||||
backdrop: 'static',
|
|
||||||
keyboard: true,
|
|
||||||
show: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (nodeType == 'inventory') {
|
|
||||||
return {
|
return {
|
||||||
addGroup: {
|
addGroup: {
|
||||||
label: 'Add Group',
|
label: 'Add Group',
|
||||||
@@ -392,22 +355,22 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
|
|||||||
addGroup: {
|
addGroup: {
|
||||||
label: 'Add Subgroup',
|
label: 'Add Subgroup',
|
||||||
action: function(obj) {
|
action: function(obj) {
|
||||||
LoadBreadCrumbs({ path: '/groups/' + $(obj).attr('id'), title: $(obj).attr('name') });
|
LoadBreadCrumbs({ path: '/groups/' + $(obj).attr('group_id'), title: $(obj).attr('name') });
|
||||||
changePath($location.path() + '/groups/' + $(obj).attr('id') + '/children');
|
changePath($location.path() + '/groups/' + $(obj).attr('group_id') + '/children');
|
||||||
},
|
},
|
||||||
"_disabled": (nodeType == 'all-hosts-group') ? true : false
|
"_disabled": (nodeType == 'all-hosts-group') ? true : false
|
||||||
},
|
},
|
||||||
// addHost: {
|
addHost: {
|
||||||
// label: 'Add Host',
|
label: 'Add Host',
|
||||||
// action: function(obj) {
|
action: function(obj) {
|
||||||
// LoadBreadCrumbs({ path: '/groups/' + $(obj).attr('id'), title: $(obj).attr('name') });
|
LoadBreadCrumbs({ path: '/groups/' + $(obj).attr('group_id'), title: $(obj).attr('name') });
|
||||||
// changePath($location.path() + '/groups/' + $(obj).attr('id') + '/hosts');
|
changePath($location.path() + '/groups/' + $(obj).attr('group_id') + '/hosts');
|
||||||
// },
|
},
|
||||||
// "_disabled": (nodeType == 'all-hosts-group') ? true : false
|
"_disabled": (nodeType == 'all-hosts-group') ? true : false
|
||||||
// },
|
},
|
||||||
edit: {
|
edit: {
|
||||||
label: 'Edit Group',
|
label: 'Edit Group',
|
||||||
action: function(obj) { changePath($location.path() + '/groups/' + $(obj).attr('id')); },
|
action: function(obj) { changePath($location.path() + '/groups/' + $(obj).attr('group_id')); },
|
||||||
separator_before: true,
|
separator_before: true,
|
||||||
"_disabled": (nodeType == 'all-hosts-group') ? true : false
|
"_disabled": (nodeType == 'all-hosts-group') ? true : false
|
||||||
},
|
},
|
||||||
@@ -455,18 +418,22 @@ function InventoriesEdit ($scope, $rootScope, $compile, $location, $log, $routeP
|
|||||||
if (type == 'group') {
|
if (type == 'group') {
|
||||||
url = node.attr('all');
|
url = node.attr('all');
|
||||||
scope.createButtonShow = true;
|
scope.createButtonShow = true;
|
||||||
scope.group_id = node.attr('id');
|
scope.group_id = node.attr('group_id');
|
||||||
scope.groupName = n.data;
|
scope.groupName = n.data;
|
||||||
|
scope.groupTitle = 'Hosts: ' + n.data;
|
||||||
|
scope.groupTitle += (node.attr('description')) ? ' -' + node.attr('description') : '';
|
||||||
}
|
}
|
||||||
else if (type == 'all-hosts-group') {
|
else if (type == 'all-hosts-group') {
|
||||||
url = node.attr('url');
|
url = node.attr('url');
|
||||||
scope.createButtonShow = false;
|
scope.createButtonShow = false;
|
||||||
scope.groupName = 'All Hosts';
|
scope.groupName = 'All Hosts';
|
||||||
|
scope.groupTitle = 'All Hosts';
|
||||||
}
|
}
|
||||||
else if (type == 'inventory-node') {
|
else if (type == 'inventory-node') {
|
||||||
url = node.attr('hosts');
|
url = node.attr('hosts');
|
||||||
scope.createButtonShow = false;
|
scope.createButtonShow = false;
|
||||||
scope.groupName = 'All Hosts';
|
scope.groupName = 'All Hosts';
|
||||||
|
scope.groupTitle = 'All Hosts';
|
||||||
}
|
}
|
||||||
relatedSets['hosts'] = { url: url, iterator: 'host' };
|
relatedSets['hosts'] = { url: url, iterator: 'host' };
|
||||||
RelatedSearchInit({ scope: scope, form: form, relatedSets: relatedSets });
|
RelatedSearchInit({ scope: scope, form: form, relatedSets: relatedSets });
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ angular.module('InventoryFormDefinition', [])
|
|||||||
|
|
||||||
hosts: {
|
hosts: {
|
||||||
type: 'treeview',
|
type: 'treeview',
|
||||||
title: "{{ groupName }}",
|
title: "{{ groupTitle }}",
|
||||||
iterator: 'host',
|
iterator: 'host',
|
||||||
actions: {
|
actions: {
|
||||||
add: {
|
add: {
|
||||||
|
|||||||
@@ -23,49 +23,11 @@ angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationLi
|
|||||||
var inventory_name = inventory.name;
|
var inventory_name = inventory.name;
|
||||||
var inventory_url = inventory.url;
|
var inventory_url = inventory.url;
|
||||||
var inventory_id = inventory.id;
|
var inventory_id = inventory.id;
|
||||||
|
var inventory_descr = inventory.description;
|
||||||
var tree_id = '#tree-view';
|
var tree_id = '#tree-view';
|
||||||
|
var idx=0;
|
||||||
var treeData = [];
|
var treeData = [];
|
||||||
|
|
||||||
|
|
||||||
// On group expand, fetch and add hosts
|
|
||||||
if (scope.loadHostsRemove) {
|
|
||||||
scope.loadHostsRemove();
|
|
||||||
}
|
|
||||||
scope.loadHostsRemove = scope.$on('loadHosts', function(){
|
|
||||||
var node = scope.selected_node;
|
|
||||||
var url = $(node).attr('hosts');
|
|
||||||
var children = [];
|
|
||||||
// Rest and $http refuse to work. Seems we've hit a nesting limit at this point?
|
|
||||||
$.ajax({
|
|
||||||
url: url,
|
|
||||||
dataType: 'json',
|
|
||||||
headers: { 'Authorization': 'Token ' + Authorization.getToken() }
|
|
||||||
}).done( function(data) {
|
|
||||||
for (var i=0; i < data.results.length; i++) {
|
|
||||||
// Add each host to the group node
|
|
||||||
$(tree_id).jstree("create_node", node, "inside", {
|
|
||||||
data: {
|
|
||||||
title: data.results[i].name,
|
|
||||||
icon: '/'
|
|
||||||
},
|
|
||||||
attr: {
|
|
||||||
id: data.results[i].id,
|
|
||||||
type: 'host',
|
|
||||||
name: data.results[i].name,
|
|
||||||
description: data.results[i].description,
|
|
||||||
url: data.results[i].url,
|
|
||||||
variable_data: data.results[i].varaible_data,
|
|
||||||
inventory: data.results[i].related.inventory,
|
|
||||||
job_events: data.results[i].related.job_events
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// Open the group node
|
|
||||||
$(tree_id).jstree("open_node", node);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// After loading the Inventory top-level data, initialize the tree
|
// After loading the Inventory top-level data, initialize the tree
|
||||||
if (scope.buildTreeRemove) {
|
if (scope.buildTreeRemove) {
|
||||||
scope.buildTreeRemove();
|
scope.buildTreeRemove();
|
||||||
@@ -96,7 +58,8 @@ angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationLi
|
|||||||
title: data.results[i].name
|
title: data.results[i].name
|
||||||
},
|
},
|
||||||
attr: {
|
attr: {
|
||||||
id: data.results[i].id,
|
id: idx,
|
||||||
|
group_id: data.results[i].id,
|
||||||
type: 'group',
|
type: 'group',
|
||||||
name: data.results[i].name,
|
name: data.results[i].name,
|
||||||
description: data.results[i].description,
|
description: data.results[i].description,
|
||||||
@@ -108,6 +71,7 @@ angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationLi
|
|||||||
},
|
},
|
||||||
state: 'closed'
|
state: 'closed'
|
||||||
});
|
});
|
||||||
|
idx++;
|
||||||
}
|
}
|
||||||
//scope.$emit('loadHosts');
|
//scope.$emit('loadHosts');
|
||||||
return response;
|
return response;
|
||||||
@@ -125,7 +89,7 @@ angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationLi
|
|||||||
//selected node text: data.inst.get_json()[0].data
|
//selected node text: data.inst.get_json()[0].data
|
||||||
//console.log( data.inst.get_json()[0].data + ', ' + data.inst.get_json()[0].attr.id );
|
//console.log( data.inst.get_json()[0].data + ', ' + data.inst.get_json()[0].attr.id );
|
||||||
if (data.inst.get_json()[0].attr.id != 'inventory-node') {
|
if (data.inst.get_json()[0].attr.id != 'inventory-node') {
|
||||||
scope.$emit('NodeSelect',data.inst.get_json()[0]);
|
scope.$emit('NodeSelect',data.inst.get_json()[0]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$('#all-hosts-group a').click();
|
$('#all-hosts-group a').click();
|
||||||
@@ -147,7 +111,8 @@ angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationLi
|
|||||||
title: data.results[i].name
|
title: data.results[i].name
|
||||||
},
|
},
|
||||||
attr: {
|
attr: {
|
||||||
id: data.results[i].id,
|
id: idx,
|
||||||
|
group_id: data.results[i].id,
|
||||||
type: 'group',
|
type: 'group',
|
||||||
name: data.results[i].name,
|
name: data.results[i].name,
|
||||||
description: data.results[i].description,
|
description: data.results[i].description,
|
||||||
@@ -159,6 +124,7 @@ angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationLi
|
|||||||
},
|
},
|
||||||
state: 'closed'
|
state: 'closed'
|
||||||
});
|
});
|
||||||
|
idx++;
|
||||||
}
|
}
|
||||||
scope.$emit('buildTree');
|
scope.$emit('buildTree');
|
||||||
})
|
})
|
||||||
@@ -182,12 +148,13 @@ angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationLi
|
|||||||
url: inventory_url,
|
url: inventory_url,
|
||||||
'inventory_id': inventory_id,
|
'inventory_id': inventory_id,
|
||||||
hosts: hosts,
|
hosts: hosts,
|
||||||
name: inventory_name
|
name: inventory_name,
|
||||||
|
description: inventory_descr
|
||||||
},
|
},
|
||||||
state: 'open',
|
state: 'open',
|
||||||
children:[]
|
children:[]
|
||||||
});
|
});
|
||||||
//treeData[0].children.push({
|
|
||||||
var all_hosts_node = {
|
var all_hosts_node = {
|
||||||
data: {
|
data: {
|
||||||
title: 'All Hosts'
|
title: 'All Hosts'
|
||||||
@@ -198,30 +165,9 @@ angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationLi
|
|||||||
url: hosts,
|
url: hosts,
|
||||||
name: 'All Hosts'
|
name: 'All Hosts'
|
||||||
},
|
},
|
||||||
state: 'closed',
|
state: 'closed'
|
||||||
children: []
|
|
||||||
};
|
};
|
||||||
//
|
|
||||||
// No longer loading hosts inside the tree. Instead, we'll show hosts in the list view.
|
|
||||||
//
|
|
||||||
// for (var i=0; i < data.results.length; i++ ) {
|
|
||||||
// all_hosts_node.children.push({
|
|
||||||
// data: {
|
|
||||||
// title: data.results[i].name,
|
|
||||||
// icon: '/'
|
|
||||||
// },
|
|
||||||
// attr: {
|
|
||||||
// id: data.results[i].id,
|
|
||||||
// type: 'host',
|
|
||||||
// name: data.results[i].name,
|
|
||||||
// description: data.results[i].description,
|
|
||||||
// url: data.results[i].url,
|
|
||||||
// variable_data: data.results[i].varaible_data,
|
|
||||||
// inventory: data.results[i].related.inventory,
|
|
||||||
// job_events: data.results[i].related.job_events
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
treeData[0].children.push(all_hosts_node);
|
treeData[0].children.push(all_hosts_node);
|
||||||
scope.$emit('hostsLoaded');
|
scope.$emit('hostsLoaded');
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -609,7 +609,7 @@ angular.module('FormGenerator', ['GeneratorHelpers'])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.form.name == 'inventory') {
|
if (this.form.name == 'inventory' && options.mode == 'edit') {
|
||||||
html += this.buildTree();
|
html += this.buildTree();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
Reference in New Issue
Block a user