diff --git a/dmp-frontend/src/app/ui/description/editor/description-editor.component.ts b/dmp-frontend/src/app/ui/description/editor/description-editor.component.ts index 1ea2e62f0..2183a398c 100644 --- a/dmp-frontend/src/app/ui/description/editor/description-editor.component.ts +++ b/dmp-frontend/src/app/ui/description/editor/description-editor.component.ts @@ -918,29 +918,45 @@ export class DescriptionEditorComponent extends BaseEditor(); descriptionTemplate.definition.pages?.forEach((page: DescriptionTemplatePage) => { - page.sections?.forEach((section: DescriptionTemplateSection) => { - const fieldsets = this.getFieldsetsFromSection(section); - const value = fieldsets?.flatMap((fieldset: DescriptionTemplateFieldSet) => - fieldset.fields?.flatMap((field: DescriptionTemplateField) => - new DescriptionFieldIndicator(page.id, section.id, fieldset.id, field.id, field.data.fieldType, field.data.multipleSelect) - // 'properties.fieldSets.' + fieldset.id + '.items.0.fields.' + field.id// + '.textValue' - )); - pageToFieldSetMap.set(page.id, - value - ); - }); + let fieldsByPage = this.getFieldsetsOfPage(page); + pageToFieldSetMap.set(page.id, fieldsByPage); }); return pageToFieldSetMap; } - getFieldsetsFromSection(section: DescriptionTemplateSection): DescriptionTemplateFieldSet[] { + getFieldsetsOfPage(page: DescriptionTemplatePage): DescriptionFieldIndicator[] { + const fieldsByPage: DescriptionFieldIndicator[] = [] + + page.sections?.forEach((section: DescriptionTemplateSection) => { + let fieldsets = this.getNestedSectionFieldsets(section); + let sectionIds = this.getNestedSectionIds(section); + let fieldsBySection: DescriptionFieldIndicator[] = fieldsets?.flatMap((fieldset: DescriptionTemplateFieldSet) => + fieldset.fields?.flatMap((field: DescriptionTemplateField) => + new DescriptionFieldIndicator(page.id, sectionIds, fieldset.id, field.id, field.data.fieldType, field.data.multipleSelect) + )); + + fieldsByPage.push(...fieldsBySection); + }); + + return fieldsByPage; + } + + getNestedSectionFieldsets(section: DescriptionTemplateSection): DescriptionTemplateFieldSet[] { if (section.sections) { - return section.sections.flatMap((subsection: DescriptionTemplateSection) => this.getFieldsetsFromSection(subsection)); + return section.sections.flatMap((subsection: DescriptionTemplateSection) => this.getNestedSectionFieldsets(subsection)); } else return section.fieldSets; } + + getNestedSectionIds(section: DescriptionTemplateSection): string[] { + if (section.sections) { + return [section.id, ...section.sections.flatMap((subsection: DescriptionTemplateSection) => this.getNestedSectionIds(subsection))]; + } + + else return [section.id]; + } // // this._listenersSubscription.add(dmpSubscription); // // this._listenersSubscription.add(profileSubscription); diff --git a/dmp-frontend/src/app/ui/description/editor/description-editor.model.ts b/dmp-frontend/src/app/ui/description/editor/description-editor.model.ts index 68b60a73d..507f6a053 100644 --- a/dmp-frontend/src/app/ui/description/editor/description-editor.model.ts +++ b/dmp-frontend/src/app/ui/description/editor/description-editor.model.ts @@ -695,14 +695,14 @@ export class DescriptionReferenceEditorModel implements DescriptionReferencePers export class DescriptionFieldIndicator { pageId: string; - sectionId: string; + sectionIds: string[]; fieldSetId: string; fieldId: string; type: string; - constructor(pageId: string, sectionId: string, fieldSetId: string, fieldId: string, type: DescriptionTemplateFieldType, multipleSelect: boolean = false) { + constructor(pageId: string, sectionIds: string[], fieldSetId: string, fieldId: string, type: DescriptionTemplateFieldType, multipleSelect: boolean = false) { this.pageId = pageId; - this.sectionId = sectionId; + this.sectionIds = sectionIds; this.fieldSetId = fieldSetId; this.fieldId = fieldId; diff --git a/dmp-frontend/src/app/ui/description/editor/table-of-contents/table-of-contents-internal/table-of-contents-internal.ts b/dmp-frontend/src/app/ui/description/editor/table-of-contents/table-of-contents-internal/table-of-contents-internal.ts index 4bc9f3c62..1cc393d39 100644 --- a/dmp-frontend/src/app/ui/description/editor/table-of-contents/table-of-contents-internal/table-of-contents-internal.ts +++ b/dmp-frontend/src/app/ui/description/editor/table-of-contents/table-of-contents-internal/table-of-contents-internal.ts @@ -50,7 +50,6 @@ export class TableOfContentsInternal implements OnInit { if (this.parentMap) { this.updatedMap = this.updateMap(this.tocentries, this.parentMap); - console.log(this.updatedMap); } } } @@ -82,7 +81,7 @@ export class TableOfContentsInternal implements OnInit { parentMap.forEach((fields: DescriptionFieldIndicator[], parentId: string) => { if (this.parentId === parentId) { for (let entry of entries) { - let entryFields = fields.filter((field: DescriptionFieldIndicator) => field.sectionId === entry.id || field.fieldSetId === entry.id || field.fieldId === entry.id ) + let entryFields = fields.filter((field: DescriptionFieldIndicator) => field.sectionIds.includes(entry.id) || field.fieldSetId === entry.id || field.fieldId === entry.id ) updatedMap.set(entry.id, entryFields); }