2024-02-26 18:40:31 +01:00
|
|
|
import { Component, Input, OnInit } 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';
|
|
|
|
import { ReferenceType } from '@app/core/model/reference-type/reference-type';
|
|
|
|
import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
|
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
|
|
|
import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model';
|
2024-02-27 15:27:26 +01:00
|
|
|
import { ExternalFetcherBaseSourceConfigurationEditorModel, QueryCaseConfigEditorModel, QueryConfigEditorModel, StaticOptionEditorModel } from './external-fetcher-source-editor.model';
|
2024-02-26 18:40:31 +01:00
|
|
|
import { Guid } from '@common/types/guid';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-external-fetcher-source-component',
|
|
|
|
templateUrl: 'external-fetcher-source.component.html',
|
|
|
|
styleUrls: ['./external-fetcher-source.component.scss']
|
|
|
|
})
|
|
|
|
export class ExternalFetcherSourceComponent extends BaseComponent implements OnInit {
|
|
|
|
|
|
|
|
@Input() formGroup: UntypedFormGroup = null;
|
|
|
|
@Input() validationErrorModel: ValidationErrorModel = null;
|
|
|
|
@Input() validationRootPath: string = null;
|
|
|
|
@Input() referenceTypeSourceIndex: number = null;
|
|
|
|
@Input() referenceTypes: ReferenceType[] = null;
|
|
|
|
@Input() sourceKeysMap: Map<Guid, string[]> = new Map<Guid, string[]>();
|
|
|
|
|
|
|
|
externalFetcherSourceType = ExternalFetcherSourceType;
|
|
|
|
externalFetcherApiHTTPMethodType = ExternalFetcherApiHTTPMethodType;
|
|
|
|
externalFetcherSourceTypeEnum = this.enumUtils.getEnumValues<ExternalFetcherSourceType>(ExternalFetcherSourceType);
|
|
|
|
externalFetcherApiHTTPMethodTypeEnum = this.enumUtils.getEnumValues<ExternalFetcherApiHTTPMethodType>(ExternalFetcherApiHTTPMethodType);
|
|
|
|
referenceTypeDependenciesMap: Map<number, ReferenceType[]> = new Map<number, ReferenceType[]>();
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
public enumUtils: EnumUtils,
|
|
|
|
) { super(); }
|
|
|
|
|
|
|
|
ngOnInit() {
|
2024-02-27 15:27:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private reApplyValidators(){
|
|
|
|
ExternalFetcherBaseSourceConfigurationEditorModel.reapplyValidators(
|
|
|
|
{
|
|
|
|
formGroup: this.formGroup,
|
|
|
|
validationErrorModel: this.validationErrorModel,
|
|
|
|
rootPath: this.validationRootPath
|
|
|
|
}
|
|
|
|
)
|
2024-02-26 18:40:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// queries
|
|
|
|
//
|
|
|
|
//
|
|
|
|
addQuery(): void {
|
|
|
|
const formArray= this.formGroup.get('queries') as FormArray;
|
|
|
|
const query: QueryConfigEditorModel = new QueryConfigEditorModel(this.validationErrorModel);
|
|
|
|
formArray.push(query.buildForm({rootPath: this.validationRootPath + 'queries[' + formArray.length + '].'}));
|
|
|
|
}
|
|
|
|
|
|
|
|
removeQuery(queryIndex: number): void {
|
|
|
|
const formArray = (this.formGroup.get('queries') as FormArray);
|
2024-02-27 15:27:26 +01:00
|
|
|
formArray.removeAt(queryIndex);
|
|
|
|
this.reApplyValidators();
|
|
|
|
formArray.markAsDirty();
|
2024-02-26 18:40:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// cases
|
|
|
|
|
|
|
|
addCase(queryIndex: number): void {
|
|
|
|
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);
|
2024-02-27 15:27:26 +01:00
|
|
|
this.reApplyValidators();
|
|
|
|
formArray.markAsDirty();
|
2024-02-26 18:40:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Options
|
|
|
|
|
|
|
|
addOption(code: string): void {
|
|
|
|
const optionsSize = (this.formGroup.get('options') as FormArray).length;
|
|
|
|
|
|
|
|
if (optionsSize > 0) {
|
|
|
|
for (let i = 0; i < optionsSize; i++) {
|
|
|
|
if ((this.formGroup.get('options') as FormArray).at(i).get('code').getRawValue() == code) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const option = new StaticOptionEditorModel(this.validationErrorModel);
|
|
|
|
(this.formGroup.get('options') as FormArray).push(option.buildForm());
|
|
|
|
(this.formGroup.get('options') as FormArray).at(optionsSize).get('code').patchValue(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
removeOption(optionIndex: number): void {
|
|
|
|
const formArray = (this.formGroup.get('options') as FormArray);
|
|
|
|
formArray.removeAt(optionIndex);
|
2024-02-27 15:27:26 +01:00
|
|
|
this.reApplyValidators();
|
|
|
|
formArray.markAsDirty();
|
2024-02-26 18:40:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
setReferenceTypeDependenciesMap(ids: Guid[], index: number){
|
|
|
|
let mapValues :ReferenceType[] = [];
|
|
|
|
this.referenceTypes.forEach(x => {
|
|
|
|
if(ids.includes(x.id)){
|
|
|
|
mapValues.push(x);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
this.referenceTypeDependenciesMap.set(index, mapValues);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|