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,95 +34,62 @@ angular.module('inventory', [
let stateDefinitions = stateDefinitionsProvider.$get(), let stateDefinitions = stateDefinitionsProvider.$get(),
stateExtender = $stateExtenderProvider.$get(); stateExtender = $stateExtenderProvider.$get();
function generateInventoryStates() { function generateInventoryStates() {
let smartInventoryAdd = { let basicInventoryAdd = stateDefinitions.generateTree({
name: 'inventories.addSmartInventory', name: 'inventories.add', // top-most node in the generated tree (will replace this state definition)
url: '/smartinventory', url: '/basic_inventory/add',
form: 'SmartInventoryForm', modes: ['add'],
ncyBreadcrumb: { form: 'InventoryForm',
label: "CREATE SMART INVENTORY" controllers: {
}, add: 'InventoryAddController'
views: { }
'form@inventories': { });
templateProvider: function(SmartInventoryForm, GenerateForm) {
return GenerateForm.buildHTML(SmartInventoryForm, { let basicInventoryEdit = stateDefinitions.generateTree({
mode: 'add', name: 'inventories.edit',
related: false url: '/basic_inventory/:inventory_id',
}); modes: ['edit'],
},
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', form: 'InventoryForm',
controllers: { controllers: {
list: 'InventoryListController',
add: 'InventoryAddController',
edit: 'InventoryEditController' edit: 'InventoryEditController'
}, }
urls: { });
list: '/inventories'
}, 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: { ncyBreadcrumb: {
label: N_('INVENTORIES') label: N_('INVENTORIES')
}, },
@@ -140,24 +107,147 @@ angular.module('inventory', [
}, },
controller: 'InventoryListController' controller: 'InventoryListController'
} }
},
searchPrefix: 'inventory',
resolve: {
Dataset: ['InventoryList', 'QuerySet', '$stateParams', 'GetBasePath',
function(list, qs, $stateParams, GetBasePath) {
let path = GetBasePath(list.basePath) || GetBasePath(list.name);
return qs.search(path, $stateParams[`${list.iterator}_search`]);
} }
}); ]
}
return Promise.all([ })
inventories
]).then((generated) => {
return {
states: _.reduce(generated, (result, definition) => {
return result.concat(definition.states);
}, [
stateExtender.buildDefinition(smartInventoryAdd),
stateExtender.buildDefinition(smartInventoryAddOrgLookup)
]) ])
}; };
}); });
} }
// function generateInventoryStates() {
//
// let smartInventoryAdd = {
// name: 'inventories.addSmartInventory',
// url: '/smartinventory',
// form: 'SmartInventoryForm',
// ncyBreadcrumb: {
// label: "CREATE SMART INVENTORY"
// },
// 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',
url: '/hosts', url: '/hosts',