60 lines
1.7 KiB
JavaScript
Raw Normal View History

import StandardWidget from "./standard_widget.js";
2019-07-21 21:55:48 +02:00
let linkMapContainerIdCtr = 1;
const TPL = `
2019-08-30 20:15:59 +02:00
<div class="link-map-widget">
2019-07-21 21:55:48 +02:00
<div class="link-map-container"></div>
</div>
`;
class LinkMapWidget extends StandardWidget {
2019-08-17 10:45:20 +02:00
getWidgetTitle() { return "Link map"; }
2019-07-24 22:52:51 +02:00
2019-08-17 10:45:20 +02:00
getHeaderActions() {
2019-07-24 22:52:51 +02:00
const $showFullButton = $("<a>").append("show full").addClass('widget-header-action');
$showFullButton.click(async () => {
const linkMapDialog = await import("../dialogs/link_map.js");
2019-07-24 22:52:51 +02:00
linkMapDialog.showDialog();
});
2019-08-17 10:45:20 +02:00
return [$showFullButton];
2019-07-21 21:55:48 +02:00
}
async doRenderBody() {
this.$body.html(TPL);
2019-08-15 10:04:03 +02:00
2019-08-27 20:20:00 +02:00
const $linkMapContainer = this.$body.find('.link-map-container');
$linkMapContainer.attr("id", "link-map-container-" + linkMapContainerIdCtr++);
2019-08-27 22:19:32 +02:00
$linkMapContainer.css("height", "300px");
2019-07-21 21:55:48 +02:00
2019-08-27 20:20:00 +02:00
const LinkMapServiceClass = (await import('../services/link_map.js')).default;
2019-07-21 21:55:48 +02:00
2019-08-28 21:15:16 +02:00
this.linkMapService = new LinkMapServiceClass(this.ctx.note, $linkMapContainer, {
2019-08-27 22:19:32 +02:00
maxDepth: 1,
2019-08-30 20:15:59 +02:00
zoom: 0.6
2019-08-27 22:19:32 +02:00
});
2019-07-21 21:55:48 +02:00
2019-08-28 21:15:16 +02:00
await this.linkMapService.render();
}
cleanup() {
if (this.linkMapService) {
this.linkMapService.cleanup();
}
2019-07-21 21:55:48 +02:00
}
2019-08-29 23:08:30 +02:00
eventReceived(name, data) {
if (name === 'syncData') {
if (data.find(sd => sd.entityName === 'attributes' && sd.noteId === this.ctx.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-29 23:08:30 +02:00
}
}
}
2019-07-21 21:55:48 +02:00
}
export default LinkMapWidget;