Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
global link map WIP
zadambdde52f00400
diff --git a/src/public/app/widgets/type_widgets/global_link_map.js b/src/public/app/widgets/type_widgets/global_link_map.jsindex 042d5b7945..39b0adbb7e 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.jsindex cbd72f5e80..183b5e2842 100644--- a/src/routes/api/link_map.js+++ b/src/routes/api/link_map.js@@ -102,10 +102,25 @@ function buildDescendantCountMap() {}function getGlobalLinkMap() {- const relations = Object.values(becca.attributes).filter(rel => {+ 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 = 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);@@ -114,23 +129,22 @@ function getGlobalLinkMap() {else {return true;}- });-- const noteIdToLinkCountMap = {};-- for (const noteId in becca.notes) {- noteIdToLinkCountMap[noteId] = getRelations(noteId).length;- }-- let links = Array.from(relations).map(rel => ({+ })+ .map(rel => ({id: rel.noteId + "-" + rel.name + "-" + rel.value,sourceNoteId: rel.noteId,targetNoteId: rel.value,name: rel.name}));- links = [];+ return {+ notes: notes,+ noteIdToDescendantCountMap: buildDescendantCountMap(),+ links: links+ };+}+function getGlobalTreeMap() {const noteIds = new Set();const notes = Object.values(becca.notes)@@ -143,6 +157,8 @@ function getGlobalLinkMap() {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.jsindex 262160cc19..5302c83b1e 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);