Skip to content

Build your personal knowledge base with Trilium Notes

links are now shown in the relation map as well

azivnerfc9495bcdf3c
diff --git a/src/public/javascripts/services/note_detail_relation_map.js b/src/public/javascripts/services/note_detail_relation_map.js
index d763f026f7..8cf1c599ba 100644
--- a/src/public/javascripts/services/note_detail_relation_map.js
+++ b/src/public/javascripts/services/note_detail_relation_map.js
@@ -67,6 +67,14 @@ const mirrorOverlays = [
} ]
];
+const linkOverlays = [
+ [ "Arrow", {
+ location: 1,
+ id: "arrow",
+ length: 14,
+ foldback: 0.8
+ } ]
+];
function loadMapData() {
const currentNote = noteDetailService.getCurrentNote();
@@ -159,6 +167,14 @@ async function loadNotesAndRelations() {
connection.canvas.setAttribute("data-connection-id", connection.id);
}
+
+ for (const link of data.links) {
+ jsPlumbInstance.connect({
+ source: link.sourceNoteId,
+ target: link.targetNoteId,
+ type: 'link'
+ });
+ }
});
}
@@ -253,6 +269,8 @@ function initJsPlumbInstance () {
jsPlumbInstance.registerConnectionType("mirror", { anchor:"Continuous", connector:"StateMachine", overlays: mirrorOverlays });
+ jsPlumbInstance.registerConnectionType("link", { anchor:"Continuous", connector:"StateMachine", overlays: linkOverlays });
+
jsPlumbInstance.bind("connection", connectionCreatedHandler);
// so that canvas is not panned when clicking/dragging note box
@@ -285,7 +303,18 @@ function connectionContextMenuHandler(connection, event) {
async function connectionCreatedHandler(info, originalEvent) {
const connection = info.connection;
- connection.bind("contextmenu", (obj, event) => connectionContextMenuHandler(connection, event));
+ const isRelation = relations.some(rel => rel.attributeId === connection.id);
+
+ connection.bind("contextmenu", (obj, event) => {
+ if (connection.getType().includes("link")) {
+ // don't create context menu if it's a link since there's nothing to do with link from relation map
+ // (don't open browser menu either)
+ event.preventDefault();
+ }
+ else {
+ connectionContextMenuHandler(connection, event);
+ }
+ });
// if there's no event, then this has been triggered programatically
if (!originalEvent) {
diff --git a/src/public/javascripts/services/tooltip.js b/src/public/javascripts/services/tooltip.js
index 863a87527f..d27a7dad00 100644
--- a/src/public/javascripts/services/tooltip.js
+++ b/src/public/javascripts/services/tooltip.js
@@ -108,8 +108,6 @@ async function renderTooltip(note, attributes) {
.prop("src", `/api/images/${note.noteId}/${note.title}`)
.prop("style", "max-width: 300px; max-height: 300px;")
.prop('outerHTML');
-
- console.log(content);
}
// other types of notes don't have tooltip preview
diff --git a/src/routes/api/notes.js b/src/routes/api/notes.js
index 6c3560d0fb..bc6574aa1a 100644
--- a/src/routes/api/notes.js
+++ b/src/routes/api/notes.js
@@ -99,7 +99,8 @@ async function getRelationMap(req) {
noteTitles: {},
relations: [],
// relation name => mirror relation name
- mirrorRelations: {}
+ mirrorRelations: {},
+ links: []
};
if (noteIds.length === 0) {
@@ -129,6 +130,16 @@ async function getRelationMap(req) {
}
}
+ resp.links = (await repository.getEntities(`SELECT * FROM links WHERE isDeleted = 0 AND noteId IN (${questionMarks})`, noteIds))
+ .filter(link => noteIds.includes(link.targetNoteId))
+ .map(link => {
+ return {
+ linkId: link.linkId,
+ sourceNoteId: link.noteId,
+ targetNoteId: link.targetNoteId
+ }
+ });
+
return resp;
}
diff --git a/src/services/notes.js b/src/services/notes.js
index fb29239259..08eb35e1d5 100644
--- a/src/services/notes.js
+++ b/src/services/notes.js
@@ -183,7 +183,7 @@ function findImageLinks(content, foundLinks) {
}
function findHyperLinks(content, foundLinks) {
- const re = /href="#root[a-zA-Z0-9\/]*\/([a-zA-Z0-9]+)\//g;
+ const re = /href="#root[a-zA-Z0-9\/]*\/([a-zA-Z0-9]+)\/?"/g;
let match;
while (match = re.exec(content)) {