argos/dmp-frontend/src/app/ui/external-fetcher/external-fetcher-source.com...

104 lines
4.0 KiB
TypeScript

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';
import { QueryCaseConfigEditorModel, QueryConfigEditorModel, StaticOptionEditorModel } from './external-fetcher-source-editor.model';
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() {
console.log(this.referenceTypeSourceIndex);
}
//
//
// 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);
formArray.removeAt(queryIndex);
}
// 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);
}
// 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);
}
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);
}
}