mirror of
https://github.com/ansible/awx.git
synced 2024-11-02 09:51:09 +03:00
Function/code cleanup
This commit is contained in:
parent
23d1454646
commit
453a8507b0
@ -73,7 +73,12 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition',
|
||||
options: inventorySourcesOptions
|
||||
});
|
||||
|
||||
initVerbositySelect();
|
||||
CreateSelect2({
|
||||
element: '#inventory_source_verbosity',
|
||||
multiple: false
|
||||
});
|
||||
|
||||
$scope.verbosity = $scope.verbosity_options[1];
|
||||
|
||||
GetSourceTypeOptions({
|
||||
scope: $scope,
|
||||
@ -93,7 +98,14 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition',
|
||||
.then(({data}) => {
|
||||
$scope.inventory_files = data;
|
||||
$scope.inventory_files.push("/ (project root)");
|
||||
sync_inventory_file_select2();
|
||||
CreateSelect2({
|
||||
element:'#inventory-file-select',
|
||||
addNew: true,
|
||||
multiple: false,
|
||||
scope: $scope,
|
||||
options: 'inventory_files',
|
||||
model: 'inventory_file'
|
||||
});
|
||||
Wait('stop');
|
||||
})
|
||||
.catch(() => {
|
||||
@ -113,17 +125,6 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition',
|
||||
}
|
||||
});
|
||||
|
||||
function sync_inventory_file_select2() {
|
||||
CreateSelect2({
|
||||
element:'#inventory-file-select',
|
||||
addNew: true,
|
||||
multiple: false,
|
||||
scope: $scope,
|
||||
options: 'inventory_files',
|
||||
model: 'inventory_file'
|
||||
});
|
||||
}
|
||||
|
||||
$scope.lookupCredential = function(){
|
||||
if($scope.source.value !== "scm" && $scope.source.value !== "custom") {
|
||||
let kind = ($scope.source.value === "ec2") ? "aws" : $scope.source.value;
|
||||
@ -205,7 +206,10 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition',
|
||||
// region / source options callback
|
||||
|
||||
$scope.$on('sourceTypeOptionsReady', function() {
|
||||
initSourceSelect();
|
||||
CreateSelect2({
|
||||
element: '#inventory_source_source',
|
||||
multiple: false
|
||||
});
|
||||
});
|
||||
|
||||
function initRegionSelect(){
|
||||
@ -214,10 +218,6 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition',
|
||||
multiple: true
|
||||
});
|
||||
|
||||
initGroupBySelect();
|
||||
}
|
||||
|
||||
function initGroupBySelect(){
|
||||
let add_new = false;
|
||||
if( _.get($scope, 'source') === 'ec2' || _.get($scope.source, 'value') === 'ec2') {
|
||||
$scope.group_by_choices = $scope.ec2_group_by;
|
||||
@ -263,22 +263,6 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition',
|
||||
});
|
||||
}
|
||||
|
||||
function initSourceSelect(){
|
||||
CreateSelect2({
|
||||
element: '#inventory_source_source',
|
||||
multiple: false
|
||||
});
|
||||
}
|
||||
|
||||
function initVerbositySelect(){
|
||||
CreateSelect2({
|
||||
element: '#inventory_source_verbosity',
|
||||
multiple: false
|
||||
});
|
||||
|
||||
$scope.verbosity = $scope.verbosity_options[1];
|
||||
}
|
||||
|
||||
$scope.formCancel = function() {
|
||||
$state.go('^');
|
||||
};
|
||||
|
@ -54,12 +54,94 @@ export default ['$state', '$stateParams', '$scope', 'ParseVariableString',
|
||||
});
|
||||
|
||||
$scope.$on('sourceTypeOptionsReady', function() {
|
||||
initSourceSelect();
|
||||
$scope.source = _.find($scope.source_type_options, { value: inventorySourceData.source });
|
||||
var source = $scope.source && $scope.source.value ? $scope.source.value : null;
|
||||
$scope.cloudCredentialRequired = source !== '' && source !== 'scm' && source !== 'custom' && source !== 'ec2' ? true : false;
|
||||
CreateSelect2({
|
||||
element: '#inventory_source_source',
|
||||
multiple: false
|
||||
});
|
||||
|
||||
if (source === 'ec2' || source === 'custom' ||
|
||||
source === 'vmware' || source === 'openstack' ||
|
||||
source === 'scm' || source === 'cloudforms' ||
|
||||
source === 'satellite6') {
|
||||
|
||||
var varName;
|
||||
if (source === 'scm') {
|
||||
varName = 'custom_variables';
|
||||
} else {
|
||||
varName = source + '_variables';
|
||||
}
|
||||
|
||||
$scope[varName] = ParseVariableString(inventorySourceData
|
||||
.source_vars);
|
||||
|
||||
ParseTypeChange({
|
||||
scope: $scope,
|
||||
field_id: varName,
|
||||
variable: varName,
|
||||
parse_variable: 'envParseType',
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$scope.envParseType = 'yaml';
|
||||
|
||||
initSources();
|
||||
GetSourceTypeOptions({
|
||||
scope: $scope,
|
||||
variable: 'source_type_options'
|
||||
});
|
||||
GetChoices({
|
||||
scope: $scope,
|
||||
field: 'source_regions',
|
||||
variable: 'rax_regions',
|
||||
choice_name: 'rax_region_choices',
|
||||
options: inventorySourcesOptions
|
||||
});
|
||||
GetChoices({
|
||||
scope: $scope,
|
||||
field: 'source_regions',
|
||||
variable: 'ec2_regions',
|
||||
choice_name: 'ec2_region_choices',
|
||||
options: inventorySourcesOptions
|
||||
});
|
||||
GetChoices({
|
||||
scope: $scope,
|
||||
field: 'source_regions',
|
||||
variable: 'gce_regions',
|
||||
choice_name: 'gce_region_choices',
|
||||
options: inventorySourcesOptions
|
||||
});
|
||||
GetChoices({
|
||||
scope: $scope,
|
||||
field: 'source_regions',
|
||||
variable: 'azure_regions',
|
||||
choice_name: 'azure_rm_region_choices',
|
||||
options: inventorySourcesOptions
|
||||
});
|
||||
GetChoices({
|
||||
scope: $scope,
|
||||
field: 'group_by',
|
||||
variable: 'ec2_group_by',
|
||||
choice_name: 'ec2_group_by_choices',
|
||||
options: inventorySourcesOptions
|
||||
});
|
||||
|
||||
var source = $scope.source === 'azure_rm' ? 'azure' : $scope.source;
|
||||
var regions = inventorySourceData.source_regions.split(',');
|
||||
// azure_rm regions choices are keyed as "azure" in an OPTIONS request to the inventory_sources endpoint
|
||||
$scope.source_region_choices = $scope[source + '_regions'];
|
||||
|
||||
// the API stores azure regions as all-lowercase strings - but the azure regions received from OPTIONS are Snake_Cased
|
||||
if (source === 'azure') {
|
||||
$scope.source_regions = _.map(regions, (region) => _.find($scope[source + '_regions'], (o) => o.value.toLowerCase() === region));
|
||||
}
|
||||
// all other regions are 1-1
|
||||
else {
|
||||
$scope.source_regions = _.map(regions, (region) => _.find($scope[source + '_regions'], (o) => o.value === region));
|
||||
}
|
||||
initRegionSelect();
|
||||
|
||||
GetChoices({
|
||||
scope: $scope,
|
||||
@ -140,110 +222,12 @@ export default ['$state', '$stateParams', '$scope', 'ParseVariableString',
|
||||
}
|
||||
}
|
||||
|
||||
function initSourceSelect() {
|
||||
$scope.source = _.find($scope.source_type_options, { value: inventorySourceData.source });
|
||||
var source = $scope.source && $scope.source.value ? $scope.source.value : null;
|
||||
$scope.cloudCredentialRequired = source !== '' && source !== 'scm' && source !== 'custom' && source !== 'ec2' ? true : false;
|
||||
CreateSelect2({
|
||||
element: '#inventory_source_source',
|
||||
multiple: false
|
||||
});
|
||||
|
||||
if (source === 'ec2' || source === 'custom' ||
|
||||
source === 'vmware' || source === 'openstack' ||
|
||||
source === 'scm' || source === 'cloudforms' ||
|
||||
source === 'satellite6') {
|
||||
|
||||
var varName;
|
||||
if (source === 'scm') {
|
||||
varName = 'custom_variables';
|
||||
} else {
|
||||
varName = source + '_variables';
|
||||
}
|
||||
|
||||
$scope[varName] = ParseVariableString(inventorySourceData
|
||||
.source_vars);
|
||||
|
||||
ParseTypeChange({
|
||||
scope: $scope,
|
||||
field_id: varName,
|
||||
variable: varName,
|
||||
parse_variable: 'envParseType',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function initRegionData() {
|
||||
var source = $scope.source === 'azure_rm' ? 'azure' : $scope.source;
|
||||
var regions = inventorySourceData.source_regions.split(',');
|
||||
// azure_rm regions choices are keyed as "azure" in an OPTIONS request to the inventory_sources endpoint
|
||||
$scope.source_region_choices = $scope[source + '_regions'];
|
||||
|
||||
// the API stores azure regions as all-lowercase strings - but the azure regions received from OPTIONS are Snake_Cased
|
||||
if (source === 'azure') {
|
||||
$scope.source_regions = _.map(regions, (region) => _.find($scope[source + '_regions'], (o) => o.value.toLowerCase() === region));
|
||||
}
|
||||
// all other regions are 1-1
|
||||
else {
|
||||
$scope.source_regions = _.map(regions, (region) => _.find($scope[source + '_regions'], (o) => o.value === region));
|
||||
}
|
||||
initRegionSelect();
|
||||
}
|
||||
|
||||
function initSources() {
|
||||
GetSourceTypeOptions({
|
||||
scope: $scope,
|
||||
variable: 'source_type_options'
|
||||
});
|
||||
GetChoices({
|
||||
scope: $scope,
|
||||
field: 'source_regions',
|
||||
variable: 'rax_regions',
|
||||
choice_name: 'rax_region_choices',
|
||||
options: inventorySourcesOptions
|
||||
});
|
||||
GetChoices({
|
||||
scope: $scope,
|
||||
field: 'source_regions',
|
||||
variable: 'ec2_regions',
|
||||
choice_name: 'ec2_region_choices',
|
||||
options: inventorySourcesOptions
|
||||
});
|
||||
GetChoices({
|
||||
scope: $scope,
|
||||
field: 'source_regions',
|
||||
variable: 'gce_regions',
|
||||
choice_name: 'gce_region_choices',
|
||||
options: inventorySourcesOptions
|
||||
});
|
||||
GetChoices({
|
||||
scope: $scope,
|
||||
field: 'source_regions',
|
||||
variable: 'azure_regions',
|
||||
choice_name: 'azure_rm_region_choices',
|
||||
options: inventorySourcesOptions
|
||||
});
|
||||
GetChoices({
|
||||
scope: $scope,
|
||||
field: 'group_by',
|
||||
variable: 'ec2_group_by',
|
||||
choice_name: 'ec2_group_by_choices',
|
||||
options: inventorySourcesOptions
|
||||
});
|
||||
|
||||
initRegionData();
|
||||
}
|
||||
|
||||
function initRegionSelect() {
|
||||
CreateSelect2({
|
||||
element: '#inventory_source_source_regions',
|
||||
multiple: true
|
||||
});
|
||||
|
||||
initGroupBySelect();
|
||||
}
|
||||
|
||||
function initGroupBySelect(){
|
||||
let add_new = false;
|
||||
if( _.get($scope, 'source') === 'ec2' || _.get($scope.source, 'value') === 'ec2') {
|
||||
$scope.group_by_choices = $scope.ec2_group_by;
|
||||
|
Loading…
Reference in New Issue
Block a user