global link map WIP

This commit is contained in:
zadam 2021-09-20 20:02:23 +02:00
parent dd37f09309
commit bdde52f004
3 changed files with 57 additions and 34 deletions

View File

@ -219,7 +219,7 @@ export default class GlobalLinkMapTypeWidget extends TypeWidget {
this.linkIdToLinkMap = {}; this.linkIdToLinkMap = {};
this.noteIdToLinkCountMap = {}; this.noteIdToLinkCountMap = {};
const resp = await server.post(`global-link-map`); const resp = await server.post(`note-map/${this.mapType}`);
this.noteIdToLinkCountMap = resp.noteIdToLinkCountMap; this.noteIdToLinkCountMap = resp.noteIdToLinkCountMap;
@ -291,11 +291,17 @@ export default class GlobalLinkMapTypeWidget extends TypeWidget {
this.graph.graphData(data); this.graph.graphData(data);
if (zoomToFit && data.nodes.length > 1) { if (zoomToFit && data.nodes.length > 1) {
setTimeout(() => this.graph.zoomToFit(400, zoomPadding), 1000); setTimeout(() => this.graph.zoomToFit(400, zoomPadding), 3000);
} }
} }
cleanup() { cleanup() {
this.$container.html(''); this.$container.html('');
} }
entitiesReloadedEvent({loadResults}) {
if (loadResults.getAttributes(this.componentId).find(attr => attr.name === 'mapType' && attributeService.isAffecting(attr, this.note))) {
this.refresh();
}
}
} }

View File

@ -102,35 +102,6 @@ function buildDescendantCountMap() {
} }
function getGlobalLinkMap() { 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 noteIds = new Set();
const notes = Object.values(becca.notes) const notes = Object.values(becca.notes)
@ -143,6 +114,51 @@ function getGlobalLinkMap() {
notes.forEach(([noteId]) => noteIds.add(noteId)); 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)) { for (const branch of Object.values(becca.branches)) {
if (!noteIds.has(branch.parentNoteId) || !noteIds.has(branch.noteId)) { if (!noteIds.has(branch.parentNoteId) || !noteIds.has(branch.noteId)) {
continue; continue;
@ -158,7 +174,6 @@ function getGlobalLinkMap() {
return { return {
notes: notes, notes: notes,
noteIdToLinkCountMap,
noteIdToDescendantCountMap: buildDescendantCountMap(), noteIdToDescendantCountMap: buildDescendantCountMap(),
links: links links: links
}; };
@ -166,5 +181,6 @@ function getGlobalLinkMap() {
module.exports = { module.exports = {
getLinkMap, getLinkMap,
getGlobalLinkMap getGlobalLinkMap,
getGlobalTreeMap
}; };

View File

@ -221,7 +221,8 @@ function register(app) {
apiRoute(GET, '/api/attributes/values/:attributeName', attributesRoute.getValuesForAttribute); apiRoute(GET, '/api/attributes/values/:attributeName', attributesRoute.getValuesForAttribute);
apiRoute(POST, '/api/notes/:noteId/link-map', linkMapRoute.getLinkMap); 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/inbox/:date', specialNotesRoute.getInboxNote);
apiRoute(GET, '/api/special-notes/date/:date', specialNotesRoute.getDateNote); apiRoute(GET, '/api/special-notes/date/:date', specialNotesRoute.getDateNote);