2019-01-18 18:03:45 +01:00
|
|
|
import { Component, Input, OnInit } from '@angular/core';
|
|
|
|
import { FormArray, FormGroup } from '@angular/forms';
|
2019-01-21 12:14:20 +01:00
|
|
|
import { DatasetDescriptionCompositeFieldEditorModel, DatasetDescriptionFieldEditorModel } from '../../dataset-description-form.model';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { VisibilityRulesService } from '../../visibility-rules/visibility-rules.service';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-form-composite-field',
|
|
|
|
templateUrl: './form-composite-field.component.html',
|
|
|
|
styleUrls: ['./form-composite-field.component.scss']
|
|
|
|
})
|
|
|
|
export class FormCompositeFieldComponent implements OnInit {
|
|
|
|
|
2019-01-21 12:14:20 +01:00
|
|
|
@Input() compositeField: DatasetDescriptionCompositeFieldEditorModel;
|
2019-01-18 18:03:45 +01:00
|
|
|
form: FormGroup;
|
|
|
|
trackByFn = (index, item) => item ? item['id'] : null;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private visibilityRulesService: VisibilityRulesService,
|
|
|
|
//private markForConsiderationService: MarkForConsiderationService,
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
if (this.compositeField) {
|
|
|
|
this.form = this.visibilityRulesService.getFormGroup(this.compositeField.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
addMultipleField(fieldIndex: number) {
|
2019-01-21 12:14:20 +01:00
|
|
|
const field: DatasetDescriptionFieldEditorModel = this.compositeField.fields[fieldIndex].cloneForMultiplicity(fieldIndex, '');
|
2019-01-18 18:03:45 +01:00
|
|
|
this.compositeField.fields[fieldIndex].multiplicityItems.push(field);
|
|
|
|
(<FormArray>(this.form.get('fields').get('' + fieldIndex).get('multiplicityItems'))).push(field.buildForm());
|
|
|
|
}
|
|
|
|
|
|
|
|
// markForConsideration() {
|
|
|
|
// this.markForConsiderationService.markForConsideration(this.compositeField);
|
|
|
|
// }
|
|
|
|
}
|