mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 01:48:32 +02:00
link map section widget
This commit is contained in:
parent
a3d44fbdef
commit
4b6b8b1678
@ -36,6 +36,7 @@ import BasicPropertiesWidget from "../widgets/type_property_widgets/basic_proper
|
||||
import NoteInfoWidget from "../widgets/type_property_widgets/note_info_widget.js";
|
||||
import BookPropertiesWidget from "../widgets/type_property_widgets/book_properties.js";
|
||||
import ShowNoteSourceButton from "../widgets/buttons/show_note_source.js";
|
||||
import LinkMapWidget from "../widgets/type_property_widgets/link_map.js";
|
||||
|
||||
export default class DesktopLayout {
|
||||
constructor(customWidgets) {
|
||||
@ -111,6 +112,7 @@ export default class DesktopLayout {
|
||||
.section(new PromotedAttributesWidget())
|
||||
.section(new OwnedAttributeListWidget())
|
||||
.section(new InheritedAttributesWidget())
|
||||
.section(new LinkMapWidget())
|
||||
.section(new NoteInfoWidget())
|
||||
.button(new ButtonWidget()
|
||||
.icon('bx bx-history')
|
||||
|
@ -47,7 +47,6 @@ export default class BasicPropertiesWidget extends NoteContextAwareWidget {
|
||||
getTitle() {
|
||||
return {
|
||||
show: this.isEnabled(),
|
||||
activate: true,
|
||||
title: 'Basic Properties',
|
||||
icon: 'bx bx-slider'
|
||||
};
|
||||
|
73
src/public/app/widgets/type_property_widgets/link_map.js
Normal file
73
src/public/app/widgets/type_property_widgets/link_map.js
Normal file
@ -0,0 +1,73 @@
|
||||
import NoteContextAwareWidget from "../note_context_aware_widget.js";
|
||||
import froca from "../../services/froca.js";
|
||||
|
||||
const TPL = `
|
||||
<div class="link-map-widget">
|
||||
<div class="link-map-container" style="height: 300px;"></div>
|
||||
</div>`;
|
||||
|
||||
let linkMapContainerIdCtr = 1;
|
||||
|
||||
export default class LinkMapWidget extends NoteContextAwareWidget {
|
||||
static getType() { return "link-map"; }
|
||||
|
||||
isEnabled() {
|
||||
return this.note;
|
||||
}
|
||||
|
||||
getTitle() {
|
||||
return {
|
||||
show: this.isEnabled(),
|
||||
title: 'Link Map',
|
||||
icon: 'bx bx-network-chart'
|
||||
};
|
||||
}
|
||||
|
||||
doRender() {
|
||||
this.$widget = $(TPL);
|
||||
this.overflowing();
|
||||
}
|
||||
|
||||
async refreshWithNote(note) {
|
||||
this.$widget.html(TPL);
|
||||
|
||||
const $linkMapContainer = this.$widget.find('.link-map-container');
|
||||
$linkMapContainer.attr("id", "link-map-container-" + linkMapContainerIdCtr++);
|
||||
|
||||
const LinkMapServiceClass = (await import('../../services/link_map.js')).default;
|
||||
|
||||
this.linkMapService = new LinkMapServiceClass(note, $linkMapContainer, {
|
||||
maxDepth: 3,
|
||||
zoom: 0.6,
|
||||
stopCheckerCallback: () => this.noteId !== note.noteId // stop when current note is not what was originally requested
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -71,7 +71,6 @@ export default class NoteInfoWidget extends NoteContextAwareWidget {
|
||||
getTitle() {
|
||||
return {
|
||||
show: this.isEnabled(),
|
||||
activate: true,
|
||||
title: 'Note Info',
|
||||
icon: 'bx bx-info-circle'
|
||||
};
|
||||
|
@ -210,7 +210,7 @@ export default class SearchDefinitionWidget extends NoteContextAwareWidget {
|
||||
return {
|
||||
show: this.isEnabled(),
|
||||
activate: true,
|
||||
title: 'Search',
|
||||
title: 'Search parameters',
|
||||
icon: 'bx bx-search'
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user