reference type ui fixes
This commit is contained in:
parent
4a538531f3
commit
d96a1c6763
|
@ -30,6 +30,7 @@ import { ReferenceTypeEditorModel } from './reference-type-editor.model';
|
|||
import { ReferenceTypeEditorResolver } from './reference-type-editor.resolver';
|
||||
import { ReferenceTypeEditorService } from './reference-type-editor.service';
|
||||
import { RouterUtilsService } from '@app/core/services/router/router-utils.service';
|
||||
import { StaticEditorModel, StaticOptionEditorModel } from '@app/ui/external-fetcher/external-fetcher-source-editor.model';
|
||||
|
||||
@Component({
|
||||
selector: 'app-reference-type-editor-component',
|
||||
|
@ -220,10 +221,22 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
|
|||
for (let i = 0; i < sourceFormArray.length; i++) {
|
||||
const fieldMappingFormArray = (sourceFormArray.at(i).get('results').get('fieldsMapping') as FormArray);
|
||||
for (let j = 0; j < fieldMappingFormArray.length; j++) {
|
||||
// remove code from fields mapping
|
||||
if (fieldCode == fieldMappingFormArray.at(j).get('code').getRawValue()) {
|
||||
this.removeFieldMapping(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
const staticFormArray = (this.formGroup.get('definition').get('sources') as FormArray).at(i).get('items') as FormArray;
|
||||
for (let k = 0; k < staticFormArray.length; k++) {
|
||||
const optionsFormArray = staticFormArray.at(k).get('options') as FormArray;
|
||||
for (let p = 0; p < optionsFormArray.length; p++) {
|
||||
// remove code from static options
|
||||
if (fieldCode == optionsFormArray.at(p).get('code').getRawValue()) {
|
||||
this.removeOption(i, k, p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -238,6 +251,10 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
|
|||
for (let j = 0; j < sourcesFormArray.length; j++) {
|
||||
for (let i = 0; i < fieldsFormArray.length; i++) {
|
||||
this.addFieldMapping(j, fieldsFormArray.at(i).get('code').value);
|
||||
const staticFormArray = (this.formGroup.get('definition').get('sources') as FormArray).at(j).get('items') as FormArray;
|
||||
for (let k = 0; k < staticFormArray.length; k++) {
|
||||
this.addOption(j, k, fieldsFormArray.at(i).get('code').value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -259,6 +276,7 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
|
|||
this.addFieldMapping(sourceIndex, fieldsFormArray.at(i).get('code').value);
|
||||
}
|
||||
}
|
||||
this.addStaticItem(sourceIndex);
|
||||
}
|
||||
|
||||
removeSource(sourceIndex: number): void {
|
||||
|
@ -304,7 +322,7 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
|
|||
validationErrorModel: this.editorModel.validationErrorModel
|
||||
}
|
||||
);
|
||||
(this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('fieldsMapping').markAsDirty();
|
||||
(this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('results').get('fieldsMapping').markAsDirty();
|
||||
|
||||
}
|
||||
|
||||
|
@ -348,5 +366,67 @@ export class ReferenceTypeEditorComponent extends BaseEditor<ReferenceTypeEditor
|
|||
});
|
||||
}
|
||||
|
||||
// static item
|
||||
|
||||
addStaticItem(sourceIndex: number): void {
|
||||
const formArray = (this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('items') as FormArray;
|
||||
const staticItem = new StaticEditorModel(this.editorModel.validationErrorModel);
|
||||
formArray.push(staticItem.buildForm({rootPath: 'definition.sources[' + sourceIndex + '].items[' + formArray.length + '].'}));
|
||||
|
||||
this.addOption(sourceIndex, formArray.length -1 , "reference_id");
|
||||
this.addOption(sourceIndex, formArray.length -1, "label");
|
||||
this.addOption(sourceIndex, formArray.length -1, "description");
|
||||
|
||||
const fieldsFormArray = (this.formGroup.get('definition').get('fields') as FormArray);
|
||||
if (fieldsFormArray && fieldsFormArray.length > 0) {
|
||||
for (let i = 0; i < fieldsFormArray.length; i++) {
|
||||
this.addOption(sourceIndex, formArray.length - 1, fieldsFormArray.at(i).get('code').value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
removeStaticItem(sourceIndex: number, staticIndex: number): void {
|
||||
const formArray = (this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('items') as FormArray;
|
||||
formArray.removeAt(staticIndex);
|
||||
|
||||
ReferenceTypeEditorModel.reApplyDefinitionSourcesValidators(
|
||||
{
|
||||
formGroup: this.formGroup,
|
||||
validationErrorModel: this.editorModel.validationErrorModel
|
||||
}
|
||||
);
|
||||
formArray.markAsDirty();
|
||||
}
|
||||
|
||||
|
||||
// Options
|
||||
|
||||
addOption(sourceIndex: number, staticIndex: number, code: string): void {
|
||||
const formArray = ((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('items') as FormArray).at(staticIndex).get('options') as FormArray;
|
||||
|
||||
if (formArray && formArray.length > 0) {
|
||||
for (let i = 0; i < formArray.length; i++) {
|
||||
if (formArray.at(i).get('code').getRawValue() == code) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const option = new StaticOptionEditorModel(this.editorModel.validationErrorModel);
|
||||
formArray.push(option.buildForm({rootPath: 'definition.sources[' + sourceIndex + 'items[' + staticIndex + '].options[' + formArray.length + '].'}));
|
||||
formArray.at(formArray.length -1 ).get('code').patchValue(code);
|
||||
}
|
||||
|
||||
removeOption(sourceIndex: number, staticIndex: number, optionIndex: number): void {
|
||||
const formArray = ((this.formGroup.get('definition').get('sources') as FormArray).at(sourceIndex).get('items') as FormArray).at(staticIndex).get('options') as FormArray;
|
||||
formArray.removeAt(optionIndex);
|
||||
|
||||
ReferenceTypeEditorModel.reApplyDefinitionSourcesValidators(
|
||||
{
|
||||
formGroup: this.formGroup,
|
||||
validationErrorModel: this.editorModel.validationErrorModel
|
||||
}
|
||||
);
|
||||
formArray.markAsDirty();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ export class ExternalFetcherSourceComponent extends BaseComponent implements OnI
|
|||
) { super(); }
|
||||
|
||||
ngOnInit() {
|
||||
if (this.referenceTypeSourceIndex != null && (this.formGroup.get('items') as FormArray).length == 0) this.addStaticItem();
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
|
|
Loading…
Reference in New Issue