Skip to content

Build your personal knowledge base with Trilium Notes

refactored targetNote to workNote in the ScriptContext which was very confusing with relation's targetNote

azivner6dc934abbe12
diff --git a/src/public/javascripts/services/bundle.js b/src/public/javascripts/services/bundle.js
index d5fc5e1b2b..87866aa891 100644
--- a/src/public/javascripts/services/bundle.js
+++ b/src/public/javascripts/services/bundle.js
@@ -1,14 +1,14 @@
import ScriptContext from "./script_context.js";
import server from "./server.js";
-async function getAndExecuteBundle(noteId, targetNote = null) {
+async function getAndExecuteBundle(noteId, workNote = null) {
const bundle = await server.get('script/bundle/' + noteId);
- await executeBundle(bundle, targetNote);
+ await executeBundle(bundle, workNote);
}
-async function executeBundle(bundle, targetNote) {
- const apiContext = ScriptContext(bundle.note, bundle.allNotes, targetNote);
+async function executeBundle(bundle, workNote) {
+ const apiContext = ScriptContext(bundle.note, bundle.allNotes, workNote);
return await (function () {
return eval(`const apiContext = this; (async function() { ${bundle.script}\r\n})()`);
diff --git a/src/public/javascripts/services/script_api.js b/src/public/javascripts/services/script_api.js
index 7183da5ab8..88d6ac45d8 100644
--- a/src/public/javascripts/services/script_api.js
+++ b/src/public/javascripts/services/script_api.js
@@ -4,7 +4,7 @@ import utils from './utils.js';
import infoService from './info.js';
import linkService from './link.js';
-function ScriptApi(startNote, currentNote, targetNote = null) {
+function ScriptApi(startNote, currentNote, workNote = null) {
const $pluginButtons = $("#plugin-buttons");
async function activateNote(notePath) {
@@ -44,7 +44,7 @@ function ScriptApi(startNote, currentNote, targetNote = null) {
params: prepareParams(params),
startNoteId: startNote.noteId,
currentNoteId: currentNote.noteId,
- targetNoteId: targetNote ? targetNote.noteId : null
+ workNoteId: workNote ? workNote.noteId : null
});
return ret.executionResult;
@@ -53,7 +53,7 @@ function ScriptApi(startNote, currentNote, targetNote = null) {
return {
startNote: startNote,
currentNote: currentNote,
- targetNote: targetNote,
+ workNote: workNote,
addButtonToToolbar,
activateNote,
getInstanceName: () => window.glob.instanceName,
diff --git a/src/public/javascripts/services/script_context.js b/src/public/javascripts/services/script_context.js
index afd372aab2..78a3cffd55 100644
--- a/src/public/javascripts/services/script_context.js
+++ b/src/public/javascripts/services/script_context.js
@@ -1,13 +1,13 @@
import ScriptApi from './script_api.js';
import utils from './utils.js';
-function ScriptContext(startNote, allNotes, targetNote = null) {
+function ScriptContext(startNote, allNotes, workNote = null) {
const modules = {};
return {
modules: modules,
notes: utils.toObject(allNotes, note => [note.noteId, note]),
- apis: utils.toObject(allNotes, note => [note.noteId, ScriptApi(startNote, note, targetNote)]),
+ apis: utils.toObject(allNotes, note => [note.noteId, ScriptApi(startNote, note, workNote)]),
require: moduleNoteIds => {
return moduleName => {
const candidates = allNotes.filter(note => moduleNoteIds.includes(note.noteId));
diff --git a/src/routes/api/script.js b/src/routes/api/script.js
index de50c753e0..d5e6483979 100644
--- a/src/routes/api/script.js
+++ b/src/routes/api/script.js
@@ -7,7 +7,7 @@ const repository = require('../../services/repository');
async function exec(req) {
const result = await scriptService.executeScript(req.body.script, req.body.params, req.body.startNoteId,
- req.body.currentNoteId, req.body.targetNoteId);
+ req.body.currentNoteId, req.body.workNoteId);
return { executionResult: result };
}
diff --git a/src/scripts/Edited files on day.tar b/src/scripts/Edited files on day.tar
index f1fa3b61ec..66e34b8739 100644
Binary files a/src/scripts/Edited files on day.tar and b/src/scripts/Edited files on day.tar differ
diff --git a/src/services/script.js b/src/services/script.js
index 2a5939e923..b75063849e 100644
--- a/src/services/script.js
+++ b/src/services/script.js
@@ -14,7 +14,7 @@ async function executeNote(note, targetNote) {
await executeBundle(bundle, note, targetNote);
}
-async function executeBundle(bundle, startNote, targetNote = null) {
+async function executeBundle(bundle, startNote, workNote = null) {
if (!startNote) {
// this is the default case, the only exception is when we want to preserve frontend startNote
startNote = bundle.note;
@@ -23,7 +23,7 @@ async function executeBundle(bundle, startNote, targetNote = null) {
// last \r\n is necessary if script contains line comment on its last line
const script = "async function() {\r\n" + bundle.script + "\r\n}";
- const ctx = new ScriptContext(startNote, bundle.allNotes, targetNote);
+ const ctx = new ScriptContext(startNote, bundle.allNotes, workNote);
if (await bundle.note.hasLabel('manualTransactionHandling')) {
return await execute(ctx, script, '');
diff --git a/src/services/script_context.js b/src/services/script_context.js
index 6ab8c258af..52669d49ff 100644
--- a/src/services/script_context.js
+++ b/src/services/script_context.js
@@ -10,10 +10,10 @@ const config = require('./config');
const repository = require('./repository');
const axios = require('axios');
-function ScriptContext(startNote, allNotes, targetNote = null) {
+function ScriptContext(startNote, allNotes, workNote = null) {
this.modules = {};
this.notes = utils.toObject(allNotes, note => [note.noteId, note]);
- this.apis = utils.toObject(allNotes, note => [note.noteId, new ScriptApi(startNote, note, targetNote)]);
+ this.apis = utils.toObject(allNotes, note => [note.noteId, new ScriptApi(startNote, note, workNote)]);
this.require = moduleNoteIds => {
return moduleName => {
const candidates = allNotes.filter(note => moduleNoteIds.includes(note.noteId));
@@ -28,10 +28,10 @@ function ScriptContext(startNote, allNotes, targetNote = null) {
};
}
-function ScriptApi(startNote, currentNote, targetNote) {
+function ScriptApi(startNote, currentNote, workNote) {
this.startNote = startNote;
this.currentNote = currentNote;
- this.targetNote = targetNote;
+ this.workNote = workNote;
this.axios = axios;