Untitled
private handleData(section: PageSection, node: EditorTreeNode, data: any, nodeIsItemChild: boolean, layout: PageLayout) { if (!data) { section.messages = [ ...(section.messages ?? []), { severity: 'error', detail: this.i18nService.translate( 'editor.EDITORPAGE.MESSAGE.ERRORITEMEXISTS', {}, this.i18nService.getActiveLang() ), }, ]; section.header = node.label; section.key = <string>node.key; section.expandedOnce = true; } else { const { relItemData: relatedItem, pageSection } = data; section.header = pageSection.header; section.key = <string>node.key; section.content = <EditorContent[]>pageSection.content; // create parent section for items if (relatedItem !== undefined) { const parentSection = layout.sections.find((section) => section.content.some((content) => content.nodeName === node.key) ); const itemHasChildSections = this.flattenedTreeNodes?.some( (treeNode) => treeNode.key?.includes(`${node.key}-`) ); if (!nodeIsItemChild) { section.metadata = [ ...ITEM_METADATA_NODES.map( (itemNode) => ({ ...itemNode, value: relatedItem ? relatedItem[`${itemNode.nodeName}` as keyof ItemModel] : undefined, itemId: relatedItem.id, type: EditorFieldInputType.InputText, } as EditorContent) ), ]; } section.header = pageSection.header; section.itemName = relatedItem.name; section.parentKey = parentSection?.key; section.valueName = <string>relatedItem.name; section.isItem = true; section.expandedOnce = true; section.content = section.content.map((content) => ({ itemId: relatedItem.id, ...content, })); if (itemHasChildSections) { // remove all nodes from generated item parent section to only display metadata section.content = []; } else { // update setup values with latest item values section.content.forEach((content) => { // update setup value with item value const itemValue = relatedItem.nodes?.find( (val: TreeNodeModel) => val.nodeName === content.nodeName ); const setupValue = this.setupValues?.find( (val) => val.nodeName === content.nodeName ); if (itemValue && setupValue) { setupValue.value = itemValue.value; } }); } // update tree item name and selectable state const treeNode = [ ...(this.flattenedTreeNodes?.map((treeNode) => treeNode) ?? []), ].find((tNode) => tNode.key === section.key); if (treeNode && !nodeIsItemChild) { treeNode.label = `${treeNode.label?.split(':')[0]}: ${ relatedItem.name ?? '' }`; section.header = treeNode.label; if (treeNode.selectable === false) { treeNode.selectable = true; treeNode.children = [ ...(treeNode.children?.map((cNode) => ({ ...cNode, selectable: true, })) ?? []), ]; } } } } }
Leave a Comment