mirror of
https://github.com/ansible/awx.git
synced 2026-03-23 03:45:01 -02:30
Latest UI Inventory updates
This commit is contained in:
@@ -24,9 +24,10 @@ angular.module('LookUpHelper', [ 'RestServices', 'Utilities', 'SearchHelper', 'P
|
||||
var current_item = params.current_item; //id of the item that should be selected on open
|
||||
var list = params.list; // list object
|
||||
var field = params.field; // form field
|
||||
|
||||
|
||||
// Show pop-up to select user
|
||||
var name = list.iterator.charAt(0).toUpperCase() + list.iterator.substring(1);
|
||||
|
||||
scope['lookUp' + name] = function() {
|
||||
var listGenerator = GenerateList;
|
||||
var listScope = listGenerator.inject(list, { mode: 'lookup', hdr: 'Select ' + name });
|
||||
@@ -37,11 +38,15 @@ angular.module('LookUpHelper', [ 'RestServices', 'Utilities', 'SearchHelper', 'P
|
||||
var name;
|
||||
for (var i=0; i < listScope[list.name].length; i++) {
|
||||
if (listScope[list.iterator + "_" + listScope[list.name][i].id + "_class"] == "success") {
|
||||
found = true;
|
||||
found = true;
|
||||
scope[field] = listScope[list.name][i].id;
|
||||
scope[form.fields[field].sourceModel + '_' + form.fields[field].sourceField] =
|
||||
listScope[list.name][i][form.fields[field].sourceField];
|
||||
scope[form.name + '_form'].$setDirty();
|
||||
if (form.fields[field] && form.fields[field].sourceModel) {
|
||||
scope[form.fields[field].sourceModel + '_' + form.fields[field].sourceField] =
|
||||
listScope[list.name][i][form.fields[field].sourceField];
|
||||
}
|
||||
if (scope[form.name + '_form']) {
|
||||
scope[form.name + '_form'].$setDirty();
|
||||
}
|
||||
listGenerator.hide();
|
||||
}
|
||||
}
|
||||
@@ -62,11 +67,12 @@ angular.module('LookUpHelper', [ 'RestServices', 'Utilities', 'SearchHelper', 'P
|
||||
listScope[list.iterator + "_" + id + "_class"] = "success";
|
||||
}
|
||||
}
|
||||
|
||||
SearchInit({ scope: listScope, set: list.name, list: list, url: defaultUrl });
|
||||
PaginateInit({ scope: listScope, list: list, url: defaultUrl, mode: 'lookup' });
|
||||
scope.search(list.iterator);
|
||||
listScope['toggle_' + list.iterator](current_item);
|
||||
listScope.search(list.iterator);
|
||||
if (current_item) {
|
||||
listScope['toggle_' + list.iterator](current_item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}]);
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
/*********************************************
|
||||
* Copyright (c) 2013 AnsibleWorks, Inc.
|
||||
*
|
||||
* Helper
|
||||
* Routines shared amongst the hosts controllers
|
||||
*/
|
||||
|
||||
angular.module('HostHelper', [ 'RestServices', 'Utilities', 'OrganizationListDefinition',
|
||||
'SearchHelper', 'PaginateHelper', 'ListGenerator' ])
|
||||
|
||||
.factory('LookUpInventoryInit', ['Alert', 'Rest', 'InventoryList', 'GenerateList', 'SearchInit', 'PaginateInit',
|
||||
function(Alert, Rest, InventoryList, GenerateList, SearchInit, PaginateInit) {
|
||||
return function(params) {
|
||||
|
||||
var scope = params.scope;
|
||||
|
||||
// Show pop-up to select organization
|
||||
scope.lookUpInventory = function() {
|
||||
var list = InventoryList;
|
||||
var listGenerator = GenerateList;
|
||||
var listScope = listGenerator.inject(list, { mode: 'lookup', hdr: 'Select Inventory' });
|
||||
var defaultUrl = '/api/v1/inventories';
|
||||
|
||||
listScope.selectAction = function() {
|
||||
var found = false;
|
||||
for (var i=0; i < listScope[list.name].length; i++) {
|
||||
if (listScope[list.iterator + "_" + listScope[list.name][i].id + "_class"] == "success") {
|
||||
found = true;
|
||||
scope['inventory'] = listScope[list.name][i].id;
|
||||
scope['inventory_name'] = listScope[list.name][i].name;
|
||||
scope['host_form'].$setDirty();
|
||||
listGenerator.hide();
|
||||
}
|
||||
}
|
||||
if (found == false) {
|
||||
Alert('No Selection', 'Click on a row to select an Inventory before clicking the Select button.');
|
||||
}
|
||||
}
|
||||
|
||||
listScope.toggle_inventory = function(id) {
|
||||
// when user clicks a row, remove 'success' class from all rows except clicked-on row
|
||||
if (listScope[list.name]) {
|
||||
for (var i=0; i < listScope[list.name].length; i++) {
|
||||
listScope[list.iterator + "_" + listScope[list.name][i].id + "_class"] = "";
|
||||
}
|
||||
}
|
||||
if (id != null && id != undefined) {
|
||||
listScope[list.iterator + "_" + id + "_class"] = "success";
|
||||
}
|
||||
}
|
||||
|
||||
SearchInit({ scope: listScope, set: list.name, list: list, url: defaultUrl });
|
||||
PaginateInit({ scope: listScope, list: list, url: defaultUrl, mode: 'lookup' });
|
||||
scope.search(list.iterator);
|
||||
listScope.toggle_inventory(scope.inventory);
|
||||
}
|
||||
}
|
||||
}]);
|
||||
@@ -6,123 +6,132 @@
|
||||
*/
|
||||
|
||||
angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationListDefinition',
|
||||
'SearchHelper', 'PaginateHelper', 'ListGenerator' ])
|
||||
.factory('SetListeners', ['Alert', 'Rest', function(Alert, Rest) {
|
||||
'SearchHelper', 'PaginateHelper', 'ListGenerator', 'AuthService'
|
||||
])
|
||||
|
||||
.factory('TreeInit', ['Alert', 'Rest', 'Authorization',
|
||||
function(Alert, Rest, Authorization) {
|
||||
return function(params) {
|
||||
|
||||
var scope = params.scope;
|
||||
var set = params.set;
|
||||
var iterator = params.iterator;
|
||||
|
||||
// Listeners to perform lookups after main inventory list loads
|
||||
|
||||
scope.$on('resultFound', function(e, results, lookup_results) {
|
||||
if ( lookup_results.length == results.length ) {
|
||||
key = 'organization';
|
||||
property = 'organization_name';
|
||||
for (var i=0; i < results.length; i++) {
|
||||
for (var j=0; j < lookup_results.length; j++) {
|
||||
if (results[i][key] == lookup_results[j].id) {
|
||||
results[i][property] = lookup_results[j].value;
|
||||
}
|
||||
}
|
||||
}
|
||||
scope[iterator + 'SearchSpin'] = false;
|
||||
scope[set] = results;
|
||||
}
|
||||
});
|
||||
|
||||
scope.$on('refreshFinished', function(e, results) {
|
||||
// Loop through the result set (sent to us by the search helper) and
|
||||
// lookup the id and name of each organization. After each lookup
|
||||
// completes, call resultFound.
|
||||
|
||||
var lookup_results = [];
|
||||
|
||||
for (var i = 0; i < results.length; i++) {
|
||||
Rest.setUrl('/api/v1/organizations/' + results[i].organization + '/');
|
||||
Rest.get()
|
||||
.success( function( data, status, headers, config) {
|
||||
lookup_results.push({ id: data.id, value: data.name });
|
||||
scope.$emit('resultFound', results, lookup_results);
|
||||
})
|
||||
.error( function( data, status, headers, config) {
|
||||
lookup_results.push({ id: 'error' });
|
||||
scope.$emit('resultFound', results, lookup_results);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}])
|
||||
|
||||
.factory('LookUpOrganizationInit', ['Alert', 'Rest', 'OrganizationList', 'GenerateList', 'SearchInit', 'PaginateInit',
|
||||
function(Alert, Rest, OrganizationList, GenerateList, SearchInit, PaginateInit) {
|
||||
return function(params) {
|
||||
|
||||
var scope = params.scope;
|
||||
var inventory = params.inventory;
|
||||
var groups = inventory.related.groups;
|
||||
var hosts = inventory.related.hosts;
|
||||
var inventory_name = inventory.name;
|
||||
var inventory_url = inventory.url;
|
||||
var inventory_id = inventory.id;
|
||||
|
||||
var treeData = [];
|
||||
|
||||
// Show pop-up to select organization
|
||||
scope.lookUpOrganization = function() {
|
||||
var list = OrganizationList;
|
||||
var listGenerator = GenerateList;
|
||||
var listScope = listGenerator.inject(list, { mode: 'lookup', hdr: 'Select Organization' });
|
||||
var defaultUrl = '/api/v1/organizations';
|
||||
|
||||
listScope.selectAction = function() {
|
||||
var found = false;
|
||||
for (var i=0; i < listScope[list.name].length; i++) {
|
||||
if (listScope[list.iterator + "_" + listScope[list.name][i].id + "_class"] == "success") {
|
||||
found = true;
|
||||
scope['organization'] = listScope[list.name][i].id;
|
||||
scope['organization_name'] = listScope[list.name][i].name;
|
||||
scope['inventory_form'].$setDirty();
|
||||
listGenerator.hide();
|
||||
}
|
||||
}
|
||||
if (found == false) {
|
||||
Alert('No Selection', 'Click on a row to select an Organization before clicking the Select button.');
|
||||
}
|
||||
}
|
||||
|
||||
listScope.toggle_organization = function(id) {
|
||||
// when user clicks a row, remove 'success' class from all rows except clicked-on row
|
||||
if (listScope[list.name]) {
|
||||
for (var i=0; i < listScope[list.name].length; i++) {
|
||||
listScope[list.iterator + "_" + listScope[list.name][i].id + "_class"] = "";
|
||||
}
|
||||
}
|
||||
if (id != null && id != undefined) {
|
||||
listScope[list.iterator + "_" + id + "_class"] = "success";
|
||||
}
|
||||
}
|
||||
|
||||
SearchInit({ scope: listScope, set: list.name, list: list, url: defaultUrl });
|
||||
PaginateInit({ scope: listScope, list: list, url: defaultUrl, mode: 'lookup' });
|
||||
scope.search(list.iterator);
|
||||
listScope.toggle_organization(scope.organization);
|
||||
}
|
||||
if (scope.HostLoadedRemove) {
|
||||
scope.HostLoadedRemove();
|
||||
}
|
||||
}])
|
||||
|
||||
scope.HostLoadedRemove = scope.$on('hostsLoaded', function() {
|
||||
Rest.setUrl(groups + '?order_by=name');
|
||||
Rest.get()
|
||||
.success( function(data, status, headers, config) {
|
||||
for (var i=0; i < data.results.length; i++) {
|
||||
treeData[0].children.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'
|
||||
});
|
||||
}
|
||||
|
||||
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) {
|
||||
console.log(data);
|
||||
},
|
||||
error: function() {
|
||||
if (console) {
|
||||
console.log('Error accessing node data!');
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"contextmenu": {
|
||||
items: scope.treeController
|
||||
}
|
||||
});
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
Alert('Error', 'Failed to laod tree data. Url: ' + groups + ' GET status: ' + status);
|
||||
});
|
||||
});
|
||||
|
||||
.factory('TreeInit', ['Alert', 'Rest', function(Alert, Rest) {
|
||||
return function(groups) {
|
||||
Rest.setUrl(groups);
|
||||
Rest.setUrl(hosts + '?order_by=name');
|
||||
Rest.get()
|
||||
.success( function(data, status, headers, config) {
|
||||
var treeData = [];
|
||||
for (var i=0; i < data.results.length; i++) {
|
||||
treeData.push({
|
||||
data: data.results[i].name,
|
||||
state: 'closed',
|
||||
attr: { id: data.results[i] }
|
||||
});
|
||||
.success ( function(data, status, headers, config) {
|
||||
treeData = [];
|
||||
treeData.push({
|
||||
data: {
|
||||
title: inventory_name,
|
||||
},
|
||||
attr: {
|
||||
type: 'inventory',
|
||||
id: 'inventory-node',
|
||||
url: inventory_url,
|
||||
'inventory_id': inventory_id,
|
||||
name: inventory_name
|
||||
},
|
||||
state: 'open',
|
||||
children:[]
|
||||
});
|
||||
for (var i=0; i < data.results.length; i++ ) {
|
||||
treeData[0].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
|
||||
},
|
||||
});
|
||||
}
|
||||
$('#tree-view').jstree({ "json_data": { data: treeData },
|
||||
plugins: ['themes', 'json_data', 'ui'] });
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
Alert('Error', 'Failed to laod tree data. Url: ' + groups + ' GET status: ' + status);
|
||||
});
|
||||
scope.$emit('hostsLoaded');
|
||||
})
|
||||
.error ( function(data, status, headers, config) {
|
||||
Alert('Error', 'Failed to laod tree data. Url: ' + hosts + ' GET status: ' + status);
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}]);
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ angular.module('RefreshHelper', ['RestServices', 'Utilities'])
|
||||
|
||||
url.replace(/page_size\=\d+/,''); //stop repeatedly appending page_size
|
||||
url += scope[iterator + 'SearchParams'];
|
||||
|
||||
Rest.setUrl(url);
|
||||
Rest.get({ params: { page_size: scope[iterator + 'PageSize'] }})
|
||||
.success( function(data, status, headers, config) {
|
||||
@@ -36,7 +37,7 @@ angular.module('RefreshHelper', ['RestServices', 'Utilities'])
|
||||
scope[set] = data['results'];
|
||||
})
|
||||
.error ( function(data, status, headers, config) {
|
||||
scope[iterator + 'SearchSpin'] = true;
|
||||
scope[iterator + 'SearchSpin'] = false;
|
||||
Alert('Error!', 'Failed to retrieve ' + set + '. GET returned status: ' + status);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ angular.module('SearchHelper', ['RestServices', 'Utilities', 'RefreshHelper'])
|
||||
scope[iterator + 'SearchTypeLabel'] = 'Contains';
|
||||
scope[iterator + 'SearchParams'] = '';
|
||||
scope[iterator + 'SearchValue'] = '';
|
||||
|
||||
|
||||
// Functions to handle search widget changes
|
||||
scope.setSearchField = function(iterator, fld, label) {
|
||||
scope[iterator + 'SearchFieldLabel'] = label;
|
||||
|
||||
Reference in New Issue
Block a user