mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
note map refactoring
This commit is contained in:
parent
a766374bf4
commit
e3fc0968ba
@ -233,46 +233,11 @@ export default class NoteMapWidget extends NoteContextAwareWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async loadNotesAndRelations(mapRootNoteId) {
|
async loadNotesAndRelations(mapRootNoteId) {
|
||||||
this.linkIdToLinkMap = {};
|
|
||||||
this.noteIdToLinkCountMap = {};
|
|
||||||
|
|
||||||
const resp = await server.post(`note-map/${mapRootNoteId}/${this.mapType}`);
|
const resp = await server.post(`note-map/${mapRootNoteId}/${this.mapType}`);
|
||||||
|
|
||||||
this.noteIdToLinkCountMap = resp.noteIdToLinkCountMap;
|
this.calculateSizes(resp);
|
||||||
|
|
||||||
this.calculateSizes(resp.noteIdToDescendantCountMap);
|
const links = this.getGroupedLinks(resp.links);
|
||||||
|
|
||||||
for (const link of resp.links) {
|
|
||||||
this.linkIdToLinkMap[link.id] = link;
|
|
||||||
}
|
|
||||||
|
|
||||||
const noteIdToLinkIdMap = {};
|
|
||||||
noteIdToLinkIdMap[this.noteId] = new Set(); // for case there are no relations
|
|
||||||
const linksGroupedBySourceTarget = {};
|
|
||||||
|
|
||||||
for (const link of Object.values(this.linkIdToLinkMap)) {
|
|
||||||
noteIdToLinkIdMap[link.sourceNoteId] = noteIdToLinkIdMap[link.sourceNoteId] || new Set();
|
|
||||||
noteIdToLinkIdMap[link.sourceNoteId].add(link.id);
|
|
||||||
|
|
||||||
noteIdToLinkIdMap[link.targetNoteId] = noteIdToLinkIdMap[link.targetNoteId] || new Set();
|
|
||||||
noteIdToLinkIdMap[link.targetNoteId].add(link.id);
|
|
||||||
|
|
||||||
const key = `${link.sourceNoteId}-${link.targetNoteId}`;
|
|
||||||
|
|
||||||
if (key in linksGroupedBySourceTarget) {
|
|
||||||
if (!linksGroupedBySourceTarget[key].names.includes(link.name)) {
|
|
||||||
linksGroupedBySourceTarget[key].names.push(link.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
linksGroupedBySourceTarget[key] = {
|
|
||||||
id: key,
|
|
||||||
sourceNoteId: link.sourceNoteId,
|
|
||||||
targetNoteId: link.targetNoteId,
|
|
||||||
names: [link.name]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.nodes = resp.notes.map(([noteId, title, type]) => ({
|
this.nodes = resp.notes.map(([noteId, title, type]) => ({
|
||||||
id: noteId,
|
id: noteId,
|
||||||
@ -282,7 +247,7 @@ export default class NoteMapWidget extends NoteContextAwareWidget {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
nodes: this.nodes,
|
nodes: this.nodes,
|
||||||
links: Object.values(linksGroupedBySourceTarget).map(link => ({
|
links: links.map(link => ({
|
||||||
id: link.id,
|
id: link.id,
|
||||||
source: link.sourceNoteId,
|
source: link.sourceNoteId,
|
||||||
target: link.targetNoteId,
|
target: link.targetNoteId,
|
||||||
@ -291,7 +256,32 @@ export default class NoteMapWidget extends NoteContextAwareWidget {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
calculateSizes(noteIdToDescendantCountMap) {
|
getGroupedLinks(links) {
|
||||||
|
const linksGroupedBySourceTarget = {};
|
||||||
|
|
||||||
|
for (const link of links) {
|
||||||
|
const key = `${link.sourceNoteId}-${link.targetNoteId}`;
|
||||||
|
|
||||||
|
if (key in linksGroupedBySourceTarget) {
|
||||||
|
if (!linksGroupedBySourceTarget[key].names.includes(link.name)) {
|
||||||
|
linksGroupedBySourceTarget[key].names.push(link.name);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
linksGroupedBySourceTarget[key] = {
|
||||||
|
id: key,
|
||||||
|
sourceNoteId: link.sourceNoteId,
|
||||||
|
targetNoteId: link.targetNoteId,
|
||||||
|
names: [link.name]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Object.values(linksGroupedBySourceTarget);
|
||||||
|
}
|
||||||
|
|
||||||
|
calculateSizes(resp) {
|
||||||
|
const {noteIdToDescendantCountMap} = resp;
|
||||||
|
|
||||||
this.noteIdToSizeMap = {};
|
this.noteIdToSizeMap = {};
|
||||||
|
|
||||||
for (const noteId in noteIdToDescendantCountMap) {
|
for (const noteId in noteIdToDescendantCountMap) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user