2021-05-28 23:19:11 +02:00
|
|
|
import NoteContextAwareWidget from "../note_context_aware_widget.js";
|
|
|
|
import froca from "../../services/froca.js";
|
|
|
|
|
|
|
|
const TPL = `
|
|
|
|
<div class="link-map-widget">
|
2021-05-28 23:52:42 +02:00
|
|
|
<style>
|
|
|
|
.link-map-widget {
|
|
|
|
position: relative;
|
|
|
|
}
|
2021-05-29 22:52:32 +02:00
|
|
|
|
|
|
|
.link-map-container {
|
2021-05-30 23:21:34 +02:00
|
|
|
height: 300px;
|
2021-05-29 22:52:32 +02:00
|
|
|
}
|
2021-05-28 23:52:42 +02:00
|
|
|
|
|
|
|
.open-full-dialog-button {
|
|
|
|
position: absolute;
|
|
|
|
right: 10px;
|
|
|
|
top: 10px;
|
|
|
|
z-index: 1000;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
|
|
|
<button class="bx bx-expand icon-action open-full-dialog-button" title="Show Link Map dialog"></button>
|
|
|
|
|
2021-05-30 23:21:34 +02:00
|
|
|
<div class="link-map-container"></div>
|
2021-05-28 23:19:11 +02:00
|
|
|
</div>`;
|
|
|
|
|
|
|
|
export default class LinkMapWidget extends NoteContextAwareWidget {
|
|
|
|
isEnabled() {
|
|
|
|
return this.note;
|
|
|
|
}
|
|
|
|
|
|
|
|
getTitle() {
|
|
|
|
return {
|
|
|
|
show: this.isEnabled(),
|
|
|
|
title: 'Link Map',
|
|
|
|
icon: 'bx bx-network-chart'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
doRender() {
|
|
|
|
this.$widget = $(TPL);
|
2021-05-28 23:52:42 +02:00
|
|
|
this.$widget.find('.open-full-dialog-button').on('click', () => this.triggerCommand('showLinkMap'));
|
2021-05-28 23:19:11 +02:00
|
|
|
this.overflowing();
|
|
|
|
}
|
|
|
|
|
|
|
|
async refreshWithNote(note) {
|
2021-05-28 23:52:42 +02:00
|
|
|
this.$widget.find(".link-map-container").empty();
|
2021-05-28 23:19:11 +02:00
|
|
|
|
|
|
|
const $linkMapContainer = this.$widget.find('.link-map-container');
|
|
|
|
|
|
|
|
const LinkMapServiceClass = (await import('../../services/link_map.js')).default;
|
|
|
|
|
|
|
|
this.linkMapService = new LinkMapServiceClass(note, $linkMapContainer, {
|
|
|
|
maxDepth: 3,
|
2021-05-30 23:21:34 +02:00
|
|
|
zoom: 0.6,
|
|
|
|
width: $linkMapContainer.width(),
|
|
|
|
height: $linkMapContainer.height()
|
2021-05-28 23:19:11 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
await this.linkMapService.render();
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup() {
|
|
|
|
if (this.linkMapService) {
|
|
|
|
this.linkMapService.cleanup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
entitiesReloadedEvent({loadResults}) {
|
|
|
|
if (loadResults.getAttributes().find(attr => attr.type === 'relation' && (attr.noteId === this.noteId || attr.value === this.noteId))) {
|
|
|
|
this.noteSwitched();
|
|
|
|
}
|
|
|
|
|
|
|
|
const changedNoteIds = loadResults.getNoteIds();
|
|
|
|
|
|
|
|
if (changedNoteIds.length > 0) {
|
|
|
|
const $linkMapContainer = this.$widget.find('.link-map-container');
|
|
|
|
|
|
|
|
for (const noteId of changedNoteIds) {
|
|
|
|
const note = froca.notes[noteId];
|
|
|
|
|
|
|
|
if (note) {
|
|
|
|
$linkMapContainer.find(`a[data-note-path="${noteId}"]`).text(note.title);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|