mirror of
https://github.com/ansible/awx.git
synced 2024-11-02 09:51:09 +03:00
Merge pull request #1295 from mabashian/1033-inv-source-error-handling
Fixed inventory source form error message
This commit is contained in:
commit
150467a1cb
@ -9,24 +9,83 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition',
|
||||
'GetChoices', 'GetBasePath', 'CreateSelect2', 'GetSourceTypeOptions',
|
||||
'rbacUiControlService', 'ToJSON', 'SourcesService', 'Empty',
|
||||
'Wait', 'Rest', 'Alert', 'ProcessErrors', 'inventorySourcesOptions',
|
||||
'$rootScope', 'i18n',
|
||||
'$rootScope', 'i18n', 'InventorySourceModel', 'InventoryHostsStrings',
|
||||
function($state, $stateParams, $scope, SourcesFormDefinition, ParseTypeChange,
|
||||
GenerateForm, inventoryData, GroupsService, GetChoices,
|
||||
GetBasePath, CreateSelect2, GetSourceTypeOptions, rbacUiControlService,
|
||||
ToJSON, SourcesService, Empty, Wait, Rest, Alert, ProcessErrors,
|
||||
inventorySourcesOptions,$rootScope, i18n) {
|
||||
inventorySourcesOptions,$rootScope, i18n, InventorySource, InventoryHostsStrings) {
|
||||
|
||||
let form = SourcesFormDefinition;
|
||||
init();
|
||||
|
||||
function init() {
|
||||
$scope.mode = 'add';
|
||||
// apply form definition's default field values
|
||||
GenerateForm.applyDefaults(form, $scope, true);
|
||||
$scope.canAdd = inventorySourcesOptions.actions.POST;
|
||||
$scope.envParseType = 'yaml';
|
||||
initSources();
|
||||
}
|
||||
|
||||
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
|
||||
});
|
||||
|
||||
// Load options for group_by
|
||||
GetChoices({
|
||||
scope: $scope,
|
||||
field: 'group_by',
|
||||
variable: 'ec2_group_by',
|
||||
choice_name: 'ec2_group_by_choices',
|
||||
options: inventorySourcesOptions
|
||||
});
|
||||
|
||||
initRegionSelect();
|
||||
|
||||
GetChoices({
|
||||
scope: $scope,
|
||||
field: 'verbosity',
|
||||
variable: 'verbosity_options',
|
||||
options: inventorySourcesOptions
|
||||
});
|
||||
|
||||
CreateSelect2({
|
||||
element: '#inventory_source_verbosity',
|
||||
multiple: false
|
||||
});
|
||||
|
||||
$scope.verbosity = $scope.verbosity_options[1];
|
||||
|
||||
GetSourceTypeOptions({
|
||||
scope: $scope,
|
||||
variable: 'source_type_options'
|
||||
});
|
||||
|
||||
const inventorySource = new InventorySource();
|
||||
|
||||
var getInventoryFiles = function (project) {
|
||||
var url;
|
||||
@ -39,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(() => {
|
||||
@ -59,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;
|
||||
@ -151,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(){
|
||||
@ -160,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;
|
||||
@ -209,81 +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];
|
||||
}
|
||||
|
||||
function initSources(){
|
||||
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
|
||||
});
|
||||
|
||||
// Load options for group_by
|
||||
GetChoices({
|
||||
scope: $scope,
|
||||
field: 'group_by',
|
||||
variable: 'ec2_group_by',
|
||||
choice_name: 'ec2_group_by_choices',
|
||||
options: inventorySourcesOptions
|
||||
});
|
||||
|
||||
initRegionSelect();
|
||||
|
||||
GetChoices({
|
||||
scope: $scope,
|
||||
field: 'verbosity',
|
||||
variable: 'verbosity_options',
|
||||
options: inventorySourcesOptions
|
||||
});
|
||||
|
||||
initVerbositySelect();
|
||||
|
||||
GetSourceTypeOptions({
|
||||
scope: $scope,
|
||||
variable: 'source_type_options'
|
||||
});
|
||||
}
|
||||
|
||||
$scope.formCancel = function() {
|
||||
$state.go('^');
|
||||
};
|
||||
@ -325,9 +304,17 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition',
|
||||
} else {
|
||||
params.source = null;
|
||||
}
|
||||
SourcesService.post(params).then((response) => {
|
||||
|
||||
inventorySource.request('post', {
|
||||
data: params
|
||||
}).then((response) => {
|
||||
let inventory_source_id = response.data.id;
|
||||
$state.go('^.edit', {inventory_source_id: inventory_source_id}, {reload: true});
|
||||
}).catch(({ data, status, config }) => {
|
||||
ProcessErrors($scope, data, status, null, {
|
||||
hdr: 'Error!',
|
||||
msg: InventoryHostsStrings.get('error.CALL', { path: `${config.url}`, status })
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
@ -7,15 +7,18 @@
|
||||
export default ['$state', '$stateParams', '$scope', 'ParseVariableString',
|
||||
'rbacUiControlService', 'ToJSON', 'ParseTypeChange', 'GroupsService',
|
||||
'GetChoices', 'GetBasePath', 'CreateSelect2', 'GetSourceTypeOptions',
|
||||
'inventorySourceData', 'SourcesService', 'inventoryData', 'inventorySourcesOptions', 'Empty',
|
||||
'Wait', 'Rest', 'Alert', '$rootScope', 'i18n',
|
||||
'SourcesService', 'inventoryData', 'inventorySourcesOptions', 'Empty',
|
||||
'Wait', 'Rest', 'Alert', '$rootScope', 'i18n', 'InventoryHostsStrings',
|
||||
'ProcessErrors', 'inventorySource',
|
||||
function($state, $stateParams, $scope, ParseVariableString,
|
||||
rbacUiControlService, ToJSON,ParseTypeChange, GroupsService,
|
||||
GetChoices, GetBasePath, CreateSelect2, GetSourceTypeOptions,
|
||||
inventorySourceData, SourcesService, inventoryData, inventorySourcesOptions, Empty,
|
||||
Wait, Rest, Alert, $rootScope, i18n) {
|
||||
SourcesService, inventoryData, inventorySourcesOptions, Empty,
|
||||
Wait, Rest, Alert, $rootScope, i18n, InventoryHostsStrings,
|
||||
ProcessErrors, inventorySource) {
|
||||
|
||||
const inventorySourceData = inventorySource.get();
|
||||
|
||||
function init() {
|
||||
$scope.projectBasePath = GetBasePath('projects') + '?not__status=never updated';
|
||||
$scope.canAdd = inventorySourcesOptions.actions.POST;
|
||||
// instantiate expected $scope values from inventorySourceData
|
||||
@ -51,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,
|
||||
@ -85,7 +170,6 @@ export default ['$state', '$stateParams', '$scope', 'ParseVariableString',
|
||||
updateSCMProject();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function initVerbositySelect(){
|
||||
CreateSelect2({
|
||||
@ -138,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;
|
||||
@ -366,9 +352,16 @@ export default ['$state', '$stateParams', '$scope', 'ParseVariableString',
|
||||
params.source = null;
|
||||
}
|
||||
|
||||
SourcesService
|
||||
.put(params)
|
||||
.then(() => $state.go('.', null, { reload: true }));
|
||||
inventorySource.request('put', {
|
||||
data: params
|
||||
}).then(() => {
|
||||
$state.go('.', null, { reload: true });
|
||||
}).catch(({ data, status, config }) => {
|
||||
ProcessErrors($scope, data, status, null, {
|
||||
hdr: 'Error!',
|
||||
msg: InventoryHostsStrings.get('error.CALL', { path: `${config.url}`, status })
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
$scope.sourceChange = function(source) {
|
||||
@ -419,7 +412,5 @@ export default ['$state', '$stateParams', '$scope', 'ParseVariableString',
|
||||
initRegionSelect();
|
||||
|
||||
};
|
||||
|
||||
init();
|
||||
}
|
||||
];
|
||||
|
@ -20,8 +20,8 @@ export default {
|
||||
}
|
||||
},
|
||||
resolve: {
|
||||
inventorySourceData: ['$stateParams', 'SourcesService', function($stateParams, SourcesService) {
|
||||
return SourcesService.get({id: $stateParams.inventory_source_id }).then(response => response.data.results[0]);
|
||||
inventorySource: ['InventorySourceModel', '$stateParams', (InventorySource, $stateParams) => {
|
||||
return new InventorySource('get', $stateParams.inventory_source_id);
|
||||
}],
|
||||
inventorySourcesOptions: ['InventoriesService', '$stateParams', function(InventoriesService, $stateParams) {
|
||||
return InventoriesService.inventorySourcesOptions($stateParams.inventory_id)
|
||||
|
Loading…
Reference in New Issue
Block a user