2019-01-18 18:03:45 +01:00
|
|
|
import { Component, Input, OnInit } from '@angular/core';
|
2020-02-03 16:50:18 +01:00
|
|
|
import { FormArray, FormGroup, AbstractControl } from '@angular/forms';
|
2019-01-21 12:14:20 +01:00
|
|
|
import { DatasetDescriptionCompositeFieldEditorModel, DatasetDescriptionFieldEditorModel } from '../../dataset-description-form.model';
|
2021-03-09 09:04:50 +01:00
|
|
|
import { ToCEntry } from '../../dataset-description.component';
|
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']
|
|
|
|
})
|
2019-01-28 14:47:31 +01:00
|
|
|
export class FormCompositeFieldComponent {
|
2019-01-18 18:03:45 +01:00
|
|
|
|
2019-01-29 08:47:50 +01:00
|
|
|
@Input() datasetProfileId: String;
|
2019-01-28 14:47:31 +01:00
|
|
|
@Input() form: FormGroup;
|
2019-10-15 16:25:43 +02:00
|
|
|
@Input() isChild: Boolean = false;
|
2020-02-03 16:50:18 +01:00
|
|
|
@Input() showDelete: Boolean = false;
|
2021-03-09 09:04:50 +01:00
|
|
|
@Input() tocentry: ToCEntry;
|
2019-01-18 18:03:45 +01:00
|
|
|
|
|
|
|
constructor(
|
2019-01-28 14:47:31 +01:00
|
|
|
public visibilityRulesService: VisibilityRulesService,
|
2019-01-18 18:03:45 +01:00
|
|
|
//private markForConsiderationService: MarkForConsiderationService,
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
2019-01-31 11:29:35 +01:00
|
|
|
ngOnInit() {
|
2021-03-09 09:04:50 +01:00
|
|
|
|
|
|
|
if(this.tocentry){
|
|
|
|
this.form = this.tocentry.form as FormGroup;
|
|
|
|
}
|
2019-01-31 11:29:35 +01:00
|
|
|
}
|
2019-01-18 18:03:45 +01:00
|
|
|
|
2019-02-04 14:41:54 +01:00
|
|
|
// addMultipleField(fieldIndex: number) {
|
|
|
|
// const compositeFieldToBeCloned = (this.form.get('compositeFields').get('' + fieldIndex) as FormGroup).getRawValue();
|
|
|
|
// const compositeField: DatasetDescriptionCompositeFieldEditorModel = new DatasetDescriptionCompositeFieldEditorModel().cloneForMultiplicity(compositeFieldToBeCloned);
|
|
|
|
// (<FormArray>(this.form.get('compositeFields').get('' + fieldIndex).get('multiplicityItems'))).push(compositeField.buildForm());
|
|
|
|
// }
|
2019-01-18 18:03:45 +01:00
|
|
|
|
|
|
|
// markForConsideration() {
|
|
|
|
// this.markForConsiderationService.markForConsideration(this.compositeField);
|
|
|
|
// }
|
2020-02-03 16:50:18 +01:00
|
|
|
|
|
|
|
deleteCompositeField() {
|
|
|
|
if (this.isChild) {
|
|
|
|
this.deleteMultipeFieldFromCompositeFormGroup();
|
|
|
|
} else {
|
|
|
|
this.deleteCompositeFieldFormGroup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteCompositeFieldFormGroup() {
|
|
|
|
const numberOfItems = this.form.get('multiplicityItems').get('' + 0).get('fields').value.length;
|
|
|
|
for (let i = 0; i < numberOfItems; i++) {
|
|
|
|
const multiplicityItem = this.form.get('multiplicityItems').get('' + 0).get('fields').get('' + i).value;
|
|
|
|
this.form.get('fields').get('' + i).patchValue(multiplicityItem);
|
|
|
|
}
|
|
|
|
(<FormArray>(this.form.get('multiplicityItems'))).removeAt(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteMultipeFieldFromCompositeFormGroup() {
|
|
|
|
const parent = this.form.parent;
|
|
|
|
const index = (parent as FormArray).controls.indexOf(this.form);
|
|
|
|
(parent as FormArray).removeAt(index);
|
|
|
|
// (<FormArray>(this.form as AbstractControl)).removeAt(fildIndex);
|
|
|
|
}
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|