mirror of
https://github.com/TriliumNext/Notes.git
synced 2026-05-12 15:18:27 -05:00
basic implementation of "similar notes" widget
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user