Skip to content

Build your personal knowledge base with Trilium Notes

prefixes are now displayed also in all autocompletes and recent notes

azivner8bd76721ad43
diff --git a/public/javascripts/dialogs/jump_to_note.js b/public/javascripts/dialogs/jump_to_note.js
index 7810f1afc2..ad115d69a5 100644
--- a/public/javascripts/dialogs/jump_to_note.js
+++ b/public/javascripts/dialogs/jump_to_note.js
@@ -60,8 +60,10 @@ const jumpToNote = (function() {
noteDetailEl.summernote('editor.restoreRange');
+ const noteId = treeUtils.getNoteIdFromNotePath(notePath);
+
noteDetailEl.summernote('createLink', {
- text: noteTree.getNoteTitle(notePath),
+ text: noteTree.getNoteTitle(noteId),
url: 'app#' + notePath,
isNewWindow: true
});
diff --git a/public/javascripts/dialogs/recent_notes.js b/public/javascripts/dialogs/recent_notes.js
index a1efcbbff3..afe85f6429 100644
--- a/public/javascripts/dialogs/recent_notes.js
+++ b/public/javascripts/dialogs/recent_notes.js
@@ -48,7 +48,7 @@ const recentNotes = (function() {
const recNotes = list.filter(note => note !== noteTree.getCurrentNotePath());
$.each(recNotes, (key, valueNotePath) => {
- const noteTitle = treeUtils.getFullNameForPath(valueNotePath);
+ const noteTitle = noteTree.getNotePathTitle(valueNotePath);
const option = $("<option></option>")
.attr("value", valueNotePath)
@@ -82,8 +82,9 @@ const recentNotes = (function() {
function addLinkBasedOnRecentNotes() {
const notePath = getSelectedNotePath();
+ const noteId = treeUtils.getNoteIdFromNotePath(notePath);
- const linkTitle = noteTree.getNoteTitle(notePath);
+ const linkTitle = noteTree.getNoteTitle(noteId);
dialogEl.dialog("close");
diff --git a/public/javascripts/link.js b/public/javascripts/link.js
index 036c0865bb..27e2c5fd14 100644
--- a/public/javascripts/link.js
+++ b/public/javascripts/link.js
@@ -22,8 +22,10 @@ const link = (function() {
return null;
}
- function createNoteLink(noteId, noteTitle) {
+ function createNoteLink(notePath, noteTitle) {
if (!noteTitle) {
+ const noteId = treeUtils.getNoteIdFromNotePath(notePath);
+
noteTitle = noteTree.getNoteTitle(noteId);
}
@@ -31,7 +33,7 @@ const link = (function() {
href: 'javascript:',
text: noteTitle
}).attr('action', 'note')
- .attr('note-path', noteId);
+ .attr('note-path', notePath);
return noteLink;
}
diff --git a/public/javascripts/note_tree.js b/public/javascripts/note_tree.js
index d193f8f133..a600da6c7c 100644
--- a/public/javascripts/note_tree.js
+++ b/public/javascripts/note_tree.js
@@ -5,7 +5,6 @@ const noteTree = (function() {
const parentListEl = $("#parent-list");
let startNoteTreeId = null;
- let treeLoadTime = null;
let notesTreeMap = {};
let parentToChildren = {};
@@ -14,32 +13,33 @@ const noteTree = (function() {
let parentChildToNoteTreeId = {};
let noteIdToTitle = {};
- function getTreeLoadTime() {
- return treeLoadTime;
- }
-
function getNoteTreeId(parentNoteId, childNoteId) {
const key = parentNoteId + "-" + childNoteId;
- const noteTreeId = parentChildToNoteTreeId[key];
-
- if (!noteTreeId) {
- console.trace();
-
- throw new Error("Can't find note tree id for parent=" + parentNoteId + ", child=" + childNoteId);
- }
+ // this can return undefined and client code should deal with it somehow
- return noteTreeId;
+ return parentChildToNoteTreeId[key];
}
- function getNoteTitle(notePath) {
- const noteId = treeUtils.getNoteIdFromNotePath(notePath);
- const title = noteIdToTitle[noteId];
+ function getNoteTitle(noteId, parentNoteId = null) {
+ let title = noteIdToTitle[noteId];
if (!title) {
throw new Error("Can't find title for noteId='" + noteId + "'");
}
+ if (parentNoteId !== null) {
+ const noteTreeId = getNoteTreeId(parentNoteId, noteId);
+
+ if (noteTreeId) {
+ const noteTree = notesTreeMap[noteTreeId];
+
+ if (noteTree.prefix) {
+ title = noteTree.prefix + ' - ' + title;
+ }
+ }
+ }
+
return title;
}
@@ -286,8 +286,12 @@ const noteTree = (function() {
function getNotePathTitle(notePath) {
const titlePath = [];
- for (const path of notePath.split('/')) {
- titlePath.push(getNoteTitle(path));
+ let parentNoteId = 'root';
+
+ for (const noteId of notePath.split('/')) {
+ titlePath.push(getNoteTitle(noteId, parentNoteId));
+
+ parentNoteId = noteId;
}
return titlePath.join(' / ');
@@ -476,7 +480,6 @@ const noteTree = (function() {
function loadTree() {
return server.get('tree').then(resp => {
startNoteTreeId = resp.start_note_tree_id;
- treeLoadTime = resp.tree_load_time;
if (document.location.hash) {
startNoteTreeId = document.location.hash.substr(1); // strip initial #
@@ -531,7 +534,7 @@ const noteTree = (function() {
for (const childNoteId of parentToChildren[parentNoteId]) {
const childNotePath = (notePath ? (notePath + '/') : '') + childNoteId;
- const childTitlePath = (titlePath ? (titlePath + ' / ') : '') + getNoteTitle(childNoteId);
+ const childTitlePath = (titlePath ? (titlePath + ' / ') : '') + getNoteTitle(childNoteId, parentNoteId);
autocompleteItems.push({
value: childTitlePath + ' (' + childNotePath + ')',
@@ -608,7 +611,6 @@ const noteTree = (function() {
}
return {
- getTreeLoadTime,
reload,
collapseTree,
scrollToCurrentNote,
@@ -623,6 +625,6 @@ const noteTree = (function() {
createNewTopLevelNote,
createNote,
setPrefix,
- getNodesByNoteTreeId
+ getNotePathTitle
};
})();
\ No newline at end of file
diff --git a/public/javascripts/server.js b/public/javascripts/server.js
index e8f53bf274..05ac046cbf 100644
--- a/public/javascripts/server.js
+++ b/public/javascripts/server.js
@@ -67,7 +67,7 @@ const server = (function() {
}
return await $.ajax(options).catch(e => {
- showError("Error when calling " + method + " " + url + ": " + e);
+ showError("Error when calling " + method + " " + url + ": " + e.status + " - " + e.statusText);
});
}
diff --git a/public/javascripts/tree_utils.js b/public/javascripts/tree_utils.js
index 247320195f..c144065e2e 100644
--- a/public/javascripts/tree_utils.js
+++ b/public/javascripts/tree_utils.js
@@ -17,13 +17,6 @@ const treeUtils = (function() {
return path[path.length - 1];
}
- function getFullNameForPath(notePath) {
- const path = notePath.split("/");
- const titlePath = path.map(noteId => noteTree.getNoteTitle(noteId));
-
- return titlePath.join(" > ");
- }
-
function getNotePath(node) {
const path = [];
@@ -50,7 +43,6 @@ const treeUtils = (function() {
return {
getParentProtectedStatus,
getNodeByKey,
- getFullNameForPath,
getNotePath,
getNoteIdFromNotePath,
setNodeTitleWithPrefix
diff --git a/routes/api/tree.js b/routes/api/tree.js
index 85adf4b379..ad6ca27df4 100644
--- a/routes/api/tree.js
+++ b/routes/api/tree.js
@@ -31,8 +31,7 @@ router.get('/', auth.checkApiAuth, async (req, res, next) => {
res.send({
notes: notes,
- start_note_tree_id: await options.getOption('start_note_tree_id'),
- tree_load_time: utils.nowTimestamp()
+ start_note_tree_id: await options.getOption('start_note_tree_id')
});
});