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

54 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-08-19 20:12:00 +02:00
import StandardWidget from "./standard_widget.js";
2019-08-19 20:59:40 +02:00
import linkService from "../services/link.js";
2019-08-19 20:12:00 +02:00
class WhatLinksHereWidget extends StandardWidget {
getWidgetTitle() { return "What links here"; }
2019-08-19 20:59:40 +02:00
getMaxHeight() { return "200px"; }
getHelp() {
return {
title: "This list contains all notes which link to this note through links and relations."
};
}
2019-08-28 21:15:16 +02:00
getHeaderActions() {
const $showFullButton = $("<a>").append("show link map").addClass('widget-header-action');
2019-11-09 17:39:48 +01:00
$showFullButton.on('click', async () => {
2019-08-28 21:15:16 +02:00
const linkMapDialog = await import("../dialogs/link_map.js");
linkMapDialog.showDialog();
});
return [$showFullButton];
}
async refresh() {
const targetRelations = await this.tabContext.note.getTargetRelations();
2019-08-19 20:12:00 +02:00
2019-08-19 20:59:40 +02:00
if (targetRelations.length === 0) {
this.$body.text("Nothing links here yet ...");
return;
}
2019-08-19 20:12:00 +02:00
2019-08-19 20:59:40 +02:00
const $list = $("<ul>");
2019-09-08 13:08:01 +02:00
let i = 0;
for (; i < targetRelations.length && i < 50; i++) {
const rel = targetRelations[i];
2019-08-19 20:12:00 +02:00
2019-08-19 20:59:40 +02:00
const $item = $("<li>")
.append(await linkService.createNoteLink(rel.noteId))
.append($("<span>").text(" (" + rel.name + ")"));
2019-08-19 20:12:00 +02:00
2019-08-19 20:59:40 +02:00
$list.append($item);
2019-08-19 20:12:00 +02:00
}
2019-08-19 20:59:40 +02:00
2019-09-08 13:08:01 +02:00
if (i < targetRelations.length) {
$list.append($("<li>").text(`${targetRelations.length - i} more links ...`))
}
2019-08-19 20:59:40 +02:00
this.$body.empty().append($list);
2019-08-19 20:12:00 +02:00
}
}
export default WhatLinksHereWidget;