From b642ec52bc8b3be47dc06a210cff84d9014c0f99 Mon Sep 17 00:00:00 2001 From: amentis Date: Fri, 29 Mar 2024 18:41:27 +0200 Subject: [PATCH] final description template preview changes --- .../final-preview/final-preview.component.ts | 82 ++++++++++++++++++- .../form-field-set.component.html | 8 +- 2 files changed, 82 insertions(+), 8 deletions(-) diff --git a/dmp-frontend/src/app/ui/admin/description-template/editor/components/final-preview/final-preview.component.ts b/dmp-frontend/src/app/ui/admin/description-template/editor/components/final-preview/final-preview.component.ts index ee6504887..299c36886 100644 --- a/dmp-frontend/src/app/ui/admin/description-template/editor/components/final-preview/final-preview.component.ts +++ b/dmp-frontend/src/app/ui/admin/description-template/editor/components/final-preview/final-preview.component.ts @@ -1,7 +1,8 @@ import { Component, Input, OnInit, SimpleChanges } from '@angular/core'; import { UntypedFormGroup } from '@angular/forms'; -import { DescriptionTemplate } from '@app/core/model/description-template/description-template'; -import { DescriptionTemplatePersist } from '@app/core/model/description-template/description-template-persist'; +import { DescriptionTemplateFieldType } from '@app/core/common/enum/description-template-field-type'; +import { DescriptionTemplate, DescriptionTemplateBaseFieldData, DescriptionTemplateDefinition, DescriptionTemplateField, DescriptionTemplateFieldSet, DescriptionTemplateMultiplicity, DescriptionTemplatePage, DescriptionTemplateReferenceTypeData, DescriptionTemplateRule, DescriptionTemplateSection } from '@app/core/model/description-template/description-template'; +import { DescriptionTemplateBaseFieldDataPersist, DescriptionTemplateDefinitionPersist, DescriptionTemplateFieldPersist, DescriptionTemplateFieldSetPersist, DescriptionTemplateMultiplicityPersist, DescriptionTemplatePagePersist, DescriptionTemplatePersist, DescriptionTemplateReferenceTypeFieldPersist, DescriptionTemplateRulePersist, DescriptionTemplateSectionPersist } from '@app/core/model/description-template/description-template-persist'; import { Description } from '@app/core/model/description/description'; import { DescriptionEditorModel } from '@app/ui/description/editor/description-editor.model'; import { VisibilityRulesService } from '@app/ui/description/editor/description-form/visibility-rules/visibility-rules.service'; @@ -23,7 +24,7 @@ export class FinalPreviewComponent implements OnInit { previewPropertiesFormGroup @Input() formGroup = null; - constructor(private visibilityRulesService: VisibilityRulesService) { + constructor(public visibilityRulesService: VisibilityRulesService) { } @@ -52,11 +53,84 @@ export class FinalPreviewComponent implements OnInit { language: persist.language, type: undefined, status: persist.status, - definition: persist.definition, + definition: this.buildDescriptionTemplateDefinition(persist.definition), users: persist.users } } + private buildDescriptionTemplateDefinition(persist: DescriptionTemplateDefinitionPersist) : DescriptionTemplateDefinition{ + if (persist == null) return null; + return { + pages: persist.pages.map(x => this.buildDescriptionTemplatePage(x)) + } + } + + private buildDescriptionTemplatePage(persist: DescriptionTemplatePagePersist) : DescriptionTemplatePage{ + if (persist == null) return null; + return { + id: persist.id, + ordinal: persist.ordinal, + title: persist.title, + sections: persist.sections.map(x => this.buildDescriptionTemplateSection(x)), + } + } + + private buildDescriptionTemplateSection(persist: DescriptionTemplateSectionPersist) : DescriptionTemplateSection{ + if (persist == null) return null; + return { + id: persist.id, + ordinal: persist.ordinal, + defaultVisibility: persist.defaultVisibility, + multiplicity: persist.multiplicity, + title: persist.title, + description: persist.description, + sections: persist.sections.map(x => this.buildDescriptionTemplateSection(x)), + fieldSets: persist.fieldSets.map(x => this.buildDescriptionTemplateFieldSet(x)), + } + } + + private buildDescriptionTemplateFieldSet(persist: DescriptionTemplateFieldSetPersist) : DescriptionTemplateFieldSet{ + if (persist == null) return null; + return { + id: persist.id, + ordinal: persist.ordinal, + numbering: '', + title: persist.title, + description: persist.description, + extendedDescription: persist.extendedDescription, + additionalInformation: persist.additionalInformation, + multiplicity: { + max: persist.multiplicity.max, min: persist.multiplicity.min, + placeholder: persist.multiplicity.placeholder, tableView: persist.multiplicity.tableView + }, + hasCommentField: persist.hasCommentField, + fields: persist.fields.map(x => this.buildDescriptionTemplateField(x)), + } + } + + private buildDescriptionTemplateField (persist: DescriptionTemplateFieldPersist) : DescriptionTemplateField{ + if (persist == null) return null; + let convertedField: DescriptionTemplateField ={ + id: persist.id, + ordinal: persist.ordinal, + schematics: persist.schematics, + defaultValue: persist.defaultValue, + visibilityRules: persist.visibilityRules, + validations: persist.validations, + includeInExport: persist.includeInExport, + data: persist.data, + } + + if (persist.data.fieldType === DescriptionTemplateFieldType.REFERENCE_TYPES) { + convertedField.data = persist.data; + (convertedField.data as DescriptionTemplateReferenceTypeData).referenceType = { + id: (persist.data as DescriptionTemplateReferenceTypeFieldPersist).referenceTypeId + }; + } else { + convertedField.data = persist.data; + } + return convertedField; + } ngOnInit(): void { this.generatePreviewForm(); diff --git a/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field-set/form-field-set.component.html b/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field-set/form-field-set.component.html index 2ca81178f..d8bb4fb03 100644 --- a/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field-set/form-field-set.component.html +++ b/dmp-frontend/src/app/ui/description/editor/description-form/components/form-field-set/form-field-set.component.html @@ -13,10 +13,10 @@
-
+
- +
{{field.label}}
@@ -48,9 +48,9 @@ - + - + {{fieldSetItemPropertiesControl.get('fields').get(field.id).get('value').getRawValue()}}