Skip to content

Build your personal knowledge base with Trilium Notes

basic implementation of saved searches finished, closes #83

azivnerf1b0b3bcdb87
diff --git a/src/public/javascripts/note_tree.js b/src/public/javascripts/note_tree.js
index 17c70b7f63..068121c30d 100644
--- a/src/public/javascripts/note_tree.js
+++ b/src/public/javascripts/note_tree.js
@@ -654,14 +654,28 @@ const noteTree = (function() {
$tree.contextmenu(contextMenu.contextMenuSettings);
}
- async function loadSearchNote(noteId) {
- const note = await server.get('notes/' + noteId);
+ async function loadSearchNote(searchNoteId) {
+ const note = await server.get('notes/' + searchNoteId);
const json = JSON.parse(note.detail.content);
const noteIds = await server.get('notes?search=' + encodeURIComponent(json.searchString));
- console.log("Found: ", noteIds);
+ for (const noteId of noteIds) {
+ const noteTreeId = "virt" + randomString(10);
+
+ notesTreeMap[noteTreeId] = {
+ noteTreeId: noteTreeId,
+ noteId: noteId,
+ parentNoteId: searchNoteId,
+ prefix: '',
+ virtual: true
+ };
+
+ setParentChildRelation(noteTreeId, searchNoteId, noteId);
+ }
+
+ return prepareNoteTreeInner(searchNoteId);
}
function getTree() {
diff --git a/src/public/javascripts/utils.js b/src/public/javascripts/utils.js
index a1f6c3c744..0fcb366825 100644
--- a/src/public/javascripts/utils.js
+++ b/src/public/javascripts/utils.js
@@ -219,4 +219,15 @@ function toObject(array, fn) {
}
return obj;
+}
+
+function randomString(len) {
+ let text = "";
+ const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+
+ for (let i = 0; i < len; i++) {
+ text += possible.charAt(Math.floor(Math.random() * possible.length));
+ }
+
+ return text;
}
\ No newline at end of file