192 lines
6.0 KiB
TypeScript
192 lines
6.0 KiB
TypeScript
import { FormBuilder, FormGroup } from "@angular/forms";
|
|
import { DescriptionTemplatesInSection, DmpBlueprint, DmpBlueprintDefinition, ExtraFieldInSection, ExtraFieldType, SectionDmpBlueprint, SystemFieldInSection, SystemFieldType } from "@app/core/model/dmp/dmp-blueprint/dmp-blueprint";
|
|
|
|
export class DmpBlueprintEditor {
|
|
public id: string;
|
|
public label: string;
|
|
public definition: DmpBlueprintDefinitionEditor = new DmpBlueprintDefinitionEditor();
|
|
public status: number;
|
|
public created: Date;
|
|
public modified: Date;
|
|
|
|
fromModel(item: DmpBlueprint): DmpBlueprintEditor {
|
|
this.id = item.id;
|
|
this.label = item.label;
|
|
this.definition = new DmpBlueprintDefinitionEditor().fromModel(item.definition);
|
|
this.status = item.status;
|
|
this.created = item.created;
|
|
this.modified = item.modified;
|
|
return this;
|
|
}
|
|
|
|
buildForm(): FormGroup {
|
|
const formGroup = new FormBuilder().group({
|
|
id: [this.id],
|
|
label: [this.label],
|
|
status: [this.status],
|
|
created: [this.created],
|
|
modified: [this.modified]
|
|
});
|
|
formGroup.addControl('definition', this.definition.buildForm());
|
|
return formGroup;
|
|
}
|
|
|
|
}
|
|
|
|
export class DmpBlueprintDefinitionEditor {
|
|
|
|
public sections: SectionDmpBlueprintEditor[] = new Array<SectionDmpBlueprintEditor>();
|
|
|
|
fromModel(item: DmpBlueprintDefinition): DmpBlueprintDefinitionEditor {
|
|
if (item.sections) { item.sections.map(x => this.sections.push(new SectionDmpBlueprintEditor().fromModel(x))); }
|
|
return this;
|
|
}
|
|
|
|
buildForm(): FormGroup {
|
|
const formBuilder = new FormBuilder();
|
|
const formGroup = formBuilder.group({});
|
|
const sectionsFormArray = new Array<FormGroup>();
|
|
this.sections.forEach(item => {
|
|
const form: FormGroup = item.buildForm();
|
|
sectionsFormArray.push(form);
|
|
});
|
|
formGroup.addControl('sections', formBuilder.array(sectionsFormArray));
|
|
return formGroup;
|
|
}
|
|
}
|
|
|
|
export class SectionDmpBlueprintEditor {
|
|
public id: string;
|
|
public label: string;
|
|
public description: string;
|
|
public ordinal: number;
|
|
public systemFields: SystemFieldInSectionEditor[] = new Array<SystemFieldInSectionEditor>();
|
|
public descriptionTemplates: DescriptionTemplatesInSectionEditor[] = new Array<DescriptionTemplatesInSectionEditor>();
|
|
|
|
fromModel(item: SectionDmpBlueprint): SectionDmpBlueprintEditor {
|
|
this.id = item.id;
|
|
this.label = item.label;
|
|
this.description = item.description;
|
|
this.ordinal = item.ordinal;
|
|
if (item.systemFields) { item.systemFields.map(x => this.systemFields.push(new SystemFieldInSectionEditor().fromModel(x))); }
|
|
if (item.descriptionTemplates) { item.descriptionTemplates.map(x => this.descriptionTemplates.push(new DescriptionTemplatesInSectionEditor().fromModel(x))); }
|
|
debugger;
|
|
return this;
|
|
}
|
|
|
|
buildForm(): FormGroup {
|
|
const formGroup = new FormBuilder().group({
|
|
id: [this.id],
|
|
label: [this.label],
|
|
description: [this.description],
|
|
ordinal: [this.ordinal]
|
|
});
|
|
const formBuilder = new FormBuilder();
|
|
const systemFieldsFormArray = new Array<FormGroup>();
|
|
this.systemFields.forEach(item => {
|
|
const form: FormGroup = item.buildForm();
|
|
systemFieldsFormArray.push(form);
|
|
});
|
|
formGroup.addControl('systemFields', formBuilder.array(systemFieldsFormArray));
|
|
const descriptionTemplatesFormArray = new Array<FormGroup>();
|
|
this.descriptionTemplates.forEach(item => {
|
|
const form: FormGroup = item.buildForm();
|
|
descriptionTemplatesFormArray.push(form);
|
|
});
|
|
formGroup.addControl('descriptionTemplates', formBuilder.array(descriptionTemplatesFormArray));
|
|
return formGroup;
|
|
}
|
|
}
|
|
|
|
export class SystemFieldInSectionEditor {
|
|
public id: string;
|
|
public type: SystemFieldType;
|
|
public placeholder: string;
|
|
public description: string;
|
|
public required: boolean;
|
|
public ordinal: number;
|
|
|
|
fromModel(item: SystemFieldInSection): SystemFieldInSectionEditor {
|
|
this.id = item.id;
|
|
this.type = item.type;
|
|
this.placeholder = item.placeholder;
|
|
this.description = item.description;
|
|
this.required = item.required;
|
|
this.ordinal = item.ordinal;
|
|
return this;
|
|
}
|
|
|
|
buildForm(): FormGroup {
|
|
const formGroup = new FormBuilder().group({
|
|
id: [this.id],
|
|
type: [this.type],
|
|
placeholder: [this.placeholder],
|
|
description: [this.description],
|
|
required: [this.required],
|
|
ordinal: [this.ordinal]
|
|
});
|
|
return formGroup;
|
|
}
|
|
}
|
|
|
|
export class DescriptionTemplatesInSectionEditor {
|
|
public id: string;
|
|
public descriptionTemplateId: string;
|
|
public label: string;
|
|
public minMultiplicity: number;
|
|
public maxMultiplicity: number;
|
|
|
|
fromModel(item: DescriptionTemplatesInSection): DescriptionTemplatesInSectionEditor {
|
|
this.id = item.id;
|
|
this.descriptionTemplateId = item.descriptionTemplateId;
|
|
this.label = item.label;
|
|
this.minMultiplicity = item.minMultiplicity;
|
|
this.maxMultiplicity = item.maxMultiplicity;
|
|
return this;
|
|
}
|
|
|
|
buildForm(): FormGroup {
|
|
const formGroup = new FormBuilder().group({
|
|
id: [this.id],
|
|
descriptionTemplateId: [this.descriptionTemplateId],
|
|
label: [this.label],
|
|
minMultiplicity: [this.minMultiplicity],
|
|
maxMultiplicity: [this.maxMultiplicity]
|
|
});
|
|
return formGroup;
|
|
}
|
|
}
|
|
|
|
export class ExtraFieldsInSectionEditor {
|
|
public id: string;
|
|
public label: string;
|
|
public description: string;
|
|
public placeholder: string;
|
|
public type: ExtraFieldType;
|
|
public required: boolean;
|
|
public ordinal: number;
|
|
|
|
fromModel(item: ExtraFieldInSection): ExtraFieldsInSectionEditor {
|
|
this.id = item.id;
|
|
this.label = item.label;
|
|
this.description = item.description;
|
|
this.placeholder = item.placeholder;
|
|
this.type = item.type;
|
|
this.required = item.required;
|
|
this.ordinal = item.ordinal;
|
|
return this;
|
|
}
|
|
|
|
buildForm(): FormGroup {
|
|
const formGroup = new FormBuilder().group({
|
|
id: [this.id],
|
|
label: [this.label],
|
|
description: [this.description],
|
|
placeholder: [this.placeholder],
|
|
type: [this.type],
|
|
required: [this.required],
|
|
ordinal: [this.ordinal]
|
|
});
|
|
return formGroup;
|
|
}
|
|
} |