From 5058b0d78d754cc99a89b2ca084c4a21e0f4997d Mon Sep 17 00:00:00 2001 From: Michael Abashian Date: Mon, 5 Jun 2017 12:30:28 -0400 Subject: [PATCH] Reduced options requests on inventory source form --- .../inventories/inventory-manage.service.js | 7 ++++ .../sources/add/sources-add.controller.js | 34 +++++++++---------- .../sources/add/sources-add.route.js | 9 ++--- .../sources/edit/sources-edit.controller.js | 30 ++++++++-------- .../sources/edit/sources-edit.route.js | 9 ++--- .../src/inventories/sources/sources.form.js | 4 +-- 6 files changed, 47 insertions(+), 46 deletions(-) diff --git a/awx/ui/client/src/inventories/inventory-manage.service.js b/awx/ui/client/src/inventories/inventory-manage.service.js index 710c494aeb..757d5392e7 100644 --- a/awx/ui/client/src/inventories/inventory-manage.service.js +++ b/awx/ui/client/src/inventories/inventory-manage.service.js @@ -55,6 +55,13 @@ rootGroupsUrl: function(id){ var url = GetBasePath('inventory') + id+ '/root_groups'; return url; + }, + inventorySourcesOptions: function(inventoryId) { + this.url = GetBasePath('inventory') + inventoryId + '/inventory_sources'; + Rest.setUrl(this.url); + return Rest.options() + .success(this.success.bind(this)) + .error(this.error.bind(this)); } }; }]; diff --git a/awx/ui/client/src/inventories/sources/add/sources-add.controller.js b/awx/ui/client/src/inventories/sources/add/sources-add.controller.js index 9b5c31aed0..3e8a77c09f 100644 --- a/awx/ui/client/src/inventories/sources/add/sources-add.controller.js +++ b/awx/ui/client/src/inventories/sources/add/sources-add.controller.js @@ -7,12 +7,12 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition', 'ParseTypeChange', 'GenerateForm', 'inventoryData', 'GroupManageService', 'GetChoices', 'GetBasePath', 'CreateSelect2', 'GetSourceTypeOptions', - 'rbacUiControlService', 'ToJSON', 'SourcesService', 'canAdd', 'Empty', - 'Wait', 'Rest', 'Alert', 'ProcessErrors', + 'rbacUiControlService', 'ToJSON', 'SourcesService', 'Empty', + 'Wait', 'Rest', 'Alert', 'ProcessErrors', 'inventorySourcesOptions', function($state, $stateParams, $scope, SourcesFormDefinition, ParseTypeChange, GenerateForm, inventoryData, GroupManageService, GetChoices, GetBasePath, CreateSelect2, GetSourceTypeOptions, rbacUiControlService, - ToJSON, SourcesService, canAdd, Empty, Wait, Rest, Alert, ProcessErrors) { + ToJSON, SourcesService, Empty, Wait, Rest, Alert, ProcessErrors, inventorySourcesOptions) { let form = SourcesFormDefinition; init(); @@ -20,7 +20,7 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition', function init() { // apply form definition's default field values GenerateForm.applyDefaults(form, $scope); - $scope.canAdd = canAdd; + $scope.canAdd = inventorySourcesOptions.actions.POST; $scope.envParseType = 'yaml'; initSources(); } @@ -213,61 +213,61 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition', function initSources(){ GetChoices({ scope: $scope, - url: GetBasePath('inventory_sources'), field: 'source_regions', variable: 'rax_regions', choice_name: 'rax_region_choices', - callback: 'choicesReadyGroup' + callback: 'choicesReadyGroup', + options: inventorySourcesOptions }); GetChoices({ scope: $scope, - url: GetBasePath('inventory_sources'), field: 'source_regions', variable: 'ec2_regions', choice_name: 'ec2_region_choices', - callback: 'choicesReadyGroup' + callback: 'choicesReadyGroup', + options: inventorySourcesOptions }); GetChoices({ scope: $scope, - url: GetBasePath('inventory_sources'), field: 'source_regions', variable: 'gce_regions', choice_name: 'gce_region_choices', - callback: 'choicesReadyGroup' + callback: 'choicesReadyGroup', + options: inventorySourcesOptions }); GetChoices({ scope: $scope, - url: GetBasePath('inventory_sources'), field: 'source_regions', variable: 'azure_regions', choice_name: 'azure_region_choices', - callback: 'choicesReadyGroup' + callback: 'choicesReadyGroup', + options: inventorySourcesOptions }); // Load options for group_by GetChoices({ scope: $scope, - url: GetBasePath('inventory_sources'), field: 'group_by', variable: 'ec2_group_by', choice_name: 'ec2_group_by_choices', - callback: 'choicesReadyGroup' + callback: 'choicesReadyGroup', + options: inventorySourcesOptions }); GetChoices({ scope: $scope, - url: GetBasePath('inventory_sources'), field: 'verbosity', variable: 'verbosity_options', - callback: 'choicesReadyVerbosity' + callback: 'choicesReadyVerbosity', + options: inventorySourcesOptions }); GetSourceTypeOptions({ scope: $scope, - variable: 'source_type_options', + variable: 'source_type_options' //callback: 'sourceTypeOptionsReady' this callback is hard-coded into GetSourceTypeOptions(), included for ref }); } diff --git a/awx/ui/client/src/inventories/sources/add/sources-add.route.js b/awx/ui/client/src/inventories/sources/add/sources-add.route.js index bf5c878312..dda3d69bd6 100644 --- a/awx/ui/client/src/inventories/sources/add/sources-add.route.js +++ b/awx/ui/client/src/inventories/sources/add/sources-add.route.js @@ -20,13 +20,10 @@ export default { } }, resolve: { - canAdd: ['rbacUiControlService', 'GetBasePath', '$stateParams', function(rbacUiControlService, GetBasePath, $stateParams) { - return rbacUiControlService.canAdd(GetBasePath('inventory') + $stateParams.inventory_id + "/inventory_sources") + inventorySourcesOptions: ['InventoryManageService', '$stateParams', function(InventoryManageService, $stateParams) { + return InventoryManageService.inventorySourcesOptions($stateParams.inventory_id) .then(function(res) { - return res.canAdd; - }) - .catch(function() { - return false; + return res.data; }); }] } diff --git a/awx/ui/client/src/inventories/sources/edit/sources-edit.controller.js b/awx/ui/client/src/inventories/sources/edit/sources-edit.controller.js index 80a62605b4..2ea375abd9 100644 --- a/awx/ui/client/src/inventories/sources/edit/sources-edit.controller.js +++ b/awx/ui/client/src/inventories/sources/edit/sources-edit.controller.js @@ -7,18 +7,18 @@ export default ['$state', '$stateParams', '$scope', 'ParseVariableString', 'rbacUiControlService', 'ToJSON', 'ParseTypeChange', 'GroupManageService', 'GetChoices', 'GetBasePath', 'CreateSelect2', 'GetSourceTypeOptions', - 'inventorySourceData', 'SourcesService', 'inventoryData', 'canAdd', 'Empty', + 'inventorySourceData', 'SourcesService', 'inventoryData', 'inventorySourcesOptions', 'Empty', 'Wait', 'Rest', 'Alert', 'ProcessErrors', function($state, $stateParams, $scope, ParseVariableString, rbacUiControlService, ToJSON,ParseTypeChange, GroupManageService, GetChoices, GetBasePath, CreateSelect2, GetSourceTypeOptions, - inventorySourceData, SourcesService, inventoryData, canAdd, Empty, + inventorySourceData, SourcesService, inventoryData, inventorySourcesOptions, Empty, Wait, Rest, Alert, ProcessErrors) { init(); function init() { - $scope.canAdd = canAdd; + $scope.canAdd = inventorySourcesOptions.actions.POST; // instantiate expected $scope values from inventorySourceData _.assign($scope, {credential: inventorySourceData.credential}, @@ -316,43 +316,43 @@ export default ['$state', '$stateParams', '$scope', 'ParseVariableString', }); GetChoices({ scope: $scope, - url: GetBasePath('inventory_sources'), field: 'source_regions', variable: 'rax_regions', choice_name: 'rax_region_choices', - callback: 'choicesReadyGroup' + callback: 'choicesReadyGroup', + options: inventorySourcesOptions }); GetChoices({ scope: $scope, - url: GetBasePath('inventory_sources'), field: 'source_regions', variable: 'ec2_regions', choice_name: 'ec2_region_choices', - callback: 'choicesReadyGroup' + callback: 'choicesReadyGroup', + options: inventorySourcesOptions }); GetChoices({ scope: $scope, - url: GetBasePath('inventory_sources'), field: 'source_regions', variable: 'gce_regions', choice_name: 'gce_region_choices', - callback: 'choicesReadyGroup' + callback: 'choicesReadyGroup', + options: inventorySourcesOptions }); GetChoices({ scope: $scope, - url: GetBasePath('inventory_sources'), field: 'source_regions', variable: 'azure_regions', choice_name: 'azure_region_choices', - callback: 'choicesReadyGroup' + callback: 'choicesReadyGroup', + options: inventorySourcesOptions }); GetChoices({ scope: $scope, - url: GetBasePath('inventory_sources'), field: 'group_by', variable: 'ec2_group_by', choice_name: 'ec2_group_by_choices', - callback: 'choicesReadyGroup' + callback: 'choicesReadyGroup', + options: inventorySourcesOptions }); } @@ -385,10 +385,10 @@ export default ['$state', '$stateParams', '$scope', 'ParseVariableString', GetChoices({ scope: $scope, - url: GetBasePath('inventory_sources'), field: 'verbosity', variable: 'verbosity_options', - callback: 'choicesReadyVerbosity' + callback: 'choicesReadyVerbosity', + options: inventorySourcesOptions }); // region / source options callback diff --git a/awx/ui/client/src/inventories/sources/edit/sources-edit.route.js b/awx/ui/client/src/inventories/sources/edit/sources-edit.route.js index 21d289f1dc..a5ac85c1a6 100644 --- a/awx/ui/client/src/inventories/sources/edit/sources-edit.route.js +++ b/awx/ui/client/src/inventories/sources/edit/sources-edit.route.js @@ -23,13 +23,10 @@ export default { inventorySourceData: ['$stateParams', 'SourcesService', function($stateParams, SourcesService) { return SourcesService.get({id: $stateParams.inventory_source_id }).then(res => res.data.results[0]); }], - canAdd: ['rbacUiControlService', 'GetBasePath', '$stateParams', function(rbacUiControlService, GetBasePath, $stateParams) { - return rbacUiControlService.canAdd(GetBasePath('inventory') + $stateParams.inventory_id + "/inventory_sources") + inventorySourcesOptions: ['InventoryManageService', '$stateParams', function(InventoryManageService, $stateParams) { + return InventoryManageService.inventorySourcesOptions($stateParams.inventory_id) .then(function(res) { - return res.canAdd; - }) - .catch(function() { - return false; + return res.data; }); }] } diff --git a/awx/ui/client/src/inventories/sources/sources.form.js b/awx/ui/client/src/inventories/sources/sources.form.js index 465a05f6df..3ab68e5a8e 100644 --- a/awx/ui/client/src/inventories/sources/sources.form.js +++ b/awx/ui/client/src/inventories/sources/sources.form.js @@ -93,7 +93,7 @@ return { sourceField: 'name', ngClick: 'lookupProject()', awRequiredWhen: { - reqExpression: "projectRequired", + reqExpression: "source && source.value === 'scm'", init: "false" }, ngDisabled: '!(inventory_source_obj.summary_fields.user_capabilities.edit || canAdd)', @@ -107,7 +107,7 @@ return { ngDisabled: "!(inventory_source_obj.summary_fields.user_capabilities.edit || canAdd) || disableInventoryFileBecausePermissionDenied", id: 'inventory-file-select', awRequiredWhen: { - reqExpression: "inventoryfilerequired", + reqExpression: "source && source.value === 'scm'", init: "true" }, column: 1,