Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
changing title directly from relation map
azivner639284fd8534
diff --git a/src/entities/note.js b/src/entities/note.jsindex 005ef1ad82..68d6598605 100644--- a/src/entities/note.js+++ b/src/entities/note.js@@ -36,9 +36,14 @@ class Note extends Entity {super(row);this.isProtected = !!this.isProtected;+ /* true if content (meaning any kind of potentially encrypted content) is either not encrypted+ * or encrypted, but with available protected session (so effectively decrypted) */+ this.isContentAvailable = true;// check if there's noteId, otherwise this is a new entity which wasn't encrypted yetif (this.isProtected && this.noteId) {+ this.isContentAvailable = protectedSessionService.isProtectedSessionAvailable();+protectedSessionService.decryptNote(this);}diff --git a/src/public/javascripts/services/note_detail_relation_map.js b/src/public/javascripts/services/note_detail_relation_map.jsindex 39c5f72e99..2b5c286ab8 100644--- a/src/public/javascripts/services/note_detail_relation_map.js+++ b/src/public/javascripts/services/note_detail_relation_map.js@@ -2,6 +2,7 @@ import server from "./server.js";import noteDetailService from "./note_detail.js";import linkService from "./link.js";import libraryLoader from "./library_loader.js";+import treeService from "./tree.js";const $noteDetailRelationMap = $("#note-detail-relation-map");const $relationMapCanvas = $("#relation-map-canvas");@@ -267,18 +268,18 @@ async function noteContextMenuHandler(event, ui) {saveData();}else if (ui.cmd === "edit-title") {- const title = prompt("Enter new note title:");+ const $title = $noteBox.find(".title a");+ const title = prompt("Enter new note title:", $title.text());if (!title) {return;}- const note = mapData.notes.find(note => note.id === noteId);- note.title = title;+ await server.put(`notes/${noteId}/change-title`, { title });- $noteBox.find(".title").text(note.title);+ treeService.setNoteTitle(noteId, title);- saveData();+ $title.text(title);}}diff --git a/src/routes/api/notes.js b/src/routes/api/notes.jsindex 60c8f260ae..20413d0cf8 100644--- a/src/routes/api/notes.js+++ b/src/routes/api/notes.js@@ -122,6 +122,25 @@ async function getRelationMap(req) {return resp;}+async function changeTitle(req) {+ const noteId = req.params.noteId;+ const title = req.body.title;++ const note = await repository.getNote(noteId);++ if (!note) {+ return [404, `Note ${noteId} has not been found`];+ }++ if (!note.isContentAvailable) {+ return [400, `Note ${noteId} is not available for change`];+ }++ note.title = title;++ await note.save();+}+module.exports = {getNote,updateNote,@@ -130,5 +149,6 @@ module.exports = {protectSubtree,setNoteTypeMime,getChildren,- getRelationMap+ getRelationMap,+ changeTitle};\ No newline at end of filediff --git a/src/routes/routes.js b/src/routes/routes.jsindex e500202b91..187c8eec5f 100644--- a/src/routes/routes.js+++ b/src/routes/routes.js@@ -122,6 +122,7 @@ function register(app) {apiRoute(PUT, /\/api\/notes\/(.*)\/type\/(.*)\/mime\/(.*)/, notesApiRoute.setNoteTypeMime);apiRoute(GET, '/api/notes/:noteId/revisions', noteRevisionsApiRoute.getNoteRevisions);apiRoute(POST, '/api/notes/relation-map', notesApiRoute.getRelationMap);+ apiRoute(PUT, '/api/notes/:noteId/change-title', notesApiRoute.changeTitle);apiRoute(PUT, '/api/notes/:noteId/clone-to/:parentNoteId', cloningApiRoute.cloneNoteToParent);apiRoute(PUT, '/api/notes/:noteId/clone-after/:afterBranchId', cloningApiRoute.cloneNoteAfter);diff --git a/src/services/notes.js b/src/services/notes.jsindex 03054af70b..b48506bb0a 100644--- a/src/services/notes.js+++ b/src/services/notes.js@@ -222,6 +222,10 @@ async function saveNoteRevision(note) {async function updateNote(noteId, noteUpdates) {const note = await repository.getNote(noteId);+ if (!note.isContentAvailable) {+ throw new Error(`Note ${noteId} is not available for change!`);+ }+if (note.type === 'file') {// for update file, newNote doesn't contain file payloadsnoteUpdates.content = note.content;diff --git a/src/services/repository.js b/src/services/repository.jsindex 7021bbe093..c7720cfb52 100644--- a/src/services/repository.js+++ b/src/services/repository.js@@ -78,6 +78,7 @@ async function updateEntity(entity) {delete clone.isOwned;delete clone.isChanged;delete clone.origParentNoteId;+ delete clone.isContentAvailable;delete clone.__attributeCache;for (const key in clone) {