diff --git a/dmp-frontend/src/app/ui/external-fetcher/external-fetcher-source.component.ts b/dmp-frontend/src/app/ui/external-fetcher/external-fetcher-source.component.ts index d9fd4359c..0dbca5dc3 100644 --- a/dmp-frontend/src/app/ui/external-fetcher/external-fetcher-source.component.ts +++ b/dmp-frontend/src/app/ui/external-fetcher/external-fetcher-source.component.ts @@ -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 { ExternalFetcherApiHTTPMethodType } from '@app/core/common/enum/external-fetcher-api-http-method-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', 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() 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(); } + 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(){ ExternalFetcherBaseSourceConfigurationEditorModel.reapplyValidators( { @@ -61,8 +71,8 @@ export class ExternalFetcherSourceComponent extends BaseComponent implements OnI removeQuery(queryIndex: number): void { const formArray = (this.formGroup.get('queries') as FormArray); - formArray.removeAt(queryIndex); - this.reApplyValidators(); + formArray.removeAt(queryIndex); + this.reApplyValidators(); 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 queryCase: QueryCaseConfigEditorModel = new QueryCaseConfigEditorModel(this.validationErrorModel); formArray.push(queryCase.buildForm({rootPath: this.validationRootPath + 'queries[' + queryIndex + '].cases[' + formArray.length + '].'})); - + } removeCase(queryIndex: number, index: number): void { const formArray = (this.formGroup.get('queries') as FormArray).at(queryIndex).get('cases') as FormArray; formArray.removeAt(index); - this.reApplyValidators(); + this.reApplyValidators(); formArray.markAsDirty(); } @@ -104,7 +114,7 @@ export class ExternalFetcherSourceComponent extends BaseComponent implements OnI removeStaticItem(staticIndex: number): void { const formArray = this.formGroup.get('items') as FormArray; formArray.removeAt(staticIndex); - this.reApplyValidators(); + this.reApplyValidators(); formArray.markAsDirty(); } @@ -129,7 +139,7 @@ export class ExternalFetcherSourceComponent extends BaseComponent implements OnI removeOption(staticIndex: number, optionIndex: number): void { const formArray = (this.formGroup.get('items') as FormArray).at(staticIndex).get('options') as FormArray; formArray.removeAt(optionIndex); - this.reApplyValidators(); + this.reApplyValidators(); formArray.markAsDirty(); }