1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-02 09:51:09 +03:00

Merge pull request #6459 from mabashian/inventory-source-fixes

Reduced options requests on inventory source form
This commit is contained in:
Michael Abashian 2017-06-06 09:59:13 -04:00 committed by GitHub
commit ebebb7149f
6 changed files with 47 additions and 46 deletions

View File

@ -55,6 +55,13 @@
rootGroupsUrl: function(id){ rootGroupsUrl: function(id){
var url = GetBasePath('inventory') + id+ '/root_groups'; var url = GetBasePath('inventory') + id+ '/root_groups';
return url; 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));
} }
}; };
}]; }];

View File

@ -7,12 +7,12 @@
export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition', export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition',
'ParseTypeChange', 'GenerateForm', 'inventoryData', 'GroupManageService', 'ParseTypeChange', 'GenerateForm', 'inventoryData', 'GroupManageService',
'GetChoices', 'GetBasePath', 'CreateSelect2', 'GetSourceTypeOptions', 'GetChoices', 'GetBasePath', 'CreateSelect2', 'GetSourceTypeOptions',
'rbacUiControlService', 'ToJSON', 'SourcesService', 'canAdd', 'Empty', 'rbacUiControlService', 'ToJSON', 'SourcesService', 'Empty',
'Wait', 'Rest', 'Alert', 'ProcessErrors', 'Wait', 'Rest', 'Alert', 'ProcessErrors', 'inventorySourcesOptions',
function($state, $stateParams, $scope, SourcesFormDefinition, ParseTypeChange, function($state, $stateParams, $scope, SourcesFormDefinition, ParseTypeChange,
GenerateForm, inventoryData, GroupManageService, GetChoices, GenerateForm, inventoryData, GroupManageService, GetChoices,
GetBasePath, CreateSelect2, GetSourceTypeOptions, rbacUiControlService, GetBasePath, CreateSelect2, GetSourceTypeOptions, rbacUiControlService,
ToJSON, SourcesService, canAdd, Empty, Wait, Rest, Alert, ProcessErrors) { ToJSON, SourcesService, Empty, Wait, Rest, Alert, ProcessErrors, inventorySourcesOptions) {
let form = SourcesFormDefinition; let form = SourcesFormDefinition;
init(); init();
@ -20,7 +20,7 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition',
function init() { function init() {
// apply form definition's default field values // apply form definition's default field values
GenerateForm.applyDefaults(form, $scope); GenerateForm.applyDefaults(form, $scope);
$scope.canAdd = canAdd; $scope.canAdd = inventorySourcesOptions.actions.POST;
$scope.envParseType = 'yaml'; $scope.envParseType = 'yaml';
initSources(); initSources();
} }
@ -213,61 +213,61 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition',
function initSources(){ function initSources(){
GetChoices({ GetChoices({
scope: $scope, scope: $scope,
url: GetBasePath('inventory_sources'),
field: 'source_regions', field: 'source_regions',
variable: 'rax_regions', variable: 'rax_regions',
choice_name: 'rax_region_choices', choice_name: 'rax_region_choices',
callback: 'choicesReadyGroup' callback: 'choicesReadyGroup',
options: inventorySourcesOptions
}); });
GetChoices({ GetChoices({
scope: $scope, scope: $scope,
url: GetBasePath('inventory_sources'),
field: 'source_regions', field: 'source_regions',
variable: 'ec2_regions', variable: 'ec2_regions',
choice_name: 'ec2_region_choices', choice_name: 'ec2_region_choices',
callback: 'choicesReadyGroup' callback: 'choicesReadyGroup',
options: inventorySourcesOptions
}); });
GetChoices({ GetChoices({
scope: $scope, scope: $scope,
url: GetBasePath('inventory_sources'),
field: 'source_regions', field: 'source_regions',
variable: 'gce_regions', variable: 'gce_regions',
choice_name: 'gce_region_choices', choice_name: 'gce_region_choices',
callback: 'choicesReadyGroup' callback: 'choicesReadyGroup',
options: inventorySourcesOptions
}); });
GetChoices({ GetChoices({
scope: $scope, scope: $scope,
url: GetBasePath('inventory_sources'),
field: 'source_regions', field: 'source_regions',
variable: 'azure_regions', variable: 'azure_regions',
choice_name: 'azure_region_choices', choice_name: 'azure_region_choices',
callback: 'choicesReadyGroup' callback: 'choicesReadyGroup',
options: inventorySourcesOptions
}); });
// Load options for group_by // Load options for group_by
GetChoices({ GetChoices({
scope: $scope, scope: $scope,
url: GetBasePath('inventory_sources'),
field: 'group_by', field: 'group_by',
variable: 'ec2_group_by', variable: 'ec2_group_by',
choice_name: 'ec2_group_by_choices', choice_name: 'ec2_group_by_choices',
callback: 'choicesReadyGroup' callback: 'choicesReadyGroup',
options: inventorySourcesOptions
}); });
GetChoices({ GetChoices({
scope: $scope, scope: $scope,
url: GetBasePath('inventory_sources'),
field: 'verbosity', field: 'verbosity',
variable: 'verbosity_options', variable: 'verbosity_options',
callback: 'choicesReadyVerbosity' callback: 'choicesReadyVerbosity',
options: inventorySourcesOptions
}); });
GetSourceTypeOptions({ GetSourceTypeOptions({
scope: $scope, scope: $scope,
variable: 'source_type_options', variable: 'source_type_options'
//callback: 'sourceTypeOptionsReady' this callback is hard-coded into GetSourceTypeOptions(), included for ref //callback: 'sourceTypeOptionsReady' this callback is hard-coded into GetSourceTypeOptions(), included for ref
}); });
} }

View File

@ -20,13 +20,10 @@ export default {
} }
}, },
resolve: { resolve: {
canAdd: ['rbacUiControlService', 'GetBasePath', '$stateParams', function(rbacUiControlService, GetBasePath, $stateParams) { inventorySourcesOptions: ['InventoryManageService', '$stateParams', function(InventoryManageService, $stateParams) {
return rbacUiControlService.canAdd(GetBasePath('inventory') + $stateParams.inventory_id + "/inventory_sources") return InventoryManageService.inventorySourcesOptions($stateParams.inventory_id)
.then(function(res) { .then(function(res) {
return res.canAdd; return res.data;
})
.catch(function() {
return false;
}); });
}] }]
} }

View File

@ -7,18 +7,18 @@
export default ['$state', '$stateParams', '$scope', 'ParseVariableString', export default ['$state', '$stateParams', '$scope', 'ParseVariableString',
'rbacUiControlService', 'ToJSON', 'ParseTypeChange', 'GroupManageService', 'rbacUiControlService', 'ToJSON', 'ParseTypeChange', 'GroupManageService',
'GetChoices', 'GetBasePath', 'CreateSelect2', 'GetSourceTypeOptions', 'GetChoices', 'GetBasePath', 'CreateSelect2', 'GetSourceTypeOptions',
'inventorySourceData', 'SourcesService', 'inventoryData', 'canAdd', 'Empty', 'inventorySourceData', 'SourcesService', 'inventoryData', 'inventorySourcesOptions', 'Empty',
'Wait', 'Rest', 'Alert', 'ProcessErrors', 'Wait', 'Rest', 'Alert', 'ProcessErrors',
function($state, $stateParams, $scope, ParseVariableString, function($state, $stateParams, $scope, ParseVariableString,
rbacUiControlService, ToJSON,ParseTypeChange, GroupManageService, rbacUiControlService, ToJSON,ParseTypeChange, GroupManageService,
GetChoices, GetBasePath, CreateSelect2, GetSourceTypeOptions, GetChoices, GetBasePath, CreateSelect2, GetSourceTypeOptions,
inventorySourceData, SourcesService, inventoryData, canAdd, Empty, inventorySourceData, SourcesService, inventoryData, inventorySourcesOptions, Empty,
Wait, Rest, Alert, ProcessErrors) { Wait, Rest, Alert, ProcessErrors) {
init(); init();
function init() { function init() {
$scope.canAdd = canAdd; $scope.canAdd = inventorySourcesOptions.actions.POST;
// instantiate expected $scope values from inventorySourceData // instantiate expected $scope values from inventorySourceData
_.assign($scope, _.assign($scope,
{credential: inventorySourceData.credential}, {credential: inventorySourceData.credential},
@ -316,43 +316,43 @@ export default ['$state', '$stateParams', '$scope', 'ParseVariableString',
}); });
GetChoices({ GetChoices({
scope: $scope, scope: $scope,
url: GetBasePath('inventory_sources'),
field: 'source_regions', field: 'source_regions',
variable: 'rax_regions', variable: 'rax_regions',
choice_name: 'rax_region_choices', choice_name: 'rax_region_choices',
callback: 'choicesReadyGroup' callback: 'choicesReadyGroup',
options: inventorySourcesOptions
}); });
GetChoices({ GetChoices({
scope: $scope, scope: $scope,
url: GetBasePath('inventory_sources'),
field: 'source_regions', field: 'source_regions',
variable: 'ec2_regions', variable: 'ec2_regions',
choice_name: 'ec2_region_choices', choice_name: 'ec2_region_choices',
callback: 'choicesReadyGroup' callback: 'choicesReadyGroup',
options: inventorySourcesOptions
}); });
GetChoices({ GetChoices({
scope: $scope, scope: $scope,
url: GetBasePath('inventory_sources'),
field: 'source_regions', field: 'source_regions',
variable: 'gce_regions', variable: 'gce_regions',
choice_name: 'gce_region_choices', choice_name: 'gce_region_choices',
callback: 'choicesReadyGroup' callback: 'choicesReadyGroup',
options: inventorySourcesOptions
}); });
GetChoices({ GetChoices({
scope: $scope, scope: $scope,
url: GetBasePath('inventory_sources'),
field: 'source_regions', field: 'source_regions',
variable: 'azure_regions', variable: 'azure_regions',
choice_name: 'azure_region_choices', choice_name: 'azure_region_choices',
callback: 'choicesReadyGroup' callback: 'choicesReadyGroup',
options: inventorySourcesOptions
}); });
GetChoices({ GetChoices({
scope: $scope, scope: $scope,
url: GetBasePath('inventory_sources'),
field: 'group_by', field: 'group_by',
variable: 'ec2_group_by', variable: 'ec2_group_by',
choice_name: 'ec2_group_by_choices', choice_name: 'ec2_group_by_choices',
callback: 'choicesReadyGroup' callback: 'choicesReadyGroup',
options: inventorySourcesOptions
}); });
} }
@ -385,10 +385,10 @@ export default ['$state', '$stateParams', '$scope', 'ParseVariableString',
GetChoices({ GetChoices({
scope: $scope, scope: $scope,
url: GetBasePath('inventory_sources'),
field: 'verbosity', field: 'verbosity',
variable: 'verbosity_options', variable: 'verbosity_options',
callback: 'choicesReadyVerbosity' callback: 'choicesReadyVerbosity',
options: inventorySourcesOptions
}); });
// region / source options callback // region / source options callback

View File

@ -23,13 +23,10 @@ export default {
inventorySourceData: ['$stateParams', 'SourcesService', function($stateParams, SourcesService) { inventorySourceData: ['$stateParams', 'SourcesService', function($stateParams, SourcesService) {
return SourcesService.get({id: $stateParams.inventory_source_id }).then(res => res.data.results[0]); return SourcesService.get({id: $stateParams.inventory_source_id }).then(res => res.data.results[0]);
}], }],
canAdd: ['rbacUiControlService', 'GetBasePath', '$stateParams', function(rbacUiControlService, GetBasePath, $stateParams) { inventorySourcesOptions: ['InventoryManageService', '$stateParams', function(InventoryManageService, $stateParams) {
return rbacUiControlService.canAdd(GetBasePath('inventory') + $stateParams.inventory_id + "/inventory_sources") return InventoryManageService.inventorySourcesOptions($stateParams.inventory_id)
.then(function(res) { .then(function(res) {
return res.canAdd; return res.data;
})
.catch(function() {
return false;
}); });
}] }]
} }

View File

@ -93,7 +93,7 @@ return {
sourceField: 'name', sourceField: 'name',
ngClick: 'lookupProject()', ngClick: 'lookupProject()',
awRequiredWhen: { awRequiredWhen: {
reqExpression: "projectRequired", reqExpression: "source && source.value === 'scm'",
init: "false" init: "false"
}, },
ngDisabled: '!(inventory_source_obj.summary_fields.user_capabilities.edit || canAdd)', 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", ngDisabled: "!(inventory_source_obj.summary_fields.user_capabilities.edit || canAdd) || disableInventoryFileBecausePermissionDenied",
id: 'inventory-file-select', id: 'inventory-file-select',
awRequiredWhen: { awRequiredWhen: {
reqExpression: "inventoryfilerequired", reqExpression: "source && source.value === 'scm'",
init: "true" init: "true"
}, },
column: 1, column: 1,