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-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;
|