argos/dmp-frontend/src/app/ui/admin/description-template/editor/components/field-type/external-select/description-template-editor...

47 lines
2.3 KiB
TypeScript

import { Component, Input, OnInit } from '@angular/core';
import { UntypedFormArray, UntypedFormGroup } from '@angular/forms';
import { DescriptionTemplateExternalSelectDataEditorModel, DescriptionTemplateExternalSelectSourceEditorModel } from '../../../description-template-editor.model';
import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
import { DescriptionTemplateExternalSelectHttpMethodType } from '@app/core/common/enum/description-template-external-select-http-method-type';
import { DescriptionTemplateExternalSelectAuthType } from '@app/core/common/enum/description-template-external-select-auth-type';
import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model';
@Component({
selector: 'app-description-template-editor-external-select-field-component',
styleUrls: ['./description-template-editor-external-select-field.component.scss'],
templateUrl: './description-template-editor-external-select-field.component.html'
})
export class DescriptionTemplateEditorExternalSelectFieldComponent implements OnInit {
@Input() form: UntypedFormGroup;
@Input() validationErrorModel: ValidationErrorModel;
@Input() rootPath: string;
methodTypeValues = this.enumUtils.getEnumValues<DescriptionTemplateExternalSelectHttpMethodType>(DescriptionTemplateExternalSelectHttpMethodType);
authTypeValues = this.enumUtils.getEnumValues<DescriptionTemplateExternalSelectAuthType>(DescriptionTemplateExternalSelectAuthType);
constructor (
public enumUtils: EnumUtils
) {}
ngOnInit() {
}
addSource() {
const externalDataset = new DescriptionTemplateExternalSelectSourceEditorModel(this.validationErrorModel);
const externalSelectArray = this.form.get('data').get('sources') as UntypedFormArray;
externalSelectArray.push(externalDataset.buildForm({rootPath: this.rootPath + 'data.sources[' + externalSelectArray.length + '].'}));
}
removeSource(index: number) {
(<UntypedFormArray>this.form.get('data').get('sources')).removeAt(index);
DescriptionTemplateExternalSelectDataEditorModel.reapplyValidators({
formGroup: this.form?.get('data') as UntypedFormGroup,
rootPath: `${this.rootPath}data.`,
validationErrorModel: this.validationErrorModel
});
this.form.get('data').get('sources').markAsDirty();
}
}