argos/dmp-frontend/src/app/models/data-managemnt-plans/DynamicField.ts

39 lines
1.1 KiB
TypeScript
Raw Normal View History

2018-10-05 17:00:54 +02:00
import { DynamicFieldDependency } from './DynamicFieldDependency';
import { Serializable } from '../Serializable';
import { JsonSerializer } from '../../utilities/JsonSerializer';
import { FormGroup, FormBuilder } from '@angular/forms';
import { FormGenerator } from '../interfaces/FormGenerator';
2018-03-28 15:24:47 +02:00
2018-10-05 17:00:54 +02:00
export class DynamicField implements Serializable<DynamicField>, FormGenerator<FormGroup> {
2018-03-28 15:24:47 +02:00
2018-10-05 17:00:54 +02:00
public id: string;
public name: string;
public required: boolean;
public queryProperty;
public value: string;
public dependencies: Array<DynamicFieldDependency>;
2018-03-28 15:24:47 +02:00
2018-10-05 17:00:54 +02:00
fromJSONObject(item: any): DynamicField {
this.id = item.id;
this.name = item.name;
this.required = item.required;
this.value = item.value;
this.queryProperty = item.queryProperty;
this.dependencies = JsonSerializer.fromJSONArray(item.dependencies, DynamicFieldDependency);
return this;
}
2018-03-28 15:24:47 +02:00
2018-10-05 17:00:54 +02:00
buildForm(): FormGroup {
const builder = new FormBuilder();
const formGroup = builder.group({
id: [this.id],
name: [this.name],
required: [this.required],
value: [this.value],
queryProperty: [this.queryProperty],
dependencies: [this.dependencies]
});
return formGroup;
}
}