2019-08-16 03:18:33 +08:00
|
|
|
import StandardWidget from "./standard_widget.js";
|
2019-07-22 03:55:48 +08:00
|
|
|
|
|
|
|
let linkMapContainerIdCtr = 1;
|
|
|
|
|
|
|
|
const TPL = `
|
2019-08-31 02:15:59 +08:00
|
|
|
<div class="link-map-widget">
|
2019-07-22 03:55:48 +08:00
|
|
|
<div class="link-map-container"></div>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
|
2019-08-16 03:18:33 +08:00
|
|
|
class LinkMapWidget extends StandardWidget {
|
2019-08-17 16:45:20 +08:00
|
|
|
getWidgetTitle() { return "Link map"; }
|
2019-07-25 04:52:51 +08:00
|
|
|
|
2019-09-10 03:23:04 +08:00
|
|
|
getHelp() {
|
|
|
|
return {
|
|
|
|
title: "Link map shows incoming and outgoing links from/to the current note.",
|
|
|
|
url: "https://github.com/zadam/trilium/wiki/Link-map"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-08-17 16:45:20 +08:00
|
|
|
getHeaderActions() {
|
2019-07-25 04:52:51 +08:00
|
|
|
const $showFullButton = $("<a>").append("show full").addClass('widget-header-action');
|
2019-11-10 00:39:48 +08:00
|
|
|
$showFullButton.on('click', async () => {
|
2019-08-21 03:40:47 +08:00
|
|
|
const linkMapDialog = await import("../dialogs/link_map.js");
|
2019-07-25 04:52:51 +08:00
|
|
|
linkMapDialog.showDialog();
|
|
|
|
});
|
|
|
|
|
2019-08-17 16:45:20 +08:00
|
|
|
return [$showFullButton];
|
2019-07-22 03:55:48 +08:00
|
|
|
}
|
|
|
|
|
2020-01-19 18:37:24 +08:00
|
|
|
async refreshWithNote() {
|
2019-11-06 03:59:20 +08:00
|
|
|
this.$body.css('opacity', 0);
|
2019-08-16 03:18:33 +08:00
|
|
|
this.$body.html(TPL);
|
2019-08-15 16:04:03 +08:00
|
|
|
|
2019-08-28 02:20:00 +08:00
|
|
|
const $linkMapContainer = this.$body.find('.link-map-container');
|
|
|
|
$linkMapContainer.attr("id", "link-map-container-" + linkMapContainerIdCtr++);
|
2019-08-28 04:19:32 +08:00
|
|
|
$linkMapContainer.css("height", "300px");
|
2019-07-22 03:55:48 +08:00
|
|
|
|
2019-08-28 02:20:00 +08:00
|
|
|
const LinkMapServiceClass = (await import('../services/link_map.js')).default;
|
2019-07-22 03:55:48 +08:00
|
|
|
|
2020-01-15 04:23:32 +08:00
|
|
|
this.linkMapService = new LinkMapServiceClass(this.tabContext.note, $linkMapContainer, {
|
2019-08-28 04:19:32 +08:00
|
|
|
maxDepth: 1,
|
2019-08-31 02:15:59 +08:00
|
|
|
zoom: 0.6
|
2019-08-28 04:19:32 +08:00
|
|
|
});
|
2019-07-22 03:55:48 +08:00
|
|
|
|
2019-08-29 03:15:16 +08:00
|
|
|
await this.linkMapService.render();
|
2019-11-06 03:59:20 +08:00
|
|
|
|
|
|
|
this.$body.animate({opacity: 1}, 300);
|
2019-08-29 03:15:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cleanup() {
|
|
|
|
if (this.linkMapService) {
|
|
|
|
this.linkMapService.cleanup();
|
|
|
|
}
|
2019-07-22 03:55:48 +08:00
|
|
|
}
|
2019-08-30 05:08:30 +08:00
|
|
|
|
2020-01-15 04:23:32 +08:00
|
|
|
syncDataListener({data}) {
|
|
|
|
if (data.find(sd => sd.entityName === 'attributes' && sd.noteId === this.tabContext.note.noteId)) {
|
|
|
|
// no need to invalidate attributes since the Attribute class listens to this as well
|
|
|
|
// (and is guaranteed to run first)
|
|
|
|
if (this.linkMapService) {
|
|
|
|
this.linkMapService.loadNotesAndRelations();
|
2019-08-30 05:08:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-22 03:55:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default LinkMapWidget;
|