More inventory state setup. This should get basic/smart inventory forms working in conjunction

This commit is contained in:
Michael Abashian
2017-04-13 10:49:06 -04:00
committed by Jared Tabor
parent 09f99b04f2
commit e411d5c69b
2 changed files with 211 additions and 144 deletions

View File

@@ -4,7 +4,7 @@
* All Rights Reserved * All Rights Reserved
*************************************************/ *************************************************/
export default ['i18n', function(i18n) { export default ['i18n', 'buildHostListState', function(i18n, buildHostListState) {
return { return {
addTitle: i18n._('NEW SMART INVENTORY'), addTitle: i18n._('NEW SMART INVENTORY'),
@@ -126,35 +126,12 @@ export default ['i18n', function(i18n) {
}, },
hosts: { hosts: {
name: 'hosts', name: 'hosts',
// awToolTip: i18n._('Please save before assigning permissions'), include: "RelatedHostsListDefinition",
// dataPlacement: 'top',
basePath: 'api/v2/inventories/{{$stateParams.inventory_id}}/hosts/',
type: 'collection',
title: i18n._('Hosts'), title: i18n._('Hosts'),
iterator: 'host', iterator: 'host',
index: false, listState: buildHostListState,
open: false, // addState: buildGroupsAddState,
// search: { // editState: buildGroupsEditState
// 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 //this is a placeholder for when we're ready for completed jobs
completed_jobs: { completed_jobs: {

View File

@@ -34,129 +34,219 @@ angular.module('inventory', [
let stateDefinitions = stateDefinitionsProvider.$get(), let stateDefinitions = stateDefinitionsProvider.$get(),
stateExtender = $stateExtenderProvider.$get(); stateExtender = $stateExtenderProvider.$get();
function generateInventoryStates() {
let smartInventoryAdd = { function generateInventoryStates() {
name: 'inventories.addSmartInventory',
url: '/smartinventory', let basicInventoryAdd = stateDefinitions.generateTree({
form: 'SmartInventoryForm', name: 'inventories.add', // top-most node in the generated tree (will replace this state definition)
ncyBreadcrumb: { url: '/basic_inventory/add',
label: "CREATE SMART INVENTORY" modes: ['add'],
}, form: 'InventoryForm',
views: { controllers: {
'form@inventories': { add: 'InventoryAddController'
templateProvider: function(SmartInventoryForm, GenerateForm) { }
return GenerateForm.buildHTML(SmartInventoryForm, { });
mode: 'add',
related: false let basicInventoryEdit = stateDefinitions.generateTree({
}); name: 'inventories.edit',
url: '/basic_inventory/:inventory_id',
modes: ['edit'],
form: 'InventoryForm',
controllers: {
edit: 'InventoryEditController'
}
});
let smartInventoryAdd = stateDefinitions.generateTree({
name: 'inventories.addSmartInventory', // top-most node in the generated tree (will replace this state definition)
url: '/smart_inventory/add',
modes: ['add'],
form: 'SmartInventoryForm',
controllers: {
add: 'SmartInventoryAddController'
}
});
let smartInventoryEdit = stateDefinitions.generateTree({
name: 'inventories.editSmartInventory',
url: '/smart_inventory/:inventory_id',
modes: ['edit'],
form: 'SmartInventoryForm',
controllers: {
edit: 'SmartInventoryEditController'
}
});
return Promise.all([
basicInventoryAdd,
basicInventoryEdit,
smartInventoryAdd,
smartInventoryEdit
]).then((generated) => {
return {
states: _.reduce(generated, (result, definition) => {
return result.concat(definition.states);
}, [
stateExtender.buildDefinition({
name: 'inventories', // top-most node in the generated tree (will replace this state definition)
route: '/inventories',
ncyBreadcrumb: {
label: N_('INVENTORIES')
}, },
controller: 'SmartInventoryAddController' views: {
} '@': {
} templateUrl: templateUrl('inventories/inventories')
}; },
'list@inventories': {
let smartInventoryAddOrgLookup = { templateProvider: function(InventoryList, generateList) {
searchPrefix: 'organization', let html = generateList.build({
name: 'inventories.addSmartInventory.organization', list: InventoryList,
url: '/organization', mode: 'edit'
data: { });
formChildState: true return html;
}, },
params: { controller: 'InventoryListController'
organization_search: { }
value: {
page_size: '5'
}, },
squash: true, searchPrefix: 'inventory',
dynamic: true resolve: {
} Dataset: ['InventoryList', 'QuerySet', '$stateParams', 'GetBasePath',
}, function(list, qs, $stateParams, GetBasePath) {
ncyBreadcrumb: { let path = GetBasePath(list.basePath) || GetBasePath(list.name);
skip: true return qs.search(path, $stateParams[`${list.iterator}_search`]);
}, }
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 inventories = stateDefinitions.generateTree({ }
parent: 'inventories', // top-most node in the generated tree (will replace this state definition)
modes: ['add', 'edit'],
list: 'InventoryList',
form: 'InventoryForm',
controllers: {
list: 'InventoryListController',
add: 'InventoryAddController',
edit: 'InventoryEditController'
},
urls: {
list: '/inventories'
},
ncyBreadcrumb: {
label: N_('INVENTORIES')
},
views: {
'@': {
templateUrl: templateUrl('inventories/inventories')
},
'list@inventories': {
templateProvider: function(InventoryList, generateList) {
let html = generateList.build({
list: InventoryList,
mode: 'edit'
});
return html;
},
controller: 'InventoryListController'
}
}
});
return Promise.all([ // function generateInventoryStates() {
inventories //
]).then((generated) => { // let smartInventoryAdd = {
return { // name: 'inventories.addSmartInventory',
states: _.reduce(generated, (result, definition) => { // url: '/smartinventory',
return result.concat(definition.states); // form: 'SmartInventoryForm',
}, [ // ncyBreadcrumb: {
stateExtender.buildDefinition(smartInventoryAdd), // label: "CREATE SMART INVENTORY"
stateExtender.buildDefinition(smartInventoryAddOrgLookup) // },
]) // views: {
}; // 'form@inventories': {
}); // templateProvider: function(SmartInventoryForm, GenerateForm) {
// return GenerateForm.buildHTML(SmartInventoryForm, {
} // mode: 'add',
// related: false
// });
// },
// controller: 'SmartInventoryAddController'
// }
// }
// };
//
// let smartInventoryAddOrgLookup = {
// searchPrefix: 'organization',
// name: 'inventories.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 inventories = stateDefinitions.generateTree({
// parent: 'inventories', // top-most node in the generated tree (will replace this state definition)
// modes: ['add', 'edit'],
// list: 'InventoryList',
// form: 'InventoryForm',
// controllers: {
// list: 'InventoryListController',
// add: 'InventoryAddController',
// edit: 'InventoryEditController'
// },
// urls: {
// list: '/inventories'
// },
// ncyBreadcrumb: {
// label: N_('INVENTORIES')
// },
// views: {
// '@': {
// templateUrl: templateUrl('inventories/inventories')
// },
// 'list@inventories': {
// templateProvider: function(InventoryList, generateList) {
// let html = generateList.build({
// list: InventoryList,
// mode: 'edit'
// });
// return html;
// },
// controller: 'InventoryListController'
// }
// }
// });
//
// return Promise.all([
// inventories
// ]).then((generated) => {
// return {
// states: _.reduce(generated, (result, definition) => {
// return result.concat(definition.states);
// }, [
// stateExtender.buildDefinition(smartInventoryAdd),
// stateExtender.buildDefinition(smartInventoryAddOrgLookup)
// ])
// };
// });
//
// }
$stateProvider.state({ $stateProvider.state({
name: 'hosts', name: 'hosts',