2018-10-05 17:00:54 +02:00
|
|
|
import { Component, ViewEncapsulation, AfterViewInit, Input, OnInit, OnDestroy } from '@angular/core';
|
|
|
|
import { DataManagementPlanProfile } from '../../../models/data-management-plan-profile/DataManagementPlanProfile';
|
|
|
|
import { DMPProfileFieldDataType, DMPProfileType } from '../../../models/data-management-plan-profile/DataManagementProfileField';
|
|
|
|
import { FormGroup, FormBuilder, FormArray } from '@angular/forms';
|
|
|
|
import { LanguageResolverService } from '../../../services/language-resolver/language-resolver.service';
|
2018-03-28 15:24:47 +02:00
|
|
|
|
|
|
|
@Component({
|
2018-10-05 17:00:54 +02:00
|
|
|
selector: 'app-dynamic-dmp-field-resolver',
|
|
|
|
templateUrl: 'dynamic-dmp-field-resolver.component.html',
|
|
|
|
styleUrls: ['./dynamic-dmp-field-resolver.component.scss'],
|
|
|
|
encapsulation: ViewEncapsulation.None
|
2018-03-28 15:24:47 +02:00
|
|
|
})
|
2018-10-05 17:00:54 +02:00
|
|
|
export class DynamicDmpFieldResolverComponent implements OnInit, OnDestroy {
|
2018-03-28 15:24:47 +02:00
|
|
|
|
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
DMPProfileFieldDataType = DMPProfileFieldDataType;
|
|
|
|
DMPProfileType = DMPProfileType;
|
2018-03-28 15:24:47 +02:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
@Input()
|
|
|
|
dataManagementPlanProfile: DataManagementPlanProfile;
|
2018-03-28 15:24:47 +02:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
@Input()
|
|
|
|
formGroup: FormGroup;
|
2018-03-28 15:24:47 +02:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
ngOnInit(): void {
|
|
|
|
this.formGroup.addControl('properties', new FormBuilder().group([]));
|
|
|
|
(<FormGroup>this.formGroup.get('properties')).addControl('fields', new FormBuilder().array([]));
|
2018-03-28 15:24:47 +02:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
this.dataManagementPlanProfile.fields.forEach(item => {
|
|
|
|
(<FormArray>this.formGroup.get('properties').get('fields')).push(new FormBuilder().group({
|
|
|
|
id: [item.id],
|
|
|
|
value: [item.value]
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
}
|
2018-03-28 15:24:47 +02:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
ngOnDestroy(): void {
|
|
|
|
this.formGroup.removeControl('properties');
|
|
|
|
}
|
2018-05-28 11:50:42 +02:00
|
|
|
}
|