mirror of
https://github.com/ansible/awx.git
synced 2026-04-05 01:59:25 -02:30
Latest UI Inventory updates
This commit is contained in:
@@ -12,23 +12,23 @@
|
||||
|
||||
function HostsList ($scope, $rootScope, $location, $log, $routeParams, Rest,
|
||||
Alert, HostList, GenerateList, LoadBreadCrumbs, Prompt, SearchInit, PaginateInit,
|
||||
ReturnToCaller, ClearScope, ProcessErrors)
|
||||
ReturnToCaller, ClearScope, ProcessErrors, GetBasePath)
|
||||
{
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
|
||||
var list = HostList;
|
||||
var defaultUrl = '/api/v1/inventories/' + $routeParams.id + '/hosts/';
|
||||
|
||||
var list = HostList
|
||||
var base = $location.path().replace(/^\//,'').split('/')[0];
|
||||
var defaultUrl = GetBasePath('hosts');
|
||||
var view = GenerateList;
|
||||
var paths = $location.path().replace(/^\//,'').split('/');
|
||||
var scope = view.inject(HostList, { mode: 'edit' }); // Inject our view
|
||||
var mode = (base == 'hosts') ? 'edit' : 'select';
|
||||
var scope = view.inject(list, { mode: mode }); // Inject our view
|
||||
scope.selected = [];
|
||||
|
||||
SearchInit({ scope: scope, set: 'hosts', list: list, url: defaultUrl });
|
||||
PaginateInit({ scope: scope, list: list, url: defaultUrl });
|
||||
scope.search(list.iterator);
|
||||
|
||||
|
||||
LoadBreadCrumbs();
|
||||
|
||||
scope.addHost = function() {
|
||||
@@ -62,21 +62,89 @@ function HostsList ($scope, $rootScope, $location, $log, $routeParams, Rest,
|
||||
});
|
||||
}
|
||||
|
||||
scope.finishSelection = function() {
|
||||
var url = ($routeParams.group_id) ? GetBasePath('groups') + $routeParams.group_id + '/hosts/' :
|
||||
GetBasePath('inventory') + $routeParams.inventory_id + '/hosts/';
|
||||
|
||||
Rest.setUrl(url); // We're assuming the path matches the api path.
|
||||
// Will this always be true??
|
||||
scope.queue = [];
|
||||
|
||||
scope.$on('callFinished', function() {
|
||||
// We call the API for each selected item. We need to hang out until all the api
|
||||
// calls are finished.
|
||||
if (scope.queue.length == scope.selected.length) {
|
||||
// All the api calls finished
|
||||
$('input[type="checkbox"]').prop("checked",false);
|
||||
scope.selected = [];
|
||||
var errors = 0;
|
||||
for (var i=0; i < scope.queue.length; i++) {
|
||||
if (scope.queue[i].result == 'error') {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
if (errors > 0) {
|
||||
Alert('Error', 'There was an error while adding one or more of the selected hosts.');
|
||||
}
|
||||
else {
|
||||
ReturnToCaller(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (scope.selected.length > 0 ) {
|
||||
var host;
|
||||
for (var i=0; i < scope.selected.length; i++) {
|
||||
host = null;
|
||||
for (var j=0; j < scope.hosts.length; j++) {
|
||||
if (scope.hosts[j].id == scope.selected[i]) {
|
||||
host = scope.hosts[j];
|
||||
}
|
||||
}
|
||||
if (host !== null) {
|
||||
Rest.post(host)
|
||||
.success( function(data, status, headers, config) {
|
||||
scope.queue.push({ result: 'success', data: data, status: status });
|
||||
scope.$emit('callFinished');
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
scope.queue.push({ result: 'error', data: data, status: status, headers: headers });
|
||||
scope.$emit('callFinished');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
ReturnToCaller(1);
|
||||
}
|
||||
}
|
||||
|
||||
scope.toggle_host = function(idx) {
|
||||
if (scope.selected.indexOf(idx) > -1) {
|
||||
scope.selected.splice(scope.selected.indexOf(idx),1);
|
||||
}
|
||||
else {
|
||||
scope.selected.push(idx);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
HostsList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'HostList', 'GenerateList',
|
||||
'LoadBreadCrumbs', 'Prompt', 'SearchInit', 'PaginateInit', 'ReturnToCaller', 'ClearScope', 'ProcessErrors' ];
|
||||
'LoadBreadCrumbs', 'Prompt', 'SearchInit', 'PaginateInit', 'ReturnToCaller', 'ClearScope', 'ProcessErrors',
|
||||
'GetBasePath' ];
|
||||
|
||||
|
||||
function HostsAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, HostForm,
|
||||
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller,
|
||||
ClearScope, LookUpInventoryInit)
|
||||
ClearScope, GetBasePath )
|
||||
{
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
|
||||
// Inject dynamic view
|
||||
var defaultUrl = '/api/v1/inventories/';
|
||||
var defaultUrl = ($routeParams.group_id) ? GetBasePath('groups') + $routeParams.group_id + '/hosts/' :
|
||||
GetBasePath('inventory') + $routeParams.inventory_id + '/hosts/';
|
||||
var form = HostForm;
|
||||
var generator = GenerateForm;
|
||||
var scope = generator.inject(form, {mode: 'add', related: false});
|
||||
@@ -85,30 +153,18 @@ function HostsAdd ($scope, $rootScope, $compile, $location, $log, $routeParams,
|
||||
|
||||
LoadBreadCrumbs();
|
||||
|
||||
LookUpInventoryInit({ scope: scope });
|
||||
|
||||
// Load inventory lookup value
|
||||
var url = defaultUrl + $routeParams.id + '/';
|
||||
Rest.setUrl(url);
|
||||
Rest.get()
|
||||
.success( function(data, status, headers, config) {
|
||||
scope['inventory'] = data.id;
|
||||
master['inventory'] = data.id;
|
||||
scope['inventory_name'] = data.name;
|
||||
master['inventory_name'] = data.name;
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, null,
|
||||
{ hdr: 'Error!', msg: 'Failed to retrieve: ' + url + '. GET status: ' + status });
|
||||
});
|
||||
|
||||
// Save
|
||||
scope.formSave = function() {
|
||||
Rest.setUrl(defaultUrl + $routeParams.id + '/hosts/');
|
||||
Rest.setUrl(defaultUrl);
|
||||
var data = {}
|
||||
for (var fld in form.fields) {
|
||||
data[fld] = scope[fld];
|
||||
}
|
||||
}
|
||||
|
||||
if ($routeParams.group_id) {
|
||||
data['inventory'] = $routeParams.inventory_id;
|
||||
}
|
||||
|
||||
Rest.post(data)
|
||||
.success( function(data, status, headers, config) {
|
||||
ReturnToCaller(1);
|
||||
@@ -128,39 +184,28 @@ function HostsAdd ($scope, $rootScope, $compile, $location, $log, $routeParams,
|
||||
}
|
||||
|
||||
HostsAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'HostForm', 'GenerateForm',
|
||||
'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope', 'LookUpInventoryInit' ];
|
||||
'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope', 'GetBasePath' ];
|
||||
|
||||
|
||||
function HostsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams, UserForm,
|
||||
function HostsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams, HostForm,
|
||||
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit,
|
||||
RelatedPaginateInit, ReturnToCaller, ClearScope, LookUpInventoryInit)
|
||||
RelatedPaginateInit, ReturnToCaller, ClearScope, GetBasePath)
|
||||
{
|
||||
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||
//scope.
|
||||
|
||||
var defaultUrl='/api/v1/hosts/';
|
||||
var defaultUrl = GetBasePath('hosts');
|
||||
var generator = GenerateForm;
|
||||
var form = UserForm;
|
||||
var base = $location.path().replace(/^\//,'').split('/')[0];
|
||||
var form = HostForm;
|
||||
var scope = generator.inject(form, {mode: 'edit', related: true});
|
||||
generator.reset();
|
||||
var master = {};
|
||||
var id = $routeParams.id;
|
||||
var relatedSets = {};
|
||||
|
||||
LookUpInventoryInit({ scope: scope });
|
||||
|
||||
// After form data loads, load related sets and lookups
|
||||
scope.$on('hostLoaded', function() {
|
||||
Rest.setUrl(scope['inventory_url']);
|
||||
Rest.get()
|
||||
.success( function(data, status, headers, config) {
|
||||
scope['inventory_name'] = data.name;
|
||||
master['inventory_name'] = data.name;
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, null,
|
||||
{ hdr: 'Error!', msg: 'Failed to retrieve: ' + scope.inventory_url + '. GET status: ' + status });
|
||||
});
|
||||
for (var set in relatedSets) {
|
||||
scope.search(relatedSets[set].iterator);
|
||||
}
|
||||
@@ -186,7 +231,6 @@ function HostsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams,
|
||||
// Initialize related search functions. Doing it here to make sure relatedSets object is populated.
|
||||
RelatedSearchInit({ scope: scope, form: form, relatedSets: relatedSets });
|
||||
RelatedPaginateInit({ scope: scope, relatedSets: relatedSets });
|
||||
scope['inventory_url'] = data.related.inventory;
|
||||
scope.$emit('hostLoaded');
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
@@ -203,8 +247,7 @@ function HostsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams,
|
||||
}
|
||||
Rest.put(data)
|
||||
.success( function(data, status, headers, config) {
|
||||
var base = $location.path().replace(/^\//,'').split('/')[0];
|
||||
(base == 'inventories') ? ReturnToCaller() : ReturnToCaller(1);
|
||||
(base == 'hosts') ? ReturnToCaller() : ReturnToCaller(1);
|
||||
})
|
||||
.error( function(data, status, headers, config) {
|
||||
ProcessErrors(scope, data, status, form,
|
||||
@@ -224,5 +267,5 @@ function HostsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams,
|
||||
|
||||
HostsEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'HostForm',
|
||||
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit',
|
||||
'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope', 'LookUpInventoryInit' ];
|
||||
'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope', 'GetBasePath' ];
|
||||
|
||||
Reference in New Issue
Block a user