From bdde52f00400400e437dfbd89c7bf3c74a0bcb9c Mon Sep 17 00:00:00 2001 From: zadam Date: Mon, 20 Sep 2021 20:02:23 +0200 Subject: [PATCH] global link map WIP --- .../widgets/type_widgets/global_link_map.js | 10 ++- src/routes/api/link_map.js | 78 +++++++++++-------- src/routes/routes.js | 3 +- 3 files changed, 57 insertions(+), 34 deletions(-) diff --git a/src/public/app/widgets/type_widgets/global_link_map.js b/src/public/app/widgets/type_widgets/global_link_map.js index 042d5b794..39b0adbb7 100644 --- a/src/public/app/widgets/type_widgets/global_link_map.js +++ b/src/public/app/widgets/type_widgets/global_link_map.js @@ -219,7 +219,7 @@ export default class GlobalLinkMapTypeWidget extends TypeWidget { this.linkIdToLinkMap = {}; this.noteIdToLinkCountMap = {}; - const resp = await server.post(`global-link-map`); + const resp = await server.post(`note-map/${this.mapType}`); this.noteIdToLinkCountMap = resp.noteIdToLinkCountMap; @@ -291,11 +291,17 @@ export default class GlobalLinkMapTypeWidget extends TypeWidget { this.graph.graphData(data); if (zoomToFit && data.nodes.length > 1) { - setTimeout(() => this.graph.zoomToFit(400, zoomPadding), 1000); + setTimeout(() => this.graph.zoomToFit(400, zoomPadding), 3000); } } cleanup() { this.$container.html(''); } + + entitiesReloadedEvent({loadResults}) { + if (loadResults.getAttributes(this.componentId).find(attr => attr.name === 'mapType' && attributeService.isAffecting(attr, this.note))) { + this.refresh(); + } + } } diff --git a/src/routes/api/link_map.js b/src/routes/api/link_map.js index cbd72f5e8..183b5e284 100644 --- a/src/routes/api/link_map.js +++ b/src/routes/api/link_map.js @@ -102,35 +102,6 @@ function buildDescendantCountMap() { } function getGlobalLinkMap() { - const relations = Object.values(becca.attributes).filter(rel => { - if (rel.type !== 'relation' || rel.name === 'relationMapLink' || rel.name === 'template') { - return false; - } - else if (rel.name === 'imageLink') { - const parentNote = becca.getNote(rel.noteId); - - return !parentNote.getChildNotes().find(childNote => childNote.noteId === rel.value); - } - else { - return true; - } - }); - - const noteIdToLinkCountMap = {}; - - for (const noteId in becca.notes) { - noteIdToLinkCountMap[noteId] = getRelations(noteId).length; - } - - let links = Array.from(relations).map(rel => ({ - id: rel.noteId + "-" + rel.name + "-" + rel.value, - sourceNoteId: rel.noteId, - targetNoteId: rel.value, - name: rel.name - })); - - links = []; - const noteIds = new Set(); const notes = Object.values(becca.notes) @@ -143,6 +114,51 @@ function getGlobalLinkMap() { notes.forEach(([noteId]) => noteIds.add(noteId)); + const links = Object.values(becca.attributes).filter(rel => { + if (rel.type !== 'relation' || rel.name === 'relationMapLink' || rel.name === 'template') { + return false; + } + else if (!noteIds.has(rel.noteId) || !noteIds.has(rel.value)) { + return false; + } + else if (rel.name === 'imageLink') { + const parentNote = becca.getNote(rel.noteId); + + return !parentNote.getChildNotes().find(childNote => childNote.noteId === rel.value); + } + else { + return true; + } + }) + .map(rel => ({ + id: rel.noteId + "-" + rel.name + "-" + rel.value, + sourceNoteId: rel.noteId, + targetNoteId: rel.value, + name: rel.name + })); + + return { + notes: notes, + noteIdToDescendantCountMap: buildDescendantCountMap(), + links: links + }; +} + +function getGlobalTreeMap() { + const noteIds = new Set(); + + const notes = Object.values(becca.notes) + .filter(note => !note.isArchived) + .map(note => [ + note.noteId, + note.isContentAvailable() ? note.title : '[protected]', + note.type + ]); + + notes.forEach(([noteId]) => noteIds.add(noteId)); + + const links = []; + for (const branch of Object.values(becca.branches)) { if (!noteIds.has(branch.parentNoteId) || !noteIds.has(branch.noteId)) { continue; @@ -158,7 +174,6 @@ function getGlobalLinkMap() { return { notes: notes, - noteIdToLinkCountMap, noteIdToDescendantCountMap: buildDescendantCountMap(), links: links }; @@ -166,5 +181,6 @@ function getGlobalLinkMap() { module.exports = { getLinkMap, - getGlobalLinkMap + getGlobalLinkMap, + getGlobalTreeMap }; diff --git a/src/routes/routes.js b/src/routes/routes.js index 262160cc1..5302c83b1 100644 --- a/src/routes/routes.js +++ b/src/routes/routes.js @@ -221,7 +221,8 @@ function register(app) { apiRoute(GET, '/api/attributes/values/:attributeName', attributesRoute.getValuesForAttribute); apiRoute(POST, '/api/notes/:noteId/link-map', linkMapRoute.getLinkMap); - apiRoute(POST, '/api/global-link-map', linkMapRoute.getGlobalLinkMap); + apiRoute(POST, '/api/note-map/tree', linkMapRoute.getGlobalTreeMap); + apiRoute(POST, '/api/note-map/link', linkMapRoute.getGlobalLinkMap); apiRoute(GET, '/api/special-notes/inbox/:date', specialNotesRoute.getInboxNote); apiRoute(GET, '/api/special-notes/date/:date', specialNotesRoute.getDateNote);