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

31 lines
860 B
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-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-08-20 02:12:00 +08:00
2019-08-20 02:59:40 +08:00
for (const rel of targetRelations) {
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
this.$body.empty().append($list);
2019-08-20 02:12:00 +08:00
}
}
export default WhatLinksHereWidget;