From 4b6b8b1678ed0f03881bec124223129e3bda17fb Mon Sep 17 00:00:00 2001 From: zadam Date: Fri, 28 May 2021 23:19:11 +0200 Subject: [PATCH] link map section widget --- src/public/app/layouts/desktop_layout.js | 2 + .../type_property_widgets/basic_properties.js | 1 - .../widgets/type_property_widgets/link_map.js | 73 +++++++++++++++++++ .../type_property_widgets/note_info_widget.js | 1 - .../search_definition.js | 2 +- 5 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 src/public/app/widgets/type_property_widgets/link_map.js diff --git a/src/public/app/layouts/desktop_layout.js b/src/public/app/layouts/desktop_layout.js index 7d67067f7..07af6c5bd 100644 --- a/src/public/app/layouts/desktop_layout.js +++ b/src/public/app/layouts/desktop_layout.js @@ -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') diff --git a/src/public/app/widgets/type_property_widgets/basic_properties.js b/src/public/app/widgets/type_property_widgets/basic_properties.js index 83587cc59..747969d75 100644 --- a/src/public/app/widgets/type_property_widgets/basic_properties.js +++ b/src/public/app/widgets/type_property_widgets/basic_properties.js @@ -47,7 +47,6 @@ export default class BasicPropertiesWidget extends NoteContextAwareWidget { getTitle() { return { show: this.isEnabled(), - activate: true, title: 'Basic Properties', icon: 'bx bx-slider' }; diff --git a/src/public/app/widgets/type_property_widgets/link_map.js b/src/public/app/widgets/type_property_widgets/link_map.js new file mode 100644 index 000000000..1822ef40e --- /dev/null +++ b/src/public/app/widgets/type_property_widgets/link_map.js @@ -0,0 +1,73 @@ +import NoteContextAwareWidget from "../note_context_aware_widget.js"; +import froca from "../../services/froca.js"; + +const TPL = ` +`; + +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); + } + } + } + } +} diff --git a/src/public/app/widgets/type_property_widgets/note_info_widget.js b/src/public/app/widgets/type_property_widgets/note_info_widget.js index 4b7d06c86..a234cb631 100644 --- a/src/public/app/widgets/type_property_widgets/note_info_widget.js +++ b/src/public/app/widgets/type_property_widgets/note_info_widget.js @@ -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' }; diff --git a/src/public/app/widgets/type_property_widgets/search_definition.js b/src/public/app/widgets/type_property_widgets/search_definition.js index aa483b9a4..b0116e434 100644 --- a/src/public/app/widgets/type_property_widgets/search_definition.js +++ b/src/public/app/widgets/type_property_widgets/search_definition.js @@ -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' }; }