mirror of
https://github.com/ansible/awx.git
synced 2026-03-06 11:11:07 -03:30
Latest inventory tree updates. Now using root_groups to retrieve top-level inventory groups. Ajax group load now works -hosts and subgroups loading. Need to add sorting, but all works.
This commit is contained in:
@@ -2,31 +2,123 @@
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
* InventoryHelper
|
||||
* Routines shared amongst the inventory controllers
|
||||
* Routines for building the tree. Everything related to the tree is here except
|
||||
* for the menu piece. The routine for building the menu is in InventoriesEdit controller
|
||||
* (controllers/Inventories.js)
|
||||
*
|
||||
*/
|
||||
|
||||
angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationListDefinition',
|
||||
'SearchHelper', 'PaginateHelper', 'ListGenerator', 'AuthService'
|
||||
])
|
||||
|
||||
.factory('TreeInit', ['Alert', 'Rest', 'Authorization',
|
||||
function(Alert, Rest, Authorization) {
|
||||
.factory('TreeInit', ['Alert', 'Rest', 'Authorization', '$http',
|
||||
function(Alert, Rest, Authorization, $http) {
|
||||
return function(params) {
|
||||
|
||||
var scope = params.scope;
|
||||
var inventory = params.inventory;
|
||||
var groups = inventory.related.groups;
|
||||
var groups = inventory.related.root_groups;
|
||||
var hosts = inventory.related.hosts;
|
||||
var inventory_name = inventory.name;
|
||||
var inventory_url = inventory.url;
|
||||
var inventory_id = inventory.id;
|
||||
var tree_id = '#tree-view';
|
||||
|
||||
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
|
||||
if (scope.buildTreeRemove) {
|
||||
scope.buildTreeRemove();
|
||||
}
|
||||
scope.buildTreeRemove = scope.$on('buildTree', function() {
|
||||
$(tree_id).jstree({
|
||||
"core": { "initially_open":['inventory-node'] },
|
||||
"plugins": ['themes', 'json_data', 'ui', 'contextmenu'],
|
||||
"json_data": {
|
||||
data: treeData,
|
||||
ajax: {
|
||||
url: function(node){
|
||||
scope.selected_node = node;
|
||||
return $(node).attr('children');
|
||||
},
|
||||
headers: { 'Authorization': 'Token ' + Authorization.getToken() },
|
||||
success: function(data) {
|
||||
var response = [];
|
||||
for (var i=0; i < data.results.length; i++) {
|
||||
response.push({
|
||||
data: {
|
||||
title: data.results[i].name
|
||||
},
|
||||
attr: {
|
||||
id: data.results[i].id,
|
||||
type: 'group',
|
||||
name: data.results[i].name,
|
||||
description: data.results[i].description,
|
||||
inventory: data.results[i].inventory,
|
||||
all: data.results[i].related.all_hosts,
|
||||
children: data.results[i].related.children,
|
||||
hosts: data.results[i].related.hosts,
|
||||
variable: data.results[i].related.variable_data
|
||||
},
|
||||
state: 'closed'
|
||||
});
|
||||
}
|
||||
scope.$emit('loadHosts');
|
||||
return response;
|
||||
}
|
||||
}
|
||||
},
|
||||
"contextmenu": {
|
||||
items: scope.treeController
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// Ater inventory top-level hosts, load top-level groups
|
||||
if (scope.HostLoadedRemove) {
|
||||
scope.HostLoadedRemove();
|
||||
}
|
||||
|
||||
scope.HostLoadedRemove = scope.$on('hostsLoaded', function() {
|
||||
Rest.setUrl(groups + '?order_by=name');
|
||||
Rest.get()
|
||||
@@ -50,45 +142,14 @@ angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationLi
|
||||
state: 'closed'
|
||||
});
|
||||
}
|
||||
|
||||
var tree_id = '#tree-view';
|
||||
//.bind("open_node.jstree close_node.jstree", function (e,data) {
|
||||
// var currentNode = data.args[0];
|
||||
// if (e.type === "open_node") {
|
||||
//var tree = $.jstree._reference(tree_id);
|
||||
//tree.refresh(currentNode);
|
||||
// }
|
||||
// })
|
||||
$(tree_id).jstree({
|
||||
"core": { "initially_open":['inventory-node'] },
|
||||
"plugins": ['themes', 'json_data', 'ui', 'contextmenu'],
|
||||
"json_data": {
|
||||
data: treeData,
|
||||
ajax: {
|
||||
url: function(node){
|
||||
return $(node).attr('all');
|
||||
},
|
||||
headers: { 'Authorization': 'Token ' + Authorization.getToken() },
|
||||
success: function(data) {
|
||||
|
||||
},
|
||||
error: function() {
|
||||
if (console) {
|
||||
console.log('Error accessing node data!');
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"contextmenu": {
|
||||
items: scope.treeController
|
||||
}
|
||||
});
|
||||
scope.$emit('buildTree');
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
Alert('Error', 'Failed to laod tree data. Url: ' + groups + ' GET status: ' + status);
|
||||
});
|
||||
});
|
||||
|
||||
// Load inventory top-level hosts
|
||||
Rest.setUrl(hosts + '?order_by=name');
|
||||
Rest.get()
|
||||
.success ( function(data, status, headers, config) {
|
||||
|
||||
Reference in New Issue
Block a user