mirror of
https://github.com/ansible/awx.git
synced 2026-01-17 04:31:21 -03:30
move input value initialization to models
This commit is contained in:
parent
ceef7f57af
commit
7f55a1da0d
@ -58,36 +58,19 @@ function AddCredentialsController (
|
||||
|
||||
vm.form.inputs = {
|
||||
_get: ({ getSubmitData }) => {
|
||||
credentialType.mergeInputProperties();
|
||||
const apiConfig = ConfigService.get();
|
||||
|
||||
let fields = credentialType.get('inputs.fields');
|
||||
credentialType.mergeInputProperties();
|
||||
const fields = credential.assignInputGroupValues(apiConfig, credentialType);
|
||||
|
||||
if (credentialType.get('name') === 'Google Compute Engine') {
|
||||
fields.splice(2, 0, gceFileInputSchema);
|
||||
$scope.$watch(`vm.form.${gceFileInputSchema.id}._value`, vm.gceOnFileInputChanged);
|
||||
} else if (credentialType.get('name') === 'Machine') {
|
||||
const apiConfig = ConfigService.get();
|
||||
const become = fields.find((field) => field.id === 'become_method');
|
||||
become._isDynamic = true;
|
||||
become._choices = Array.from(apiConfig.become_methods, method => method[0]);
|
||||
}
|
||||
vm.isTestable = (credentialType.get('kind') === 'external');
|
||||
|
||||
vm.getSubmitData = getSubmitData;
|
||||
|
||||
vm.isTestable = credentialType.get('kind') === 'external';
|
||||
vm.inputSources.items = [];
|
||||
const linkedFieldNames = vm.inputSources.items
|
||||
.map(({ input_field_name }) => input_field_name);
|
||||
|
||||
fields = fields.map((field) => {
|
||||
field.tagMode = credentialType.get('kind') !== 'external';
|
||||
if (linkedFieldNames.includes(field.id)) {
|
||||
field.asTag = true;
|
||||
const { summary_fields } = vm.inputSources.items
|
||||
.find(({ input_field_name }) => input_field_name === field.id);
|
||||
field._value = summary_fields.source_credential.name;
|
||||
}
|
||||
return field;
|
||||
});
|
||||
|
||||
return fields;
|
||||
},
|
||||
|
||||
@ -110,59 +110,24 @@ function EditCredentialsController (
|
||||
|
||||
vm.form.inputs = {
|
||||
_get ({ getSubmitData }) {
|
||||
let fields;
|
||||
const apiConfig = ConfigService.get();
|
||||
|
||||
credentialType.mergeInputProperties();
|
||||
|
||||
if (credentialType.get('id') === credential.get('credential_type')) {
|
||||
fields = credential.assignInputGroupValues(credentialType.get('inputs.fields'));
|
||||
} else {
|
||||
fields = credentialType.get('inputs.fields');
|
||||
}
|
||||
const fields = credential.assignInputGroupValues(apiConfig, credentialType);
|
||||
|
||||
if (credentialType.get('name') === 'Google Compute Engine') {
|
||||
fields.splice(2, 0, gceFileInputSchema);
|
||||
|
||||
$scope.$watch(`vm.form.${gceFileInputSchema.id}._value`, vm.gceOnFileInputChanged);
|
||||
$scope.$watch('vm.form.ssh_key_data._isBeingReplaced', vm.gceOnReplaceKeyChanged);
|
||||
} else if (credentialType.get('name') === 'Machine') {
|
||||
const apiConfig = ConfigService.get();
|
||||
const become = fields.find((field) => field.id === 'become_method');
|
||||
become._isDynamic = true;
|
||||
become._choices = Array.from(apiConfig.become_methods, method => method[0]);
|
||||
// Add the value to the choices if it doesn't exist in the preset list
|
||||
if (become._value && become._value !== '') {
|
||||
const optionMatches = become._choices
|
||||
.findIndex((option) => option === become._value);
|
||||
if (optionMatches === -1) {
|
||||
become._choices.push(become._value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vm.isTestable = (isEditable && credentialType.get('kind') === 'external');
|
||||
vm.getSubmitData = getSubmitData;
|
||||
|
||||
vm.inputSources.initialItems = credential.get('related.input_sources.results');
|
||||
if (credential.get('credential_type') !== credentialType.get('id')) {
|
||||
vm.inputSources.items = [];
|
||||
} else {
|
||||
vm.inputSources.items = [];
|
||||
if (credential.get('credential_type') === credentialType.get('id')) {
|
||||
vm.inputSources.items = credential.get('related.input_sources.results');
|
||||
}
|
||||
|
||||
const linkedFieldNames = vm.inputSources.items
|
||||
.map(({ input_field_name }) => input_field_name);
|
||||
|
||||
fields = fields.map((field) => {
|
||||
field.tagMode = isEditable && credentialType.get('kind') !== 'external';
|
||||
if (linkedFieldNames.includes(field.id)) {
|
||||
field.asTag = true;
|
||||
const { summary_fields } = vm.inputSources.items
|
||||
.find(({ input_field_name }) => input_field_name === field.id);
|
||||
field._value = summary_fields.source_credential.name;
|
||||
}
|
||||
return field;
|
||||
});
|
||||
vm.isTestable = (isEditable && credentialType.get('kind') === 'external');
|
||||
vm.getSubmitData = getSubmitData;
|
||||
|
||||
return fields;
|
||||
},
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* eslint camelcase: 0 */
|
||||
const ENCRYPTED_VALUE = '$encrypted$';
|
||||
|
||||
let Base;
|
||||
@ -29,12 +30,23 @@ function createFormSchema (method, config) {
|
||||
return schema;
|
||||
}
|
||||
|
||||
function assignInputGroupValues (inputs) {
|
||||
function assignInputGroupValues (apiConfig, credentialType) {
|
||||
let inputs = credentialType.get('inputs.fields');
|
||||
|
||||
if (!inputs) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return inputs.map(input => {
|
||||
if (this.has('credential_type')) {
|
||||
if (credentialType.get('id') !== this.get('credential_type')) {
|
||||
inputs.forEach(field => {
|
||||
field.tagMode = this.isEditable() && credentialType.get('kind') !== 'external';
|
||||
});
|
||||
return inputs;
|
||||
}
|
||||
}
|
||||
|
||||
inputs = inputs.map(input => {
|
||||
const value = this.get(`inputs.${input.id}`);
|
||||
|
||||
input._value = value;
|
||||
@ -42,6 +54,36 @@ function assignInputGroupValues (inputs) {
|
||||
|
||||
return input;
|
||||
});
|
||||
|
||||
if (credentialType.get('name') === 'Machine') {
|
||||
const become = inputs.find((field) => field.id === 'become_method');
|
||||
become._isDynamic = true;
|
||||
become._choices = Array.from(apiConfig.become_methods, method => method[0]);
|
||||
// Add the value to the choices if it doesn't exist in the preset list
|
||||
if (become._value && become._value !== '') {
|
||||
const optionMatches = become._choices
|
||||
.findIndex((option) => option === become._value);
|
||||
if (optionMatches === -1) {
|
||||
become._choices.push(become._value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const linkedFieldNames = (this.get('related.input_sources.results') || [])
|
||||
.map(({ input_field_name }) => input_field_name);
|
||||
|
||||
inputs = inputs.map((field) => {
|
||||
field.tagMode = this.isEditable() && credentialType.get('kind') !== 'external';
|
||||
if (linkedFieldNames.includes(field.id)) {
|
||||
field.asTag = true;
|
||||
const { summary_fields } = this.get('related.input_sources.results')
|
||||
.find(({ input_field_name }) => input_field_name === field.id);
|
||||
field._value = summary_fields.source_credential.name;
|
||||
}
|
||||
return field;
|
||||
});
|
||||
|
||||
return inputs;
|
||||
}
|
||||
|
||||
function setDependentResources (id) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user