mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 09:58:32 +02:00
global link map WIP
This commit is contained in:
parent
dd37f09309
commit
bdde52f004
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
};
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user