2020-04-26 09:40:02 +02:00
|
|
|
import CollapsibleWidget from "../collapsible_widget.js";
|
|
|
|
import linkService from "../../services/link.js";
|
2019-08-19 20:12:00 +02:00
|
|
|
|
2020-02-02 21:16:20 +01:00
|
|
|
export default class WhatLinksHereWidget extends CollapsibleWidget {
|
2020-09-13 21:59:31 +02:00
|
|
|
isEnabled() {
|
|
|
|
return super.isEnabled() && !this.note.hasLabel('whatLinksHereWidgetDisabled');
|
|
|
|
}
|
|
|
|
|
2020-03-16 22:14:18 +01:00
|
|
|
get widgetTitle() { return "What links here"; }
|
2019-08-19 20:12:00 +02:00
|
|
|
|
2020-03-16 22:14:18 +01:00
|
|
|
get help() {
|
2019-09-09 21:23:04 +02:00
|
|
|
return {
|
|
|
|
title: "This list contains all notes which link to this note through links and relations."
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-03-16 22:14:18 +01:00
|
|
|
get headerActions() {
|
2020-10-15 20:37:55 +02:00
|
|
|
const $showFullButton = $("<a>")
|
2020-11-29 22:32:31 +01:00
|
|
|
.addClass("bx bx-network-chart")
|
2020-10-15 20:37:55 +02:00
|
|
|
.addClass('widget-header-action')
|
|
|
|
.attr('title', 'Show full link map');
|
|
|
|
|
2019-11-09 17:39:48 +01:00
|
|
|
$showFullButton.on('click', async () => {
|
2020-04-26 09:40:02 +02:00
|
|
|
const linkMapDialog = await import("../../dialogs/link_map.js");
|
2019-08-28 21:15:16 +02:00
|
|
|
linkMapDialog.showDialog();
|
|
|
|
});
|
|
|
|
|
|
|
|
return [$showFullButton];
|
|
|
|
}
|
|
|
|
|
2020-02-03 21:56:45 +01:00
|
|
|
async refreshWithNote(note) {
|
|
|
|
const targetRelations = 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) {
|
2020-02-03 21:56:45 +01:00
|
|
|
$list.append($("<li>").text(`${targetRelations.length - i} more links ...`));
|
2019-09-08 13:08:01 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2020-02-16 19:23:49 +01:00
|
|
|
entitiesReloadedEvent({loadResults}) {
|
2020-01-29 21:38:58 +01:00
|
|
|
if (loadResults.getAttributes().find(attr => attr.type === 'relation' && attr.value === this.noteId)) {
|
|
|
|
this.refresh();
|
|
|
|
}
|
|
|
|
}
|
2020-09-05 22:45:26 +02:00
|
|
|
}
|