add keyboard action to force creating note revisions, #2147

This commit is contained in:
zadam 2022-11-08 22:36:15 +01:00
parent bf4776a33c
commit 60fc621cd4
4 changed files with 33 additions and 1 deletions

View File

@ -201,4 +201,12 @@ export default class Entrypoints extends Component {
activeContextChangedEvent() { activeContextChangedEvent() {
this.hideAllTooltips(); this.hideAllTooltips();
} }
async forceSaveNoteRevisionCommand() {
const noteId = appContext.tabManager.getActiveContextNoteId();
await server.post(`notes/${noteId}/revision`);
toastService.showMessage("Note revision has been created.");
}
} }

View File

@ -6,6 +6,7 @@ const sql = require('../../services/sql');
const utils = require('../../services/utils'); const utils = require('../../services/utils');
const log = require('../../services/log'); const log = require('../../services/log');
const TaskContext = require('../../services/task_context'); const TaskContext = require('../../services/task_context');
const protectedSessionService = require('../../services/protected_session');
const fs = require('fs'); const fs = require('fs');
const becca = require("../../becca/becca"); const becca = require("../../becca/becca");
@ -305,6 +306,21 @@ function uploadModifiedFile(req) {
note.setContent(fileContent); note.setContent(fileContent);
} }
function forceSaveNoteRevision(req) {
const {noteId} = req.params;
const note = becca.getNote(noteId);
if (!note) {
return [404, `Note ${noteId} not found.`];
}
if (!note.isContentAvailable()) {
return [400, `Note revision of a protected note cannot be created outside of a protected session.`];
}
note.saveNoteRevision();
}
module.exports = { module.exports = {
getNote, getNote,
updateNoteContent, updateNoteContent,
@ -319,5 +335,6 @@ module.exports = {
duplicateSubtree, duplicateSubtree,
eraseDeletedNotesNow, eraseDeletedNotesNow,
getDeleteNotesPreview, getDeleteNotesPreview,
uploadModifiedFile uploadModifiedFile,
forceSaveNoteRevision
}; };

View File

@ -254,6 +254,7 @@ function register(app) {
apiRoute(PUT, '/api/notes/:noteId/content', notesApiRoute.updateNoteContent); apiRoute(PUT, '/api/notes/:noteId/content', notesApiRoute.updateNoteContent);
apiRoute(DELETE, '/api/notes/:noteId', notesApiRoute.deleteNote); apiRoute(DELETE, '/api/notes/:noteId', notesApiRoute.deleteNote);
apiRoute(PUT, '/api/notes/:noteId/undelete', notesApiRoute.undeleteNote); apiRoute(PUT, '/api/notes/:noteId/undelete', notesApiRoute.undeleteNote);
apiRoute(POST, '/api/notes/:noteId/revision', notesApiRoute.forceSaveNoteRevision);
apiRoute(POST, '/api/notes/:parentNoteId/children', notesApiRoute.createNote); apiRoute(POST, '/api/notes/:parentNoteId/children', notesApiRoute.createNote);
apiRoute(PUT, '/api/notes/:noteId/sort-children', notesApiRoute.sortChildNotes); apiRoute(PUT, '/api/notes/:noteId/sort-children', notesApiRoute.sortChildNotes);
apiRoute(PUT, '/api/notes/:noteId/protect/:isProtected', notesApiRoute.protectNote); apiRoute(PUT, '/api/notes/:noteId/protect/:isProtected', notesApiRoute.protectNote);

View File

@ -500,6 +500,12 @@ const DEFAULT_KEYBOARD_ACTIONS = [
defaultShortcuts: ["CommandOrControl+Alt+C"], defaultShortcuts: ["CommandOrControl+Alt+C"],
description: "Copy selected text without formatting", description: "Copy selected text without formatting",
scope: "text-detail" scope: "text-detail"
},
{
actionName: "forceSaveNoteRevision",
defaultShortcuts: [],
description: "Force creating / saving new note revision of the active note",
scope: "window"
} }
]; ];