2019-01-18 18:03:45 +01:00
|
|
|
import { AfterViewInit, Component, Input, OnInit } from '@angular/core';
|
|
|
|
import { FormArray, FormGroup } from '@angular/forms';
|
|
|
|
import { CompositeField } from '../../../../../core/model/dataset-profile-definition/composite-field';
|
2019-01-21 12:14:20 +01:00
|
|
|
import { DatasetDescriptionCompositeFieldEditorModel, DatasetDescriptionSectionEditorModel } from '../../dataset-description-form.model';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { FormFocusService } from '../../form-focus/form-focus.service';
|
|
|
|
import { VisibilityRulesService } from '../../visibility-rules/visibility-rules.service';
|
2018-01-05 18:02:26 +01:00
|
|
|
|
2017-11-23 11:40:02 +01:00
|
|
|
@Component({
|
2019-01-18 18:03:45 +01:00
|
|
|
selector: 'app-form-section',
|
|
|
|
templateUrl: './form-section.component.html',
|
|
|
|
styleUrls: ['./form-section.component.scss']
|
2017-12-06 11:35:50 +01:00
|
|
|
})
|
2019-01-18 18:03:45 +01:00
|
|
|
export class FormSectionComponent implements OnInit, AfterViewInit {
|
2017-11-23 11:40:02 +01:00
|
|
|
|
2019-01-21 12:14:20 +01:00
|
|
|
@Input() section: DatasetDescriptionSectionEditorModel;
|
2018-10-05 17:00:54 +02:00
|
|
|
form: FormGroup;
|
|
|
|
@Input() pathName: string;
|
|
|
|
@Input() path: string;
|
|
|
|
trackByFn = (index, item) => item ? item['id'] : null;
|
2018-11-01 17:02:15 +01:00
|
|
|
constructor(
|
2019-01-18 18:03:45 +01:00
|
|
|
private visibilityRulesService: VisibilityRulesService,
|
2018-11-01 17:02:15 +01:00
|
|
|
private formFocusService: FormFocusService
|
|
|
|
) { }
|
2017-11-23 11:40:02 +01:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
ngOnInit() {
|
|
|
|
if (this.section) {
|
|
|
|
this.form = this.visibilityRulesService.getFormGroup(this.section.id);
|
|
|
|
}
|
|
|
|
}
|
2018-09-18 14:41:24 +02:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
ngAfterViewInit() {
|
|
|
|
this.visibilityRulesService.triggerVisibilityEvaluation();
|
|
|
|
}
|
2018-01-05 18:02:26 +01:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
addMultipleField(fieldsetIndex: number) {
|
2019-01-21 12:14:20 +01:00
|
|
|
const compositeField: DatasetDescriptionCompositeFieldEditorModel = this.section.compositeFields[fieldsetIndex].cloneForMultiplicity(fieldsetIndex);
|
2018-10-05 17:00:54 +02:00
|
|
|
this.section.compositeFields[fieldsetIndex].multiplicityItems.push(compositeField);
|
|
|
|
(<FormArray>(this.form.get('compositeFields').get('' + fieldsetIndex).get('multiplicityItems'))).push(compositeField.buildForm());
|
|
|
|
}
|
2018-01-05 18:02:26 +01:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
isElementVisible(fieldSet: CompositeField): boolean {
|
|
|
|
if (!fieldSet) { return false; }
|
|
|
|
for (let i = 0; i < fieldSet.fields.length; i++) {
|
|
|
|
if (fieldSet.fields[i]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2018-11-01 17:02:15 +01:00
|
|
|
|
|
|
|
next(compositeField: CompositeField) {
|
|
|
|
this.formFocusService.focusNext(compositeField);
|
|
|
|
}
|
2018-05-28 11:50:42 +02:00
|
|
|
}
|