trilium/src/public/javascripts/widgets/what_links_here.js

48 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-08-20 02:12:00 +08:00
import StandardWidget from "./standard_widget.js";
2019-08-20 02:59:40 +08:00
import linkService from "../services/link.js";
2019-08-20 02:12:00 +08:00
class WhatLinksHereWidget extends StandardWidget {
getWidgetTitle() { return "What links here"; }
2019-08-20 02:59:40 +08:00
getMaxHeight() { return "200px"; }
2019-08-29 03:15:16 +08:00
getHeaderActions() {
const $showFullButton = $("<a>").append("show link map").addClass('widget-header-action');
$showFullButton.click(async () => {
const linkMapDialog = await import("../dialogs/link_map.js");
linkMapDialog.showDialog();
});
return [$showFullButton];
}
2019-08-20 02:12:00 +08:00
async doRenderBody() {
2019-08-20 02:59:40 +08:00
const targetRelations = await this.ctx.note.getTargetRelations();
2019-08-20 02:12:00 +08:00
2019-08-20 02:59:40 +08:00
if (targetRelations.length === 0) {
this.$body.text("Nothing links here yet ...");
return;
}
2019-08-20 02:12:00 +08:00
2019-08-20 02:59:40 +08:00
const $list = $("<ul>");
2019-09-08 19:08:01 +08:00
let i = 0;
for (; i < targetRelations.length && i < 50; i++) {
const rel = targetRelations[i];
2019-08-20 02:12:00 +08:00
2019-08-20 02:59:40 +08:00
const $item = $("<li>")
.append(await linkService.createNoteLink(rel.noteId))
.append($("<span>").text(" (" + rel.name + ")"));
2019-08-20 02:12:00 +08:00
2019-08-20 02:59:40 +08:00
$list.append($item);
2019-08-20 02:12:00 +08:00
}
2019-08-20 02:59:40 +08:00
2019-09-08 19:08:01 +08:00
if (i < targetRelations.length) {
$list.append($("<li>").text(`${targetRelations.length - i} more links ...`))
}
2019-08-20 02:59:40 +08:00
this.$body.empty().append($list);
2019-08-20 02:12:00 +08:00
}
}
export default WhatLinksHereWidget;