Skip to content

Build your personal knowledge base with Trilium Notes

support passing functions to the backend as parameters

azivnerddc885066e88
diff --git a/src/public/javascripts/server.js b/src/public/javascripts/server.js
index 60898c649d..8d3002d06c 100644
--- a/src/public/javascripts/server.js
+++ b/src/public/javascripts/server.js
@@ -31,12 +31,23 @@ const server = (function() {
return await call('DELETE', url);
}
+ function prepareParams(params) {
+ return params.map(p => {
+ if (typeof p === "function") {
+ return "!@#Function: " + p.toString();
+ }
+ else {
+ return p;
+ }
+ });
+ }
+
async function exec(params, script) {
if (typeof script === "function") {
script = script.toString();
}
- const ret = await post('script/exec', { script: script, params: params });
+ const ret = await post('script/exec', { script: script, params: prepareParams(params) });
return ret.executionResult;
}
diff --git a/src/scripts/weight.html b/src/scripts/weight.html
index f22049f356..b3ae26702a 100644
--- a/src/scripts/weight.html
+++ b/src/scripts/weight.html
@@ -117,16 +117,11 @@
return data;
});
- const colors = data.map(row => row.comment ? 'darkred' : 'red');
-
const datasets = [{
label: "Weight",
backgroundColor: 'red',
borderColor: 'red',
data: data.map(row => row.weight),
- // this is to emphasize points with color
- pointBackgroundColor: colors,
- pointBorderColor: colors,
fill: false
}];
diff --git a/src/services/script.js b/src/services/script.js
index ec02f37c96..9b860d49d9 100644
--- a/src/services/script.js
+++ b/src/services/script.js
@@ -19,7 +19,14 @@ async function executeScript(dataKey, script, params) {
}
function getParams(params) {
- return params.map(p => JSON.stringify(p)).join(",");
+ return params.map(p => {
+ if (typeof p === "string" && p.startsWith("!@#Function: ")) {
+ return p.substr(13);
+ }
+ else {
+ return JSON.stringify(p);
+ }
+ }).join(",");
}
module.exports = {