mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	added "restore this revision" button
This commit is contained in:
		| @@ -82,6 +82,21 @@ async function setContentPane() { | ||||
|  | ||||
|     $title.html(revisionItem.title); | ||||
|  | ||||
|     const $restoreRevisionButton = $('<button class="btn btn-sm" type="button">Restore this revision</button>'); | ||||
|  | ||||
|     $restoreRevisionButton.on('click', async () => { | ||||
|         const confirmDialog = await import('../dialogs/confirm.js'); | ||||
|         const text = 'Do you want to restore this revision? This will overwrite current title/content of the note with this revision.'; | ||||
|  | ||||
|         if (await confirmDialog.confirm(text)) { | ||||
|             await server.put(`notes/${revisionItem.noteId}/restore-revision/${revisionItem.noteRevisionId}`); | ||||
|  | ||||
|             $dialog.modal('hide'); | ||||
|  | ||||
|             toastService.showMessage('Note revision has been restored.'); | ||||
|         } | ||||
|     }); | ||||
|  | ||||
|     const $eraseRevisionButton = $('<button class="btn btn-sm" type="button">Delete this revision</button>'); | ||||
|  | ||||
|     $eraseRevisionButton.on('click', async () => { | ||||
| @@ -98,6 +113,8 @@ async function setContentPane() { | ||||
|     }); | ||||
|  | ||||
|     $titleButtons | ||||
|         .append($restoreRevisionButton) | ||||
|         .append('   ') | ||||
|         .append($eraseRevisionButton) | ||||
|         .append('   '); | ||||
|  | ||||
|   | ||||
| @@ -3,6 +3,7 @@ | ||||
| const repository = require('../../services/repository'); | ||||
| const noteCacheService = require('../../services/note_cache'); | ||||
| const protectedSessionService = require('../../services/protected_session'); | ||||
| const noteRevisionService = require('../../services/note_revisions'); | ||||
| const utils = require('../../services/utils'); | ||||
| const path = require('path'); | ||||
|  | ||||
| @@ -109,6 +110,20 @@ async function eraseNoteRevision(req) { | ||||
|     } | ||||
| } | ||||
|  | ||||
| async function restoreNoteRevision(req) { | ||||
|     const noteRevision = await repository.getNoteRevision(req.params.noteRevisionId); | ||||
|  | ||||
|     if (noteRevision && !noteRevision.isErased) { | ||||
|         const note = await noteRevision.getNote(); | ||||
|  | ||||
|         await noteRevisionService.createNoteRevision(note); | ||||
|  | ||||
|         note.title = noteRevision.title; | ||||
|         await note.setContent(await noteRevision.getContent()); | ||||
|         await note.save(); | ||||
|     } | ||||
| } | ||||
|  | ||||
| async function getEditedNotesOnDate(req) { | ||||
|     const date = utils.sanitizeSql(req.params.date); | ||||
|  | ||||
| @@ -141,5 +156,6 @@ module.exports = { | ||||
|     downloadNoteRevision, | ||||
|     getEditedNotesOnDate, | ||||
|     eraseAllNoteRevisions, | ||||
|     eraseNoteRevision | ||||
|     eraseNoteRevision, | ||||
|     restoreNoteRevision | ||||
| }; | ||||
| @@ -145,6 +145,7 @@ function register(app) { | ||||
|     apiRoute(GET, '/api/notes/:noteId/revisions/:noteRevisionId', noteRevisionsApiRoute.getNoteRevision); | ||||
|     apiRoute(DELETE, '/api/notes/:noteId/revisions/:noteRevisionId', noteRevisionsApiRoute.eraseNoteRevision); | ||||
|     route(GET, '/api/notes/:noteId/revisions/:noteRevisionId/download', [auth.checkApiAuthOrElectron], noteRevisionsApiRoute.downloadNoteRevision); | ||||
|     apiRoute(PUT, '/api/notes/:noteId/restore-revision/:noteRevisionId', noteRevisionsApiRoute.restoreNoteRevision); | ||||
|     apiRoute(POST, '/api/notes/relation-map', notesApiRoute.getRelationMap); | ||||
|     apiRoute(PUT, '/api/notes/:noteId/change-title', notesApiRoute.changeTitle); | ||||
|     apiRoute(POST, '/api/notes/:noteId/duplicate/:parentNoteId', notesApiRoute.duplicateNote); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user