support passing functions to the backend as parameters

This commit is contained in:
azivner 2018-02-18 09:53:36 -05:00
parent 08bc2afb49
commit ddc885066e
3 changed files with 20 additions and 7 deletions

View File

@ -31,12 +31,23 @@ const server = (function() {
return await call('DELETE', url); 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) { async function exec(params, script) {
if (typeof script === "function") { if (typeof script === "function") {
script = script.toString(); 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; return ret.executionResult;
} }

View File

@ -117,16 +117,11 @@
return data; return data;
}); });
const colors = data.map(row => row.comment ? 'darkred' : 'red');
const datasets = [{ const datasets = [{
label: "Weight", label: "Weight",
backgroundColor: 'red', backgroundColor: 'red',
borderColor: 'red', borderColor: 'red',
data: data.map(row => row.weight), data: data.map(row => row.weight),
// this is to emphasize points with color
pointBackgroundColor: colors,
pointBorderColor: colors,
fill: false fill: false
}]; }];

View File

@ -19,7 +19,14 @@ async function executeScript(dataKey, script, params) {
} }
function getParams(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 = { module.exports = {