import { Component, Input, OnInit } from '@angular/core'; import { FormArray, FormControl, FormGroup } from '@angular/forms'; import { takeUntil } from 'rxjs/operators'; import { BaseComponent } from '../../../../../../core/common/base/base.component'; import { DatasetProfileFieldViewStyle } from '../../../../../../core/common/enum/dataset-profile-field-view-style'; import { ValidationType } from '../../../../../../core/common/enum/validation-type'; import { EnumUtils } from '../../../../../../core/services/utilities/enum-utils.service'; import { BooleanDecisionFieldDataEditorModel } from '../../../admin/field-data/boolean-decision-field-data-editor-model'; import { CheckBoxFieldDataEditorModel } from '../../../admin/field-data/check-box-field-data-editor-model'; import { FreeTextFieldDataEditorModel } from '../../../admin/field-data/free-text-field-data-editor-model'; import { RadioBoxFieldDataEditorModel } from '../../../admin/field-data/radio-box-field-data-editor-model'; import { TextAreaFieldDataEditorModel } from '../../../admin/field-data/text-area-field-data-editor-model'; import { WordListFieldDataEditorModel } from '../../../admin/field-data/word-list-field-data-editor-model'; import { RuleEditorModel } from '../../../admin/rule-editor-model'; @Component({ selector: 'app-dataset-profile-editor-field-component', templateUrl: './dataset-profile-editor-field.component.html', styleUrls: ['./dataset-profile-editor-field.component.scss'] }) export class DatasetProfileEditorFieldComponent extends BaseComponent implements OnInit { @Input() form: FormGroup; @Input() showOrdinal = true; @Input() indexPath: string; validationTypeEnum = ValidationType; viewStyleEnum = DatasetProfileFieldViewStyle; isFieldMultiplicityEnabled = false; constructor( public enumUtils: EnumUtils ) { super(); } ngOnInit() { if (this.form.get('multiplicity')) { if (this.form.get('multiplicity').value.min > 1 && this.form.get('multiplicity').value.max > 1) { this.isFieldMultiplicityEnabled = true; } } // this.addNewRule(); this.form.get('viewStyle').get('renderStyle').valueChanges .pipe(takeUntil(this._destroyed)) .subscribe(x => { if (this.form.get('data')) { this.form.removeControl('data'); switch (x) { case DatasetProfileFieldViewStyle.BooleanDecision: this.form.addControl('data', new BooleanDecisionFieldDataEditorModel().buildForm()); break; case DatasetProfileFieldViewStyle.CheckBox: this.form.addControl('data', new CheckBoxFieldDataEditorModel().buildForm()); break; case DatasetProfileFieldViewStyle.ComboBox: this.form.addControl('data', new WordListFieldDataEditorModel().buildForm()); break; case DatasetProfileFieldViewStyle.FreeText: this.form.addControl('data', new FreeTextFieldDataEditorModel().buildForm()); break; case DatasetProfileFieldViewStyle.RadioBox: this.form.addControl('data', new RadioBoxFieldDataEditorModel().buildForm()); break; case DatasetProfileFieldViewStyle.TextArea: this.form.addControl('data', new TextAreaFieldDataEditorModel().buildForm()); break; } } }); } onIsFieldMultiplicityEnabledChange(isFieldMultiplicityEnabled: boolean) { if (!isFieldMultiplicityEnabled) { (this.form.get('multiplicity').get('min')).setValue(0); (this.form.get('multiplicity').get('max')).setValue(0); } } addNewRule() { const rule: RuleEditorModel = new RuleEditorModel(); (this.form.get('visible').get('rules')).push(rule.buildForm()); } }