Skip to content

Build your personal knowledge base with Trilium Notes

link map fixes

zadamff1d312a43e7
diff --git a/src/public/javascripts/dialogs/link_map.js b/src/public/javascripts/dialogs/link_map.js
index 4beeda536f..8c78e1b813 100644
--- a/src/public/javascripts/dialogs/link_map.js
+++ b/src/public/javascripts/dialogs/link_map.js
@@ -4,21 +4,24 @@ import noteDetailService from "../services/note_detail.js";
const $linkMapContainer = $("#link-map-container");
-const LINK_TYPES = [ "hyper", "image", "relation", "relation-map" ];
-
const $dialog = $("#link-map-dialog");
const $maxNotesInput = $("#link-map-max-notes");
let linkMapService;
+function getOptions() {
+ return {
+ maxNotes: $maxNotesInput.val()
+ };
+}
+
export async function showDialog() {
utils.closeActiveDialog();
glob.activeDialog = $dialog;
// set default settings
- $maxNotesInput.val(10);
- LINK_TYPES.forEach(lt => $("#link-map-" + lt).prop('checked', true));
+ $maxNotesInput.val(20);
const note = noteDetailService.getActiveNote();
@@ -28,12 +31,11 @@ export async function showDialog() {
$linkMapContainer.css("height", $("body").height() - 150);
- linkMapService = new LinkMapService(note, $linkMapContainer);
+ linkMapService = new LinkMapService(note, $linkMapContainer, getOptions());
+
linkMapService.render();
$dialog.modal();
}
-$(".link-map-settings").change(() => linkMapService.loadNotesAndRelations());
-
-$maxNotesInput.on("input", () => linkMapService.loadNotesAndRelations());
+$maxNotesInput.on("input", () => linkMapService.loadNotesAndRelations(getOptions()));
diff --git a/src/public/javascripts/services/link_map.js b/src/public/javascripts/services/link_map.js
index 395a4d99d9..0d776da79b 100644
--- a/src/public/javascripts/services/link_map.js
+++ b/src/public/javascripts/services/link_map.js
@@ -18,6 +18,7 @@ export default class LinkMap {
this.note = note;
this.options = $.extend({
maxDepth: 10,
+ maxNotes: 30,
zoom: 1.0
}, options);
@@ -37,13 +38,13 @@ export default class LinkMap {
});
}
- async loadNotesAndRelations() {
- this.cleanup();
+ async loadNotesAndRelations(options = {}) {
+ this.options = $.extend(this.options, options);
- const maxNotes = 50;
+ this.cleanup();
const links = await server.post(`notes/${this.note.noteId}/link-map`, {
- maxNotes,
+ maxNotes: this.options.maxNotes,
maxDepth: this.options.maxDepth
});
diff --git a/src/routes/api/link_map.js b/src/routes/api/link_map.js
index f5704409bb..15d4862cf4 100644
--- a/src/routes/api/link_map.js
+++ b/src/routes/api/link_map.js
@@ -2,13 +2,15 @@
const sql = require('../../services/sql');
-async function getRelations(noteIds, relationNames) {
+async function getRelations(noteIds) {
return (await sql.getManyRows(`
SELECT noteId, name, value AS targetNoteId
FROM attributes
WHERE (noteId IN (???) OR value IN (???))
AND type = 'relation'
AND isDeleted = 0
+ AND noteId != ''
+ AND value != ''
`, Array.from(noteIds)));
}
@@ -35,9 +37,9 @@ async function getLinkMap(req) {
// no new note discovered, no need to search any further
break;
}
-
+ console.log(newNoteIds.size, maxNotes);
if (newNoteIds.size > maxNotes) {
- // to many notes to display
+ // too many notes to display
break;
}
diff --git a/src/services/notes.js b/src/services/notes.js
index 25eb1a336a..d9611c2e9b 100644
--- a/src/services/notes.js
+++ b/src/services/notes.js
@@ -280,7 +280,7 @@ async function saveLinks(note, content) {
noteId: note.noteId,
type: 'relation',
name: foundLink.name,
- value: foundLink.targetNoteId,
+ value: foundLink.value,
}).save();
}
else if (existingLink.isDeleted) {
diff --git a/src/views/dialogs/link_map.ejs b/src/views/dialogs/link_map.ejs
index b97bef0179..bfaeb8b7c8 100644
--- a/src/views/dialogs/link_map.ejs
+++ b/src/views/dialogs/link_map.ejs
@@ -5,32 +5,12 @@
<h5 class="modal-title" style="width: auto;">Link map</h5>
<div style="vertical-align: middle;">
- <div class="form-check form-check-inline">
- <input class="form-check-input link-map-settings" type="checkbox" id="link-map-hyper">
- <label class="form-check-label" for="link-map-hyper">text links</label>
- </div>
-
- <div class="form-check form-check-inline">
- <input class="form-check-input link-map-settings" type="checkbox" id="link-map-image">
- <label class="form-check-label" for="link-map-image">image links</label>
- </div>
-
- <div class="form-check form-check-inline">
- <input class="form-check-input link-map-settings" type="checkbox" id="link-map-relation">
- <label class="form-check-label" for="link-map-relation">relations</label>
- </div>
-
- <div class="form-check form-check-inline">
- <input class="form-check-input link-map-settings" type="checkbox" id="link-map-relation-map">
- <label class="form-check-label" for="link-map-relation-map">relation map links</label>
- </div>
-
<div style="display: inline-block; position: relative; top: -3px;">
<label for="link-map-max-notes" title="Max number of displayed notes">
<strong>max notes:</strong>
</label>
- <input id="link-map-max-notes" type="number" value="50" min="5" max="1000" step="5"
+ <input id="link-map-max-notes" type="number" value="20" min="5" max="1000" step="5"
class="form-control form-control-sm"
style="width: 80px; display: inline-block; text-align: right;"/>
</div>