basic support for custom widgets

This commit is contained in:
zadam
2020-03-16 21:16:09 +01:00
parent 8ae78a9e23
commit 173030e02e
14 changed files with 99 additions and 22 deletions

View File

@@ -1,6 +1,7 @@
import ScriptContext from "./script_context.js";
import server from "./server.js";
import toastService from "./toast.js";
import treeCache from "./tree_cache.js";
async function getAndExecuteBundle(noteId, originEntity = null) {
const bundle = await server.get('script/bundle/' + noteId);
@@ -29,8 +30,40 @@ async function executeStartupBundles() {
}
}
async function getWidgetBundlesByParent() {
const scriptBundles = await server.get("script/widgets");
const byParent = {};
for (const bundle of scriptBundles) {
let widget;
try {
widget = await executeBundle(bundle);
}
catch (e) {
console.error("Widget initialization failed: ", e);
continue;
}
if (!widget.getParentWidget) {
console.log(`Custom widget does not have mandatory 'getParent()' method defined`);
continue;
}
const parentWidgetName = widget.getParentWidget();
byParent[parentWidgetName] = byParent[parentWidgetName] || [];
byParent[parentWidgetName].push(widget);
}
return byParent;
}
export default {
executeBundle,
getAndExecuteBundle,
executeStartupBundles
executeStartupBundles,
getWidgetBundlesByParent
}