From f1b0b3bcdb87ce621c2535c3497757ecbb1fa701 Mon Sep 17 00:00:00 2001 From: azivner Date: Mon, 12 Mar 2018 23:27:21 -0400 Subject: [PATCH] basic implementation of saved searches finished, closes #83 --- src/public/javascripts/note_tree.js | 20 +++++++++++++++++--- src/public/javascripts/utils.js | 11 +++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/public/javascripts/note_tree.js b/src/public/javascripts/note_tree.js index 17c70b7f6..068121c30 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 a1f6c3c74..0fcb36682 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