From e63d3489b0679b1e07d79f25cb793cead64f25d6 Mon Sep 17 00:00:00 2001 From: CobriMediaJulien <56324041+CobriMediaJulien@users.noreply.github.com> Date: Sun, 8 Dec 2024 22:52:51 +0100 Subject: [PATCH 1/8] Better Canvas search to prevent metadata beeing searched in fulltext --- .../expressions/note_content_fulltext.ts | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/services/search/expressions/note_content_fulltext.ts b/src/services/search/expressions/note_content_fulltext.ts index 106d5d3e3..546191a3c 100644 --- a/src/services/search/expressions/note_content_fulltext.ts +++ b/src/services/search/expressions/note_content_fulltext.ts @@ -133,6 +133,30 @@ class NoteContentFulltextExp extends Expression { content = content.replace(/ /g, ' '); } + else if (type === 'mindMap' && mime === 'application/json') { + console.log("mindMap", content); + let mindMapcontent = JSON.parse (content); + console.log("mindMap", mindMapcontent); + let topic = mindMapcontent.nodedata.topic; + console.log("topic22", topic); + content = utils.normalize(topic.toString()); + } + else if (type === 'canvas' && mime === 'application/json') { + interface Element { + type: string; + text?: string; // Optional since not all objects have a `text` property + id: string; + [key: string]: any; // Other properties that may exist + } + console.log("hier") + let canvasContent = JSON.parse (content); + const elements: Element [] = canvasContent.elements; + const texts = elements + .filter((element: Element) => element.type === 'text' && element.text) // Filter for 'text' type elements with a 'text' property + .map((element: Element) => element.text!); // Use `!` to assert `text` is defined after filtering + console.log(texts) + } + return content.trim(); } From cf8ec5a28673e3115576a0a0c0d07831a0204b2a Mon Sep 17 00:00:00 2001 From: CobriMediaJulien <56324041+CobriMediaJulien@users.noreply.github.com> Date: Sun, 8 Dec 2024 22:56:26 +0100 Subject: [PATCH 2/8] Update note_content_fulltext.ts --- src/services/search/expressions/note_content_fulltext.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/services/search/expressions/note_content_fulltext.ts b/src/services/search/expressions/note_content_fulltext.ts index 546191a3c..11a8c09f3 100644 --- a/src/services/search/expressions/note_content_fulltext.ts +++ b/src/services/search/expressions/note_content_fulltext.ts @@ -134,11 +134,8 @@ class NoteContentFulltextExp extends Expression { content = content.replace(/ /g, ' '); } else if (type === 'mindMap' && mime === 'application/json') { - console.log("mindMap", content); let mindMapcontent = JSON.parse (content); - console.log("mindMap", mindMapcontent); let topic = mindMapcontent.nodedata.topic; - console.log("topic22", topic); content = utils.normalize(topic.toString()); } else if (type === 'canvas' && mime === 'application/json') { @@ -154,7 +151,6 @@ class NoteContentFulltextExp extends Expression { const texts = elements .filter((element: Element) => element.type === 'text' && element.text) // Filter for 'text' type elements with a 'text' property .map((element: Element) => element.text!); // Use `!` to assert `text` is defined after filtering - console.log(texts) } From 24d5311b9f57c97104307b76c9444a4aff795726 Mon Sep 17 00:00:00 2001 From: CobriMediaJulien <56324041+CobriMediaJulien@users.noreply.github.com> Date: Fri, 13 Dec 2024 13:28:58 +0100 Subject: [PATCH 3/8] Update note_content_fulltext.ts Mindmap search works now --- .../expressions/note_content_fulltext.ts | 55 ++++++++++++++++++- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/src/services/search/expressions/note_content_fulltext.ts b/src/services/search/expressions/note_content_fulltext.ts index 11a8c09f3..9ede1a44a 100644 --- a/src/services/search/expressions/note_content_fulltext.ts +++ b/src/services/search/expressions/note_content_fulltext.ts @@ -12,6 +12,7 @@ import striptags from "striptags"; import utils from "../../utils.js"; import sql from "../../sql.js"; + const ALLOWED_OPERATORS = ['=', '!=', '*=*', '*=', '=*', '%=']; const cachedRegexes: Record = {}; @@ -134,9 +135,55 @@ class NoteContentFulltextExp extends Expression { content = content.replace(/ /g, ' '); } else if (type === 'mindMap' && mime === 'application/json') { + let mindMapcontent = JSON.parse (content); - let topic = mindMapcontent.nodedata.topic; - content = utils.normalize(topic.toString()); + + // Define interfaces for the JSON structure + interface MindmapNode { + id: string; + topic: string; + children: MindmapNode[]; // Recursive structure + direction?: number; + expanded?: boolean; + } + + interface MindmapData { + nodedata: MindmapNode; + arrows: any[]; // If you know the structure, replace `any` with the correct type + summaries: any[]; + direction: number; + theme: { + name: string; + type: string; + palette: string[]; + cssvar: Record; // Object with string keys and string values + }; + } + + // Recursive function to collect all topics + function collectTopics(node: MindmapNode): string[] { + // Collect the current node's topic + let topics = [node.topic]; + + // If the node has children, collect topics recursively + if (node.children && node.children.length > 0) { + for (const child of node.children) { + topics = topics.concat(collectTopics(child)); + } + } + + return topics; + } + + + // Start extracting from the root node + const topicsArray = collectTopics(mindMapcontent.nodedata); + + // Combine topics into a single string + const topicsString = topicsArray.join(", "); + + + content = utils.normalize(topicsString.toString()); } else if (type === 'canvas' && mime === 'application/json') { interface Element { @@ -145,12 +192,14 @@ class NoteContentFulltextExp extends Expression { id: string; [key: string]: any; // Other properties that may exist } - console.log("hier") + let canvasContent = JSON.parse (content); const elements: Element [] = canvasContent.elements; const texts = elements .filter((element: Element) => element.type === 'text' && element.text) // Filter for 'text' type elements with a 'text' property .map((element: Element) => element.text!); // Use `!` to assert `text` is defined after filtering + + content =utils.normalize(texts.toString()) } From ee4fe05cd1eeb229fd2b8ec5d44f71653f8dd1e6 Mon Sep 17 00:00:00 2001 From: CobriMediaJulien <56324041+CobriMediaJulien@users.noreply.github.com> Date: Sun, 15 Dec 2024 15:51:11 +0100 Subject: [PATCH 4/8] Update canvas.js Improvement of canva library feature. Now u can delete items and manage your library in the UI. --- src/public/app/widgets/type_widgets/canvas.js | 96 +++++++++++++++---- 1 file changed, 80 insertions(+), 16 deletions(-) diff --git a/src/public/app/widgets/type_widgets/canvas.js b/src/public/app/widgets/type_widgets/canvas.js index 08f7128e3..0c3d2ffd6 100644 --- a/src/public/app/widgets/type_widgets/canvas.js +++ b/src/public/app/widgets/type_widgets/canvas.js @@ -2,7 +2,7 @@ import libraryLoader from '../../services/library_loader.js'; import TypeWidget from './type_widget.js'; import utils from '../../services/utils.js'; import linkService from '../../services/link.js'; - +import server from '../../services/server.js'; const TPL = `