mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	changing title directly from relation map
This commit is contained in:
		| @@ -36,9 +36,14 @@ class Note extends Entity { | |||||||
|         super(row); |         super(row); | ||||||
|  |  | ||||||
|         this.isProtected = !!this.isProtected; |         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 yet |         // check if there's noteId, otherwise this is a new entity which wasn't encrypted yet | ||||||
|         if (this.isProtected && this.noteId) { |         if (this.isProtected && this.noteId) { | ||||||
|  |             this.isContentAvailable = protectedSessionService.isProtectedSessionAvailable(); | ||||||
|  |  | ||||||
|             protectedSessionService.decryptNote(this); |             protectedSessionService.decryptNote(this); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -2,6 +2,7 @@ import server from "./server.js"; | |||||||
| import noteDetailService from "./note_detail.js"; | import noteDetailService from "./note_detail.js"; | ||||||
| import linkService from "./link.js"; | import linkService from "./link.js"; | ||||||
| import libraryLoader from "./library_loader.js"; | import libraryLoader from "./library_loader.js"; | ||||||
|  | import treeService from "./tree.js"; | ||||||
|  |  | ||||||
| const $noteDetailRelationMap = $("#note-detail-relation-map"); | const $noteDetailRelationMap = $("#note-detail-relation-map"); | ||||||
| const $relationMapCanvas = $("#relation-map-canvas"); | const $relationMapCanvas = $("#relation-map-canvas"); | ||||||
| @@ -267,18 +268,18 @@ async function noteContextMenuHandler(event, ui) { | |||||||
|         saveData(); |         saveData(); | ||||||
|     } |     } | ||||||
|     else if (ui.cmd === "edit-title") { |     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) { |         if (!title) { | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         const note = mapData.notes.find(note => note.id === noteId); |         await server.put(`notes/${noteId}/change-title`, { title }); | ||||||
|         note.title = title; |  | ||||||
|  |  | ||||||
|         $noteBox.find(".title").text(note.title); |         treeService.setNoteTitle(noteId, title); | ||||||
|  |  | ||||||
|         saveData(); |         $title.text(title); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -122,6 +122,25 @@ async function getRelationMap(req) { | |||||||
|     return resp; |     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 = { | module.exports = { | ||||||
|     getNote, |     getNote, | ||||||
|     updateNote, |     updateNote, | ||||||
| @@ -130,5 +149,6 @@ module.exports = { | |||||||
|     protectSubtree, |     protectSubtree, | ||||||
|     setNoteTypeMime, |     setNoteTypeMime, | ||||||
|     getChildren, |     getChildren, | ||||||
|     getRelationMap |     getRelationMap, | ||||||
|  |     changeTitle | ||||||
| }; | }; | ||||||
| @@ -122,6 +122,7 @@ function register(app) { | |||||||
|     apiRoute(PUT, /\/api\/notes\/(.*)\/type\/(.*)\/mime\/(.*)/, notesApiRoute.setNoteTypeMime); |     apiRoute(PUT, /\/api\/notes\/(.*)\/type\/(.*)\/mime\/(.*)/, notesApiRoute.setNoteTypeMime); | ||||||
|     apiRoute(GET, '/api/notes/:noteId/revisions', noteRevisionsApiRoute.getNoteRevisions); |     apiRoute(GET, '/api/notes/:noteId/revisions', noteRevisionsApiRoute.getNoteRevisions); | ||||||
|     apiRoute(POST, '/api/notes/relation-map', notesApiRoute.getRelationMap); |     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-to/:parentNoteId', cloningApiRoute.cloneNoteToParent); | ||||||
|     apiRoute(PUT, '/api/notes/:noteId/clone-after/:afterBranchId', cloningApiRoute.cloneNoteAfter); |     apiRoute(PUT, '/api/notes/:noteId/clone-after/:afterBranchId', cloningApiRoute.cloneNoteAfter); | ||||||
|   | |||||||
| @@ -222,6 +222,10 @@ async function saveNoteRevision(note) { | |||||||
| async function updateNote(noteId, noteUpdates) { | async function updateNote(noteId, noteUpdates) { | ||||||
|     const note = await repository.getNote(noteId); |     const note = await repository.getNote(noteId); | ||||||
|  |  | ||||||
|  |     if (!note.isContentAvailable) { | ||||||
|  |         throw new Error(`Note ${noteId} is not available for change!`); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     if (note.type === 'file') { |     if (note.type === 'file') { | ||||||
|         // for update file, newNote doesn't contain file payloads |         // for update file, newNote doesn't contain file payloads | ||||||
|         noteUpdates.content = note.content; |         noteUpdates.content = note.content; | ||||||
|   | |||||||
| @@ -78,6 +78,7 @@ async function updateEntity(entity) { | |||||||
|     delete clone.isOwned; |     delete clone.isOwned; | ||||||
|     delete clone.isChanged; |     delete clone.isChanged; | ||||||
|     delete clone.origParentNoteId; |     delete clone.origParentNoteId; | ||||||
|  |     delete clone.isContentAvailable; | ||||||
|     delete clone.__attributeCache; |     delete clone.__attributeCache; | ||||||
|  |  | ||||||
|     for (const key in clone) { |     for (const key in clone) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user