Skip to content

Build your personal knowledge base with Trilium Notes

refactoring

zadam63e044ffdf6b
diff --git a/src/becca/becca_service.js b/src/becca/becca_service.js
index d4a4269bb9..aad6fff5b8 100644
--- a/src/becca/becca_service.js
+++ b/src/becca/becca_service.js
@@ -82,41 +82,7 @@ function getNoteTitleForPath(notePathArray) {
return titles.join(' / ');
}
-function getNotePath(noteId) {
- const note = becca.notes[noteId];
-
- if (!note) {
- console.trace(`Cannot find note '${noteId}'.`);
- return;
- }
-
- const retPath = note.getBestNotePath();
-
- if (retPath) {
- const noteTitle = getNoteTitleForPath(retPath);
-
- let branchId;
-
- if (note.isRoot()) {
- branchId = 'none_root';
- }
- else {
- const parentNote = note.parents[0];
- branchId = becca.getBranchFromChildAndParent(noteId, parentNote.noteId).branchId;
- }
-
- return {
- noteId: noteId,
- branchId: branchId,
- title: noteTitle,
- notePath: retPath,
- path: retPath.join('/')
- };
- }
-}
-
module.exports = {
- getNotePath,
getNoteTitle,
getNoteTitleForPath,
isNotePathArchived
diff --git a/src/routes/api/note_revisions.js b/src/routes/api/note_revisions.js
index 7448eb7dac..f28239f2e9 100644
--- a/src/routes/api/note_revisions.js
+++ b/src/routes/api/note_revisions.js
@@ -135,7 +135,7 @@ function getEditedNotesOnDate(req) {
notes = notes.map(note => note.getPojo());
for (const note of notes) {
- const notePath = note.isDeleted ? null : beccaService.getNotePath(note.noteId);
+ const notePath = note.isDeleted ? null : getNotePathData(note);
note.notePath = notePath ? notePath.notePath : null;
}
@@ -143,6 +143,32 @@ function getEditedNotesOnDate(req) {
return notes;
}
+function getNotePathData(note) {
+ const retPath = note.getBestNotePath();
+
+ if (retPath) {
+ const noteTitle = beccaService.getNoteTitleForPath(retPath);
+
+ let branchId;
+
+ if (note.isRoot()) {
+ branchId = 'none_root';
+ }
+ else {
+ const parentNote = note.parents[0];
+ branchId = becca.getBranchFromChildAndParent(note.noteId, parentNote.noteId).branchId;
+ }
+
+ return {
+ noteId: note.noteId,
+ branchId: branchId,
+ title: noteTitle,
+ notePath: retPath,
+ path: retPath.join('/')
+ };
+ }
+}
+
module.exports = {
getNoteRevisions,
getNoteRevision,
diff --git a/src/services/cloning.js b/src/services/cloning.js
index b08b3d6b30..f62b8724b3 100644
--- a/src/services/cloning.js
+++ b/src/services/cloning.js
@@ -40,7 +40,7 @@ function cloneNoteToParentNote(noteId, parentNoteId, prefix) {
return {
success: true,
branchId: branch.branchId,
- notePath: `${beccaService.getNotePath(parentNoteId).path}/${noteId}`
+ notePath: `${parentNote.getBestNotePathString()}/${noteId}`
};
}
diff --git a/src/services/search/expressions/note_flat_text.js b/src/services/search/expressions/note_flat_text.js
index 9dbf8ba9cd..62985f5905 100644
--- a/src/services/search/expressions/note_flat_text.js
+++ b/src/services/search/expressions/note_flat_text.js
@@ -26,8 +26,6 @@ class NoteFlatTextExp extends Expression {
if (tokens.length === 0) {
const retPath = this.getNotePath(note, path);
- console.log(retPath);
-
if (retPath) {
const noteId = retPath[retPath.length - 1];