Set up dynamic inventory org lookup state

This commit is contained in:
Michael Abashian 2017-04-10 11:28:54 -04:00 committed by Jared Tabor
parent 8013f352ce
commit 2dd1901649
4 changed files with 127 additions and 122 deletions

View File

@ -51,7 +51,7 @@ function SmartInventoryAdd($scope, $location,
scope: $scope,
variable: 'variables',
parse_variable: 'parseType',
field_id: 'inventory_variables'
field_id: 'smartinventory_variables'
});
}

View File

@ -9,11 +9,10 @@ export default ['i18n', function(i18n) {
addTitle: i18n._('NEW SMART INVENTORY'),
editTitle: '{{ inventory_name }}',
name: 'inventory',
name: 'smartinventory',
basePath: 'inventory',
// the top-most node of this generated state tree
breadcrumbName: 'SMART INVENTORY',
stateTree: 'hosts',
tabs: true,
fields: {
inventory_name: {
@ -79,116 +78,6 @@ export default ['i18n', function(i18n) {
ngShow: '(inventory_obj.summary_fields.user_capabilities.edit || canAdd)'
}
},
related: {
permissions: {
name: 'permissions',
awToolTip: i18n._('Please save before assigning permissions'),
dataPlacement: 'top',
basePath: 'api/v1/inventories/{{$stateParams.inventory_id}}/access_list/',
type: 'collection',
title: i18n._('Permissions'),
iterator: 'permission',
index: false,
open: false,
search: {
order_by: 'username'
},
actions: {
add: {
label: i18n._('Add'),
ngClick: "$state.go('.add')",
awToolTip: i18n._('Add a permission'),
actionClass: 'btn List-buttonSubmit',
buttonContent: '+ ADD',
ngShow: '(inventory_obj.summary_fields.user_capabilities.edit || canAdd)'
}
},
fields: {
username: {
label: i18n._('User'),
linkBase: 'users',
class: 'col-lg-3 col-md-3 col-sm-3 col-xs-4'
},
role: {
label: i18n._('Role'),
type: 'role',
nosort: true,
class: 'col-lg-4 col-md-4 col-sm-4 col-xs-4',
},
team_roles: {
label: i18n._('Team Roles'),
type: 'team_roles',
nosort: true,
class: 'col-lg-5 col-md-5 col-sm-5 col-xs-4',
}
}
},
hosts: {
name: 'hosts',
// awToolTip: i18n._('Please save before assigning permissions'),
// dataPlacement: 'top',
basePath: 'api/v2/inventories/{{$stateParams.inventory_id}}/hosts/',
type: 'collection',
title: i18n._('Hosts'),
iterator: 'host',
index: false,
open: false,
// search: {
// order_by: 'username'
// },
actions: {
add: {
label: i18n._('Add'),
ngClick: "$state.go('.add')",
awToolTip: i18n._('Add a permission'),
actionClass: 'btn List-buttonSubmit',
buttonContent: '+ ADD',
// ngShow: '(inventory_obj.summary_fields.user_capabilities.edit || canAdd)'
}
},
fields: {
name: {
label: i18n._('Name'),
// linkBase: 'users',
class: 'col-lg-3 col-md-3 col-sm-3 col-xs-4'
}
}
},
//this is a placeholder for when we're ready for completed jobs
completed_jobs: {
name: 'completed_jobs',
// awToolTip: i18n._('Please save before assigning permissions'),
// dataPlacement: 'top',
basePath: 'api/v2/inventories/{{$stateParams.inventory_id}}/completed_jobs/',
type: 'collection',
title: i18n._('Completed Jobs'),
iterator: 'completed_job',
index: false,
open: false,
// search: {
// order_by: 'username'
// },
actions: {
add: {
label: i18n._('Add'),
ngClick: "$state.go('.add')",
awToolTip: i18n._('Add a permission'),
actionClass: 'btn List-buttonSubmit',
buttonContent: '+ ADD',
// ngShow: '(inventory_obj.summary_fields.user_capabilities.edit || canAdd)'
}
},
fields: {
name: {
label: i18n._('Name'),
// linkBase: 'users',
class: 'col-lg-3 col-md-3 col-sm-3 col-xs-4'
}
}
}
}
related: {}
};}];

View File

@ -0,0 +1,60 @@
/*************************************************
* Copyright (c) 2016 Ansible, Inc.
*
* All Rights Reserved
*************************************************/
export default
['$rootScope', 'Rest', 'GetBasePath', 'ProcessErrors', 'Wait',
function($rootScope, Rest, GetBasePath, ProcessErrors, Wait){
return {
// cute abstractions via fn.bind()
url: function(){
return '';
},
error: function(data, status) {
ProcessErrors($rootScope, data, status, null, { hdr: 'Error!',
msg: 'Call to ' + this.url + '. GET returned: ' + status });
},
success: function(data){
return data;
},
// data getters
getInventory: function(id){
Wait('start');
this.url = GetBasePath('inventory') + id;
Rest.setUrl(this.url);
return Rest.get()
.success(this.success.bind(this))
.error(this.error.bind(this))
.finally(Wait('stop'));
},
getBreadcrumbs: function(groups){
Wait('start');
this.url = GetBasePath('groups') + '?' + _.map(groups, function(item){
return '&or__id=' + item;
}).join('');
Rest.setUrl(this.url);
return Rest.get()
.success(this.success.bind(this))
.error(this.error.bind(this))
.finally(Wait('stop'));
},
rootHostsUrl: function(id){
var url = GetBasePath('inventory') + id + '/hosts';
return url;
},
childHostsUrl: function(id){
var url = GetBasePath('groups') + id + '/all_hosts';
return url;
},
childGroupsUrl: function(id){
var url = GetBasePath('groups') + id + '/children';
return url;
},
rootGroupsUrl: function(id){
var url = GetBasePath('inventory') + id+ '/root_groups';
return url;
}
};
}];

View File

@ -12,6 +12,7 @@ import { templateUrl } from '../shared/template-url/template-url.factory';
import { N_ } from '../i18n';
import InventoryList from './inventory.list';
import InventoryForm from './inventory.form';
import InventoryManageService from './inventory-manage.service';
export default
angular.module('inventory', [
host.name,
@ -21,14 +22,15 @@ angular.module('inventory', [
])
.factory('InventoryForm', InventoryForm)
.factory('InventoryList', InventoryList)
.config(['$stateProvider', '$stateExtenderProvider', 'stateDefinitionsProvider',
function($stateProvider, $stateExtenderProvider, stateDefinitionsProvider) {
.service('InventoryManageService', InventoryManageService)
.config(['$stateProvider', 'stateDefinitionsProvider', '$stateExtenderProvider',
function($stateProvider, stateDefinitionsProvider, $stateExtenderProvider) {
// When stateDefinition.lazyLoad() resolves, states matching name.** or /url** will be de-registered and replaced with resolved states
// This means inventoryManage states will not be registered correctly on page refresh, unless they're registered at the same time as the inventories state tree
let stateDefinitions = stateDefinitionsProvider.$get(),
stateExtender = $stateExtenderProvider.$get();
function foobar() {
function generateHostStates() {
let smartInventoryAdd = {
name: 'hosts.addSmartInventory',
@ -50,14 +52,67 @@ angular.module('inventory', [
}
};
let smartInventoryAddOrgLookup = {
searchPrefix: 'organization',
name: 'hosts.addSmartInventory.organization',
url: '/organization',
data: {
formChildState: true
},
params: {
organization_search: {
value: {
page_size: '5'
},
squash: true,
dynamic: true
}
},
ncyBreadcrumb: {
skip: true
},
views: {
'related': {
templateProvider: function(ListDefinition, generateList) {
let list_html = generateList.build({
mode: 'lookup',
list: ListDefinition,
input_type: 'radio'
});
return `<lookup-modal>${list_html}</lookup-modal>`;
}
}
},
resolve: {
ListDefinition: ['OrganizationList', function(OrganizationList) {
let list = _.cloneDeep(OrganizationList);
list.lookupConfirmText = 'SELECT';
return list;
}],
Dataset: ['ListDefinition', 'QuerySet', '$stateParams', 'GetBasePath',
(list, qs, $stateParams, GetBasePath) => {
let path = GetBasePath(list.name) || GetBasePath(list.basePath);
return qs.search(path, $stateParams[`${list.iterator}_search`]);
}
]
},
onExit: function($state) {
if ($state.transition) {
$('#form-modal').modal('hide');
$('.modal-backdrop').remove();
$('body').removeClass('modal-open');
}
},
};
let hosts = stateDefinitions.generateTree({
parent: 'hosts', // top-most node in the generated tree (will replace this state definition)
modes: ['add', 'edit'],
modes: ['edit'],
list: 'HostsList',
form: 'HostsForm',
controllers: {
list: 'HostListController',
add: 'HostAddController',
edit: 'HostEditController'
},
urls: {
@ -101,7 +156,8 @@ angular.module('inventory', [
states: _.reduce(generated, (result, definition) => {
return result.concat(definition.states);
}, [
stateExtender.buildDefinition(smartInventoryAdd)
stateExtender.buildDefinition(smartInventoryAdd),
stateExtender.buildDefinition(smartInventoryAddOrgLookup)
])
};
});
@ -148,7 +204,7 @@ angular.module('inventory', [
$stateProvider.state({
name: 'hosts',
url: '/hosts',
lazyLoad: () => foobar()
lazyLoad: () => generateHostStates()
});
}
]);