From 6d0218cb3648c087a71c098900835ccb809a950c Mon Sep 17 00:00:00 2001 From: azivner Date: Mon, 5 Mar 2018 23:19:46 -0500 Subject: [PATCH] execute note (ctrl+enter) now works for both frontend and backend scripts --- src/public/javascripts/note_editor.js | 12 ++++++++++-- src/routes/api/script.js | 11 +++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/public/javascripts/note_editor.js b/src/public/javascripts/note_editor.js index a9abb9d90..971f932f0 100644 --- a/src/public/javascripts/note_editor.js +++ b/src/public/javascripts/note_editor.js @@ -298,9 +298,17 @@ const noteEditor = (function() { // make sure note is saved so we load latest changes await saveNoteIfChanged(); - const bundle = await server.get('script/subtree/' + getCurrentNoteId()); + if (currentNote.detail.mime.endsWith("env=frontend")) { + const bundle = await server.get('script/subtree/' + getCurrentNoteId()); - executeBundle(bundle); + executeBundle(bundle); + } + + if (currentNote.detail.mime.endsWith("env=backend")) { + await server.post('script/run/' + getCurrentNoteId()); + } + + showMessage("Note executed"); } } diff --git a/src/routes/api/script.js b/src/routes/api/script.js index 15344fb3f..680796144 100644 --- a/src/routes/api/script.js +++ b/src/routes/api/script.js @@ -16,6 +16,17 @@ router.post('/exec', auth.checkApiAuth, wrap(async (req, res, next) => { }); })); +router.post('/run/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => { + const repository = new Repository(req); + const note = await repository.getNote(req.params.noteId); + + const ret = await script.executeNote(note); + + res.send({ + executionResult: ret + }); +})); + router.get('/startup', auth.checkApiAuth, wrap(async (req, res, next) => { const repository = new Repository(req); const notes = await attributes.getNotesWithAttribute(repository, "run", "frontend_startup");