mirror of
https://github.com/zadam/trilium.git
synced 2025-01-15 19:51:57 +08:00
display properly relations in note map even if they are not in the subtree, closes #2251
This commit is contained in:
parent
ee1b377bc2
commit
50b7063811
3 changed files with 75 additions and 11 deletions
|
@ -764,8 +764,8 @@ class Note extends AbstractEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return {String[]} */
|
/** @return {String[]} */
|
||||||
getSubtreeNoteIds() {
|
getSubtreeNoteIds(includeArchived = true) {
|
||||||
return this.getSubtreeNotes().map(note => note.noteId);
|
return this.getSubtreeNotes(includeArchived).map(note => note.noteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
getDescendantNoteIds() {
|
getDescendantNoteIds() {
|
||||||
|
|
|
@ -332,9 +332,9 @@ export default class NoteMapWidget extends NoteContextAwareWidget {
|
||||||
|
|
||||||
if (this.widgetMode === 'ribbon') {
|
if (this.widgetMode === 'ribbon') {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const node = this.nodes.find(node => node.id === this.noteId);
|
const subGraphNoteIds = this.getSubGraphConnectedToCurrentNote(data);
|
||||||
|
|
||||||
this.graph.centerAt(node.x, node.y, 500);
|
this.graph.zoomToFit(400, 50, node => subGraphNoteIds.has(node.id));
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
else if (this.widgetMode === 'type') {
|
else if (this.widgetMode === 'type') {
|
||||||
|
@ -344,6 +344,39 @@ export default class NoteMapWidget extends NoteContextAwareWidget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getSubGraphConnectedToCurrentNote(data) {
|
||||||
|
function getGroupedLinksBySource(links) {
|
||||||
|
const map = {};
|
||||||
|
|
||||||
|
for (const link of links) {
|
||||||
|
const key = link.source.id;
|
||||||
|
map[key] = map[key] || [];
|
||||||
|
map[key].push(link);
|
||||||
|
}
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
const linksBySource = getGroupedLinksBySource(data.links);
|
||||||
|
|
||||||
|
const subGraphNoteIds = new Set();
|
||||||
|
|
||||||
|
function traverseGraph(noteId) {
|
||||||
|
if (subGraphNoteIds.has(noteId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
subGraphNoteIds.add(noteId);
|
||||||
|
|
||||||
|
for (const link of linksBySource[noteId] || []) {
|
||||||
|
traverseGraph(link.target.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
traverseGraph(this.noteId);
|
||||||
|
return subGraphNoteIds;
|
||||||
|
}
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
this.$container.html('');
|
this.$container.html('');
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,23 +24,54 @@ function buildDescendantCountMap() {
|
||||||
return noteIdToCountMap;
|
return noteIdToCountMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getNeighbors(note, depth) {
|
||||||
|
if (depth === 0) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const retNoteIds = [];
|
||||||
|
|
||||||
|
for (const relation of note.getRelations()) {
|
||||||
|
if (['relationMapLink', 'template', 'image'].includes(relation.name)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const targetNote = relation.getTargetNote();
|
||||||
|
retNoteIds.push(targetNote.noteId);
|
||||||
|
|
||||||
|
for (const noteId of getNeighbors(targetNote, depth - 1)) {
|
||||||
|
retNoteIds.push(noteId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return retNoteIds;
|
||||||
|
}
|
||||||
|
|
||||||
function getLinkMap(req) {
|
function getLinkMap(req) {
|
||||||
const mapRootNote = becca.getNote(req.params.noteId);
|
const mapRootNote = becca.getNote(req.params.noteId);
|
||||||
// if the map root itself has ignore (journal typically) then there wouldn't be anything to display so
|
// if the map root itself has ignore (journal typically) then there wouldn't be anything to display so
|
||||||
// we'll just ignore it
|
// we'll just ignore it
|
||||||
const ignoreExcludeFromNoteMap = mapRootNote.hasLabel('excludeFromNoteMap');
|
const ignoreExcludeFromNoteMap = mapRootNote.hasLabel('excludeFromNoteMap');
|
||||||
|
|
||||||
const noteIds = new Set();
|
const noteIds = new Set(
|
||||||
|
mapRootNote.getSubtreeNotes(false)
|
||||||
|
.filter(note => ignoreExcludeFromNoteMap || !note.hasLabel('excludeFromNoteMap'))
|
||||||
|
.map(note => note.noteId)
|
||||||
|
);
|
||||||
|
|
||||||
const notes = mapRootNote.getSubtreeNotes(false)
|
for (const noteId of getNeighbors(mapRootNote, 3)) {
|
||||||
.filter(note => ignoreExcludeFromNoteMap || !note.hasLabel('excludeFromNoteMap'))
|
noteIds.add(noteId);
|
||||||
.map(note => [
|
}
|
||||||
|
|
||||||
|
const notes = Array.from(noteIds).map(noteId => {
|
||||||
|
const note = becca.getNote(noteId);
|
||||||
|
|
||||||
|
return [
|
||||||
note.noteId,
|
note.noteId,
|
||||||
note.isContentAvailable() ? note.title : '[protected]',
|
note.isContentAvailable() ? note.title : '[protected]',
|
||||||
note.type
|
note.type
|
||||||
]);
|
];
|
||||||
|
});
|
||||||
notes.forEach(([noteId]) => noteIds.add(noteId));
|
|
||||||
|
|
||||||
const links = Object.values(becca.attributes).filter(rel => {
|
const links = Object.values(becca.attributes).filter(rel => {
|
||||||
if (rel.type !== 'relation' || rel.name === 'relationMapLink' || rel.name === 'template') {
|
if (rel.type !== 'relation' || rel.name === 'relationMapLink' || rel.name === 'template') {
|
||||||
|
|
Loading…
Reference in a new issue