From 46c19c26aa648c39be058fad2b5c6d7440ae35ba Mon Sep 17 00:00:00 2001 From: Michael Abashian Date: Mon, 15 May 2017 16:14:38 -0400 Subject: [PATCH] Added inv source add/edit cred and inv script lookup states --- awx/ui/client/src/inventories/main.js | 24 ++++++- .../lookup/sources-lookup-credential.route.js | 50 ++++++++++++++ .../sources-lookup-inventory-script.route.js | 65 +++++++++++++++++++ 3 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 awx/ui/client/src/inventories/sources/lookup/sources-lookup-credential.route.js create mode 100644 awx/ui/client/src/inventories/sources/lookup/sources-lookup-inventory-script.route.js diff --git a/awx/ui/client/src/inventories/main.js b/awx/ui/client/src/inventories/main.js index e3362436c7..d8c095c210 100644 --- a/awx/ui/client/src/inventories/main.js +++ b/awx/ui/client/src/inventories/main.js @@ -45,6 +45,8 @@ import nestedHostsAdd from './groups/nested-hosts/nested-hosts-add.route'; import nestedHostsEdit from './groups/nested-hosts/nested-hosts-edit.route'; import ansibleFactsRoute from './ansible_facts/ansible_facts.route'; import insightsRoute from './insights/insights.route'; +import inventorySourcesCredentialRoute from './sources/lookup/sources-lookup-credential.route'; +import inventorySourcesInventoryScriptRoute from './sources/lookup/sources-lookup-inventory-script.route'; export default angular.module('inventory', [ @@ -147,6 +149,22 @@ angular.module('inventory', [ let nestedHostsInsights = _.cloneDeep(insightsRoute); nestedHostsInsights.name = 'inventories.edit.groups.edit.nested_hosts.edit.insights'; + let addSourceCredential = _.cloneDeep(inventorySourcesCredentialRoute); + addSourceCredential.name = 'inventories.edit.inventory_sources.add.credential'; + addSourceCredential.url = '/credential'; + + let addSourceInventoryScript = _.cloneDeep(inventorySourcesInventoryScriptRoute); + addSourceInventoryScript.name = 'inventories.edit.inventory_sources.add.inventory_script'; + addSourceInventoryScript.url = '/inventory_script'; + + let editSourceCredential = _.cloneDeep(inventorySourcesCredentialRoute); + editSourceCredential.name = 'inventories.edit.inventory_sources.edit.credential'; + editSourceCredential.url = '/credential'; + + let editSourceInventoryScript = _.cloneDeep(inventorySourcesInventoryScriptRoute); + editSourceInventoryScript.name = 'inventories.edit.inventory_sources.edit.inventory_script'; + editSourceInventoryScript.url = '/inventory_script'; + return Promise.all([ basicInventoryAdd, basicInventoryEdit, @@ -185,7 +203,11 @@ angular.module('inventory', [ stateExtender.buildDefinition(inventorySourceListRoute), stateExtender.buildDefinition(inventorySourceAddRoute), stateExtender.buildDefinition(inventorySourceEditRoute), - stateExtender.buildDefinition(inventoryCompletedJobsRoute) + stateExtender.buildDefinition(inventoryCompletedJobsRoute), + stateExtender.buildDefinition(addSourceCredential), + stateExtender.buildDefinition(addSourceInventoryScript), + stateExtender.buildDefinition(editSourceCredential), + stateExtender.buildDefinition(editSourceInventoryScript) ]) }; }); diff --git a/awx/ui/client/src/inventories/sources/lookup/sources-lookup-credential.route.js b/awx/ui/client/src/inventories/sources/lookup/sources-lookup-credential.route.js new file mode 100644 index 0000000000..d033432ac1 --- /dev/null +++ b/awx/ui/client/src/inventories/sources/lookup/sources-lookup-credential.route.js @@ -0,0 +1,50 @@ +export default { + params: { + credential_search: { + value: { + page_size:"5", + order_by:"name", + role_level:"use_role", + }, + dynamic:true, + squash:"" + } + }, + data: { + basePath:"credentials", + formChildState:true + }, + ncyBreadcrumb: { + skip: true + }, + views: { + 'modal': { + templateProvider: function(ListDefinition, generateList) { + let list_html = generateList.build({ + mode: 'lookup', + list: ListDefinition, + input_type: 'radio' + }); + return `${list_html}`; + + } + } + }, + resolve: { + ListDefinition: ['CredentialList', function(list) { + return list; + }], + Dataset: ['ListDefinition', 'QuerySet', '$stateParams', 'GetBasePath', + (list, qs, $stateParams, GetBasePath) => { + return qs.search(GetBasePath('credentials'), $stateParams[`${list.iterator}_search`]); + } + ] + }, + onExit: function($state) { + if ($state.transition) { + $('#form-modal').modal('hide'); + $('.modal-backdrop').remove(); + $('body').removeClass('modal-open'); + } + } +}; diff --git a/awx/ui/client/src/inventories/sources/lookup/sources-lookup-inventory-script.route.js b/awx/ui/client/src/inventories/sources/lookup/sources-lookup-inventory-script.route.js new file mode 100644 index 0000000000..30863b76fa --- /dev/null +++ b/awx/ui/client/src/inventories/sources/lookup/sources-lookup-inventory-script.route.js @@ -0,0 +1,65 @@ +export default { + params: { + inventory_script_search: { + value: { + page_size: "5", + order_by: "name", + role_level: "admin_role", + }, + dynamic: true, + squash: "" + } + }, + data: { + basePath: "inventory_scripts", + formChildState: true + }, + ncyBreadcrumb: { + skip: true + }, + views: { + 'modal': { + templateProvider: function(ListDefinition, generateList) { + let list_html = generateList.build({ + mode: 'lookup', + list: ListDefinition, + input_type: 'radio' + }); + return `${list_html}`; + + } + } + }, + resolve: { + ListDefinition: ['InventoryScriptsList', function(list) { + return list; + }], + OrganizationId: ['ListDefinition', 'InventoryManageService', '$stateParams', '$rootScope', + function(list, InventoryManageService, $stateParams, $rootScope){ + if($rootScope.$$childTail && + $rootScope.$$childTail.$resolve && + $rootScope.$$childTail.$resolve.hasOwnProperty('inventoryData')){ + return $rootScope.$$childTail.$resolve.inventoryData.summary_fields.organization.id; + } + else { + return InventoryManageService.getInventory($stateParams.inventory_id).then(res => res.data.summary_fields.organization.id); + } + }], + Dataset: ['ListDefinition', 'QuerySet', '$stateParams', 'GetBasePath', '$interpolate', '$rootScope', '$state', 'OrganizationId', + (list, qs, $stateParams, GetBasePath, $interpolate, $rootScope, $state, OrganizationId) => { + + $stateParams[`${list.iterator}_search`].role_level = "admin_role"; + $stateParams[`${list.iterator}_search`].organization = OrganizationId; + + return qs.search(GetBasePath('inventory_scripts'), $stateParams[`${list.iterator}_search`]); + } + ] + }, + onExit: function($state) { + if ($state.transition) { + $('#form-modal').modal('hide'); + $('.modal-backdrop').remove(); + $('body').removeClass('modal-open'); + } + } +};