mirror of
https://github.com/ansible/awx.git
synced 2026-05-14 04:47:44 -02:30
Fixed inventory source form error message. Leveraged inv src model for adding/editing existing object
This commit is contained in:
@@ -9,24 +9,78 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition',
|
|||||||
'GetChoices', 'GetBasePath', 'CreateSelect2', 'GetSourceTypeOptions',
|
'GetChoices', 'GetBasePath', 'CreateSelect2', 'GetSourceTypeOptions',
|
||||||
'rbacUiControlService', 'ToJSON', 'SourcesService', 'Empty',
|
'rbacUiControlService', 'ToJSON', 'SourcesService', 'Empty',
|
||||||
'Wait', 'Rest', 'Alert', 'ProcessErrors', 'inventorySourcesOptions',
|
'Wait', 'Rest', 'Alert', 'ProcessErrors', 'inventorySourcesOptions',
|
||||||
'$rootScope', 'i18n',
|
'$rootScope', 'i18n', 'InventorySourceModel', 'InventoryHostsStrings',
|
||||||
function($state, $stateParams, $scope, SourcesFormDefinition, ParseTypeChange,
|
function($state, $stateParams, $scope, SourcesFormDefinition, ParseTypeChange,
|
||||||
GenerateForm, inventoryData, GroupsService, GetChoices,
|
GenerateForm, inventoryData, GroupsService, GetChoices,
|
||||||
GetBasePath, CreateSelect2, GetSourceTypeOptions, rbacUiControlService,
|
GetBasePath, CreateSelect2, GetSourceTypeOptions, rbacUiControlService,
|
||||||
ToJSON, SourcesService, Empty, Wait, Rest, Alert, ProcessErrors,
|
ToJSON, SourcesService, Empty, Wait, Rest, Alert, ProcessErrors,
|
||||||
inventorySourcesOptions,$rootScope, i18n) {
|
inventorySourcesOptions,$rootScope, i18n, InventorySource, InventoryHostsStrings) {
|
||||||
|
|
||||||
let form = SourcesFormDefinition;
|
let form = SourcesFormDefinition;
|
||||||
init();
|
$scope.mode = 'add';
|
||||||
|
// apply form definition's default field values
|
||||||
|
GenerateForm.applyDefaults(form, $scope, true);
|
||||||
|
$scope.canAdd = inventorySourcesOptions.actions.POST;
|
||||||
|
$scope.envParseType = 'yaml';
|
||||||
|
|
||||||
function init() {
|
GetChoices({
|
||||||
$scope.mode = 'add';
|
scope: $scope,
|
||||||
// apply form definition's default field values
|
field: 'source_regions',
|
||||||
GenerateForm.applyDefaults(form, $scope, true);
|
variable: 'rax_regions',
|
||||||
$scope.canAdd = inventorySourcesOptions.actions.POST;
|
choice_name: 'rax_region_choices',
|
||||||
$scope.envParseType = 'yaml';
|
options: inventorySourcesOptions
|
||||||
initSources();
|
});
|
||||||
}
|
|
||||||
|
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'
|
||||||
|
});
|
||||||
|
|
||||||
|
const inventorySource = new InventorySource();
|
||||||
|
|
||||||
var getInventoryFiles = function (project) {
|
var getInventoryFiles = function (project) {
|
||||||
var url;
|
var url;
|
||||||
@@ -225,65 +279,6 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition',
|
|||||||
$scope.verbosity = $scope.verbosity_options[1];
|
$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() {
|
$scope.formCancel = function() {
|
||||||
$state.go('^');
|
$state.go('^');
|
||||||
};
|
};
|
||||||
@@ -325,9 +320,17 @@ export default ['$state', '$stateParams', '$scope', 'SourcesFormDefinition',
|
|||||||
} else {
|
} else {
|
||||||
params.source = null;
|
params.source = null;
|
||||||
}
|
}
|
||||||
SourcesService.post(params).then((response) => {
|
|
||||||
|
inventorySource.request('post', {
|
||||||
|
data: params
|
||||||
|
}).then((response) => {
|
||||||
let inventory_source_id = response.data.id;
|
let inventory_source_id = response.data.id;
|
||||||
$state.go('^.edit', {inventory_source_id: inventory_source_id}, {reload: true});
|
$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,85 +7,87 @@
|
|||||||
export default ['$state', '$stateParams', '$scope', 'ParseVariableString',
|
export default ['$state', '$stateParams', '$scope', 'ParseVariableString',
|
||||||
'rbacUiControlService', 'ToJSON', 'ParseTypeChange', 'GroupsService',
|
'rbacUiControlService', 'ToJSON', 'ParseTypeChange', 'GroupsService',
|
||||||
'GetChoices', 'GetBasePath', 'CreateSelect2', 'GetSourceTypeOptions',
|
'GetChoices', 'GetBasePath', 'CreateSelect2', 'GetSourceTypeOptions',
|
||||||
'inventorySourceData', 'SourcesService', 'inventoryData', 'inventorySourcesOptions', 'Empty',
|
'SourcesService', 'inventoryData', 'inventorySourcesOptions', 'Empty',
|
||||||
'Wait', 'Rest', 'Alert', '$rootScope', 'i18n',
|
'Wait', 'Rest', 'Alert', '$rootScope', 'i18n', 'InventoryHostsStrings',
|
||||||
|
'ProcessErrors', 'inventorySource',
|
||||||
function($state, $stateParams, $scope, ParseVariableString,
|
function($state, $stateParams, $scope, ParseVariableString,
|
||||||
rbacUiControlService, ToJSON,ParseTypeChange, GroupsService,
|
rbacUiControlService, ToJSON,ParseTypeChange, GroupsService,
|
||||||
GetChoices, GetBasePath, CreateSelect2, GetSourceTypeOptions,
|
GetChoices, GetBasePath, CreateSelect2, GetSourceTypeOptions,
|
||||||
inventorySourceData, SourcesService, inventoryData, inventorySourcesOptions, Empty,
|
SourcesService, inventoryData, inventorySourcesOptions, Empty,
|
||||||
Wait, Rest, Alert, $rootScope, i18n) {
|
Wait, Rest, Alert, $rootScope, i18n, InventoryHostsStrings,
|
||||||
|
ProcessErrors, inventorySource) {
|
||||||
|
|
||||||
function init() {
|
const inventorySourceData = inventorySource.get();
|
||||||
$scope.projectBasePath = GetBasePath('projects') + '?not__status=never updated';
|
|
||||||
$scope.canAdd = inventorySourcesOptions.actions.POST;
|
|
||||||
// instantiate expected $scope values from inventorySourceData
|
|
||||||
_.assign($scope,
|
|
||||||
{credential: inventorySourceData.credential},
|
|
||||||
{overwrite: inventorySourceData.overwrite},
|
|
||||||
{overwrite_vars: inventorySourceData.overwrite_vars},
|
|
||||||
{update_on_launch: inventorySourceData.update_on_launch},
|
|
||||||
{update_cache_timeout: inventorySourceData.update_cache_timeout},
|
|
||||||
{instance_filters: inventorySourceData.instance_filters},
|
|
||||||
{inventory_script: inventorySourceData.source_script},
|
|
||||||
{verbosity: inventorySourceData.verbosity});
|
|
||||||
|
|
||||||
$scope.inventory_source_obj = inventorySourceData;
|
$scope.projectBasePath = GetBasePath('projects') + '?not__status=never updated';
|
||||||
if (inventorySourceData.credential) {
|
$scope.canAdd = inventorySourcesOptions.actions.POST;
|
||||||
$scope.credential_name = inventorySourceData.summary_fields.credential.name;
|
// instantiate expected $scope values from inventorySourceData
|
||||||
|
_.assign($scope,
|
||||||
|
{credential: inventorySourceData.credential},
|
||||||
|
{overwrite: inventorySourceData.overwrite},
|
||||||
|
{overwrite_vars: inventorySourceData.overwrite_vars},
|
||||||
|
{update_on_launch: inventorySourceData.update_on_launch},
|
||||||
|
{update_cache_timeout: inventorySourceData.update_cache_timeout},
|
||||||
|
{instance_filters: inventorySourceData.instance_filters},
|
||||||
|
{inventory_script: inventorySourceData.source_script},
|
||||||
|
{verbosity: inventorySourceData.verbosity});
|
||||||
|
|
||||||
|
$scope.inventory_source_obj = inventorySourceData;
|
||||||
|
if (inventorySourceData.credential) {
|
||||||
|
$scope.credential_name = inventorySourceData.summary_fields.credential.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(inventorySourceData.source === 'scm') {
|
||||||
|
$scope.project = inventorySourceData.source_project;
|
||||||
|
$scope.project_name = inventorySourceData.summary_fields.source_project.name;
|
||||||
|
updateSCMProject();
|
||||||
|
}
|
||||||
|
|
||||||
|
// display custom inventory_script name
|
||||||
|
if (inventorySourceData.source === 'custom' && inventorySourceData.summary_fields.source_script) {
|
||||||
|
$scope.inventory_script_name = inventorySourceData.summary_fields.source_script.name;
|
||||||
|
}
|
||||||
|
$scope = angular.extend($scope, inventorySourceData);
|
||||||
|
|
||||||
|
$scope.$watch('summary_fields.user_capabilities.edit', function(val) {
|
||||||
|
$scope.canAdd = val;
|
||||||
|
});
|
||||||
|
|
||||||
|
$scope.$on('sourceTypeOptionsReady', function() {
|
||||||
|
initSourceSelect();
|
||||||
|
});
|
||||||
|
|
||||||
|
$scope.envParseType = 'yaml';
|
||||||
|
|
||||||
|
initSources();
|
||||||
|
|
||||||
|
GetChoices({
|
||||||
|
scope: $scope,
|
||||||
|
field: 'verbosity',
|
||||||
|
variable: 'verbosity_options',
|
||||||
|
options: inventorySourcesOptions
|
||||||
|
});
|
||||||
|
|
||||||
|
var i;
|
||||||
|
for (i = 0; i < $scope.verbosity_options.length; i++) {
|
||||||
|
if ($scope.verbosity_options[i].value === $scope.verbosity) {
|
||||||
|
$scope.verbosity = $scope.verbosity_options[i];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(inventorySourceData.source === 'scm') {
|
initVerbositySelect();
|
||||||
$scope.project = inventorySourceData.source_project;
|
|
||||||
$scope.project_name = inventorySourceData.summary_fields.source_project.name;
|
$scope.$watch('verbosity', initVerbositySelect);
|
||||||
|
|
||||||
|
// Register a watcher on project_name
|
||||||
|
if ($scope.getInventoryFilesUnregister) {
|
||||||
|
$scope.getInventoryFilesUnregister();
|
||||||
|
}
|
||||||
|
$scope.getInventoryFilesUnregister = $scope.$watch('project', function (newValue, oldValue) {
|
||||||
|
if (newValue !== oldValue) {
|
||||||
updateSCMProject();
|
updateSCMProject();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
// display custom inventory_script name
|
|
||||||
if (inventorySourceData.source === 'custom' && inventorySourceData.summary_fields.source_script) {
|
|
||||||
$scope.inventory_script_name = inventorySourceData.summary_fields.source_script.name;
|
|
||||||
}
|
|
||||||
$scope = angular.extend($scope, inventorySourceData);
|
|
||||||
|
|
||||||
$scope.$watch('summary_fields.user_capabilities.edit', function(val) {
|
|
||||||
$scope.canAdd = val;
|
|
||||||
});
|
|
||||||
|
|
||||||
$scope.$on('sourceTypeOptionsReady', function() {
|
|
||||||
initSourceSelect();
|
|
||||||
});
|
|
||||||
|
|
||||||
$scope.envParseType = 'yaml';
|
|
||||||
|
|
||||||
initSources();
|
|
||||||
|
|
||||||
GetChoices({
|
|
||||||
scope: $scope,
|
|
||||||
field: 'verbosity',
|
|
||||||
variable: 'verbosity_options',
|
|
||||||
options: inventorySourcesOptions
|
|
||||||
});
|
|
||||||
|
|
||||||
var i;
|
|
||||||
for (i = 0; i < $scope.verbosity_options.length; i++) {
|
|
||||||
if ($scope.verbosity_options[i].value === $scope.verbosity) {
|
|
||||||
$scope.verbosity = $scope.verbosity_options[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
initVerbositySelect();
|
|
||||||
|
|
||||||
$scope.$watch('verbosity', initVerbositySelect);
|
|
||||||
|
|
||||||
// Register a watcher on project_name
|
|
||||||
if ($scope.getInventoryFilesUnregister) {
|
|
||||||
$scope.getInventoryFilesUnregister();
|
|
||||||
}
|
|
||||||
$scope.getInventoryFilesUnregister = $scope.$watch('project', function (newValue, oldValue) {
|
|
||||||
if (newValue !== oldValue) {
|
|
||||||
updateSCMProject();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function initVerbositySelect(){
|
function initVerbositySelect(){
|
||||||
CreateSelect2({
|
CreateSelect2({
|
||||||
@@ -366,9 +368,16 @@ export default ['$state', '$stateParams', '$scope', 'ParseVariableString',
|
|||||||
params.source = null;
|
params.source = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
SourcesService
|
inventorySource.request('put', {
|
||||||
.put(params)
|
data: params
|
||||||
.then(() => $state.go('.', null, { reload: true }));
|
}).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) {
|
$scope.sourceChange = function(source) {
|
||||||
@@ -419,7 +428,5 @@ export default ['$state', '$stateParams', '$scope', 'ParseVariableString',
|
|||||||
initRegionSelect();
|
initRegionSelect();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
init();
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
inventorySourceData: ['$stateParams', 'SourcesService', function($stateParams, SourcesService) {
|
inventorySource: ['InventorySourceModel', '$stateParams', (InventorySource, $stateParams) => {
|
||||||
return SourcesService.get({id: $stateParams.inventory_source_id }).then(response => response.data.results[0]);
|
return new InventorySource('get', $stateParams.inventory_source_id);
|
||||||
}],
|
}],
|
||||||
inventorySourcesOptions: ['InventoriesService', '$stateParams', function(InventoriesService, $stateParams) {
|
inventorySourcesOptions: ['InventoriesService', '$stateParams', function(InventoriesService, $stateParams) {
|
||||||
return InventoriesService.inventorySourcesOptions($stateParams.inventory_id)
|
return InventoriesService.inventorySourcesOptions($stateParams.inventory_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user