mirror of
https://github.com/zadam/trilium.git
synced 2024-11-18 21:55:26 +08:00
34 lines
987 B
JavaScript
34 lines
987 B
JavaScript
|
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);
|
||
|
|
||
|
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;
|