basic implementation of "similar notes" widget

This commit is contained in:
zadam
2019-09-01 08:58:13 +02:00
parent bf5a31dcdb
commit 7c60080772
8 changed files with 71 additions and 3 deletions
@@ -51,7 +51,8 @@ export default class SidebarOptions {
{name: 'linkMap', title: 'Link map'},
{name: 'noteInfo', title: 'Note info'},
{name: 'noteRevisions', title: 'Note revisions'},
{name: 'whatLinksHere', title: 'What links here'}
{name: 'whatLinksHere', title: 'What links here'},
{name: 'similarNotes', title: 'Similar notes'}
].map(widget => {
widget.option = this.parseJsonSafely(options[widget.name + 'Widget']) || {
enabled: true,
+2 -1
View File
@@ -65,7 +65,8 @@ class Sidebar {
import("../widgets/link_map.js"),
import("../widgets/note_revisions.js"),
import("../widgets/attributes.js"),
import("../widgets/what_links_here.js")
import("../widgets/what_links_here.js"),
import("../widgets/similar_notes.js")
])).map(m => m.default);
const options = await optionsService.waitForOptions();
@@ -0,0 +1,36 @@
import StandardWidget from "./standard_widget.js";
import linkService from "../services/link.js";
import server from "../services/server.js";
import treeCache from "../services/tree_cache.js";
class SimilarNotesWidget extends StandardWidget {
getWidgetTitle() { return "Similar notes"; }
getMaxHeight() { return "200px"; }
async doRenderBody() {
const similarNoteIds = await server.get('similar_notes/' + this.ctx.note.noteId);
console.log(similarNoteIds);
if (similarNoteIds.length === 0) {
this.$body.text("No similar notes found ...");
return;
}
await treeCache.getNotes(similarNoteIds); // preload all at once
const $list = $("<ul>");
for (const similarNoteId of similarNoteIds) {
const $item = $("<li>")
.append(await linkService.createNoteLink(similarNoteId));
$list.append($item);
}
this.$body.empty().append($list);
}
}
export default SimilarNotesWidget;