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"; }
|
|
|
|
|
2019-09-09 21:23:04 +02:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2020-01-19 11:37:24 +01:00
|
|
|
async refreshWithNote() {
|
2020-01-25 14:48:53 +01:00
|
|
|
const targetRelations = 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
|
|
|
}
|
2020-01-29 21:38:58 +01:00
|
|
|
|
|
|
|
entitiesReloadedListener({loadResults}) {
|
|
|
|
if (loadResults.getAttributes().find(attr => attr.type === 'relation' && attr.value === this.noteId)) {
|
|
|
|
this.refresh();
|
|
|
|
}
|
|
|
|
}
|
2019-08-19 20:12:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default WhatLinksHereWidget;
|