From c9cc2cb4f3d752f3b16eee8d87593e8f3a20db30 Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 1 Sep 2019 13:42:10 +0200 Subject: [PATCH] refactoring of similar notes path handling --- src/public/javascripts/services/link.js | 20 +++++++++++++++++++ .../javascripts/widgets/similar_notes.js | 17 +++++++++------- src/public/stylesheets/desktop.css | 5 +++++ src/services/note_cache.js | 2 +- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/public/javascripts/services/link.js b/src/public/javascripts/services/link.js index 20a904812..6f4cb77cb 100644 --- a/src/public/javascripts/services/link.js +++ b/src/public/javascripts/services/link.js @@ -30,6 +30,25 @@ async function createNoteLink(notePath, noteTitle = null) { return noteLink; } +async function createNoteLinkWithPath(notePath) { + const $link = await createNoteLink(notePath); + + const $res = $("").append($link); + + if (notePath.includes("/")) { + const noteIds = notePath.split("/"); + noteIds.pop(); // remove last element + + const parentNotePath = noteIds.join("/").trim(); + + if (parentNotePath) { + $res.append($("").text(" (" + await treeUtils.getNotePathTitle(parentNotePath) + ")")); + } + } + + return $res; +} + function getNotePathFromLink($link) { const notePathAttr = $link.attr("data-note-path"); @@ -159,6 +178,7 @@ $(document).on('mousedown', 'span.ck-button__label', e => { export default { getNotePathFromUrl, createNoteLink, + createNoteLinkWithPath, addLinkToEditor, addTextToEditor, goToLink diff --git a/src/public/javascripts/widgets/similar_notes.js b/src/public/javascripts/widgets/similar_notes.js index b0cf4e4f1..d56d714c2 100644 --- a/src/public/javascripts/widgets/similar_notes.js +++ b/src/public/javascripts/widgets/similar_notes.js @@ -3,6 +3,7 @@ import linkService from "../services/link.js"; import server from "../services/server.js"; import treeCache from "../services/tree_cache.js"; import treeUtils from "../services/tree_utils.js"; +import treeService from "../services/tree.js"; class SimilarNotesWidget extends StandardWidget { getWidgetTitle() { return "Similar notes"; } @@ -19,18 +20,20 @@ class SimilarNotesWidget extends StandardWidget { await treeCache.getNotes(similarNotes.map(note => note.noteId)); // preload all at once - const $list = $('
    '); + const $list = $('
      '); for (const similarNote of similarNotes) { - const $item = $("
    • ") - .append(await linkService.createNoteLink(similarNote.notePath.join("/"))); + const note = await treeCache.getNote(similarNote.noteId); - similarNote.notePath.pop(); // remove last noteId since it's already in the link - - if (similarNote.notePath.length > 0) { - $item.append($("").text(" (" + await treeUtils.getNotePathTitle(similarNote.notePath.join("/")) + ")")); + if (!note) { + continue; } + const notePath = await treeService.getSomeNotePath(note); + + const $item = $("
    • ") + .append(await linkService.createNoteLinkWithPath(notePath)); + $list.append($item); } diff --git a/src/public/stylesheets/desktop.css b/src/public/stylesheets/desktop.css index d0644056e..9c658f488 100644 --- a/src/public/stylesheets/desktop.css +++ b/src/public/stylesheets/desktop.css @@ -392,6 +392,11 @@ body { border: 0; } +.note-detail-sidebar .card-body ul { + padding-left: 25px; + margin-bottom: 5px; +} + #widgets-configuration { margin: 0; } diff --git a/src/services/note_cache.js b/src/services/note_cache.js index ba088e33c..d5bc91b74 100644 --- a/src/services/note_cache.js +++ b/src/services/note_cache.js @@ -348,7 +348,7 @@ function evaluateSimilarity(text1, text2, noteId, results) { coeff -= 0.2; // archived penalization } - results.push({coeff, notePath, noteId}); + results.push({coeff, noteId}); } }