diff --git a/awx/ui/client/src/inventories/hosts/smart-inventory/smart-inventory.form.js b/awx/ui/client/src/inventories/hosts/smart-inventory/smart-inventory.form.js index 9404bb575c..a8055d8838 100644 --- a/awx/ui/client/src/inventories/hosts/smart-inventory/smart-inventory.form.js +++ b/awx/ui/client/src/inventories/hosts/smart-inventory/smart-inventory.form.js @@ -4,7 +4,7 @@ * All Rights Reserved *************************************************/ -export default ['i18n', function(i18n) { +export default ['i18n', 'buildHostListState', function(i18n, buildHostListState) { return { addTitle: i18n._('NEW SMART INVENTORY'), @@ -126,35 +126,12 @@ export default ['i18n', function(i18n) { }, hosts: { name: 'hosts', - // awToolTip: i18n._('Please save before assigning permissions'), - // dataPlacement: 'top', - basePath: 'api/v2/inventories/{{$stateParams.inventory_id}}/hosts/', - type: 'collection', + include: "RelatedHostsListDefinition", 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' - } - } + listState: buildHostListState, + // addState: buildGroupsAddState, + // editState: buildGroupsEditState }, //this is a placeholder for when we're ready for completed jobs completed_jobs: { diff --git a/awx/ui/client/src/inventories/main.js b/awx/ui/client/src/inventories/main.js index d8b6bcd33e..d7c93dfc22 100644 --- a/awx/ui/client/src/inventories/main.js +++ b/awx/ui/client/src/inventories/main.js @@ -34,129 +34,219 @@ angular.module('inventory', [ let stateDefinitions = stateDefinitionsProvider.$get(), stateExtender = $stateExtenderProvider.$get(); - 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 - }); + function generateInventoryStates() { + + let basicInventoryAdd = stateDefinitions.generateTree({ + name: 'inventories.add', // top-most node in the generated tree (will replace this state definition) + url: '/basic_inventory/add', + modes: ['add'], + form: 'InventoryForm', + controllers: { + add: 'InventoryAddController' + } + }); + + 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' - } - } - }; - - let smartInventoryAddOrgLookup = { - searchPrefix: 'organization', - name: 'inventories.addSmartInventory.organization', - url: '/organization', - data: { - formChildState: true - }, - params: { - organization_search: { - value: { - page_size: '5' + views: { + '@': { + templateUrl: templateUrl('inventories/inventories') + }, + 'list@inventories': { + templateProvider: function(InventoryList, generateList) { + let html = generateList.build({ + list: InventoryList, + mode: 'edit' + }); + return html; + }, + controller: 'InventoryListController' + } }, - 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 `${list_html}`; - + 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`]); + } + ] } - } - }, - 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) - ]) - }; - }); - - } + // 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 `${list_html}`; + // + // } + // } + // }, + // 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({ name: 'hosts',