reference type editor bug fix

This commit is contained in:
Efstratios Giannopoulos 2024-04-17 17:41:15 +03:00
parent c28c700eff
commit aaac7dfdf4
1 changed files with 18 additions and 8 deletions

View File

@ -1,4 +1,4 @@
import { Component, Input, OnInit } from '@angular/core'; import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';
import { FormArray, UntypedFormGroup } from '@angular/forms'; import { FormArray, UntypedFormGroup } from '@angular/forms';
import { ExternalFetcherApiHTTPMethodType } from '@app/core/common/enum/external-fetcher-api-http-method-type'; import { ExternalFetcherApiHTTPMethodType } from '@app/core/common/enum/external-fetcher-api-http-method-type';
import { ExternalFetcherSourceType } from '@app/core/common/enum/external-fetcher-source-type'; import { ExternalFetcherSourceType } from '@app/core/common/enum/external-fetcher-source-type';
@ -14,7 +14,7 @@ import { Guid } from '@common/types/guid';
templateUrl: 'external-fetcher-source.component.html', templateUrl: 'external-fetcher-source.component.html',
styleUrls: ['./external-fetcher-source.component.scss'] styleUrls: ['./external-fetcher-source.component.scss']
}) })
export class ExternalFetcherSourceComponent extends BaseComponent implements OnInit { export class ExternalFetcherSourceComponent extends BaseComponent implements OnInit, OnChanges {
@Input() formGroup: UntypedFormGroup = null; @Input() formGroup: UntypedFormGroup = null;
@Input() fieldsForm: any; @Input() fieldsForm: any;
@ -38,6 +38,16 @@ export class ExternalFetcherSourceComponent extends BaseComponent implements OnI
if (this.referenceTypeSourceIndex != null && (this.formGroup.get('items') as FormArray).length == 0) this.addStaticItem(); if (this.referenceTypeSourceIndex != null && (this.formGroup.get('items') as FormArray).length == 0) this.addStaticItem();
} }
ngOnChanges(changes: SimpleChanges) {
if (changes['referenceTypes'] || changes['formGroup']) {
if (this.referenceTypes != null && this.referenceTypes.length > 0) {
const referenceTypeDependencyIds: Guid[] = this.formGroup.get('referenceTypeDependencyIds')?.value;
if (referenceTypeDependencyIds && referenceTypeDependencyIds.length > 0 && this.referenceTypeSourceIndex != null) this.setReferenceTypeDependenciesMap(referenceTypeDependencyIds, this.referenceTypeSourceIndex);
}
}
}
private reApplyValidators(){ private reApplyValidators(){
ExternalFetcherBaseSourceConfigurationEditorModel.reapplyValidators( ExternalFetcherBaseSourceConfigurationEditorModel.reapplyValidators(
{ {
@ -61,8 +71,8 @@ export class ExternalFetcherSourceComponent extends BaseComponent implements OnI
removeQuery(queryIndex: number): void { removeQuery(queryIndex: number): void {
const formArray = (this.formGroup.get('queries') as FormArray); const formArray = (this.formGroup.get('queries') as FormArray);
formArray.removeAt(queryIndex); formArray.removeAt(queryIndex);
this.reApplyValidators(); this.reApplyValidators();
formArray.markAsDirty(); formArray.markAsDirty();
} }
@ -72,13 +82,13 @@ export class ExternalFetcherSourceComponent extends BaseComponent implements OnI
const formArray = (this.formGroup.get('queries') as FormArray).at(queryIndex).get('cases') as FormArray; const formArray = (this.formGroup.get('queries') as FormArray).at(queryIndex).get('cases') as FormArray;
const queryCase: QueryCaseConfigEditorModel = new QueryCaseConfigEditorModel(this.validationErrorModel); const queryCase: QueryCaseConfigEditorModel = new QueryCaseConfigEditorModel(this.validationErrorModel);
formArray.push(queryCase.buildForm({rootPath: this.validationRootPath + 'queries[' + queryIndex + '].cases[' + formArray.length + '].'})); formArray.push(queryCase.buildForm({rootPath: this.validationRootPath + 'queries[' + queryIndex + '].cases[' + formArray.length + '].'}));
} }
removeCase(queryIndex: number, index: number): void { removeCase(queryIndex: number, index: number): void {
const formArray = (this.formGroup.get('queries') as FormArray).at(queryIndex).get('cases') as FormArray; const formArray = (this.formGroup.get('queries') as FormArray).at(queryIndex).get('cases') as FormArray;
formArray.removeAt(index); formArray.removeAt(index);
this.reApplyValidators(); this.reApplyValidators();
formArray.markAsDirty(); formArray.markAsDirty();
} }
@ -104,7 +114,7 @@ export class ExternalFetcherSourceComponent extends BaseComponent implements OnI
removeStaticItem(staticIndex: number): void { removeStaticItem(staticIndex: number): void {
const formArray = this.formGroup.get('items') as FormArray; const formArray = this.formGroup.get('items') as FormArray;
formArray.removeAt(staticIndex); formArray.removeAt(staticIndex);
this.reApplyValidators(); this.reApplyValidators();
formArray.markAsDirty(); formArray.markAsDirty();
} }
@ -129,7 +139,7 @@ export class ExternalFetcherSourceComponent extends BaseComponent implements OnI
removeOption(staticIndex: number, optionIndex: number): void { removeOption(staticIndex: number, optionIndex: number): void {
const formArray = (this.formGroup.get('items') as FormArray).at(staticIndex).get('options') as FormArray; const formArray = (this.formGroup.get('items') as FormArray).at(staticIndex).get('options') as FormArray;
formArray.removeAt(optionIndex); formArray.removeAt(optionIndex);
this.reApplyValidators(); this.reApplyValidators();
formArray.markAsDirty(); formArray.markAsDirty();
} }