loading of custom widgets

This commit is contained in:
zadam
2019-08-17 11:28:36 +02:00
parent 53c4bb8a94
commit fd9b79e115
7 changed files with 63 additions and 12 deletions

View File

@@ -2,6 +2,8 @@ import NoteInfoWidget from "../widgets/note_info.js";
import LinkMapWidget from "../widgets/link_map.js";
import NoteRevisionsWidget from "../widgets/note_revisions.js";
import AttributesWidget from "../widgets/attributes.js";
import bundleService from "./bundle.js";
import messagingService from "./messaging.js";
class Sidebar {
/**
@@ -9,6 +11,7 @@ class Sidebar {
* @param {object} state
*/
constructor(ctx, state = {}) {
/** @property {TabContext} */
this.ctx = ctx;
this.state = state;
this.widgets = [];
@@ -51,15 +54,27 @@ class Sidebar {
const widgetClasses = [AttributesWidget, LinkMapWidget, NoteRevisionsWidget, NoteInfoWidget];
const widgetRelations = await this.ctx.note.getRelations('widget');
for (const widgetRelation of widgetRelations) {
const widgetClass = await bundleService.getAndExecuteBundle(widgetRelation.value, this.ctx.note);
widgetClasses.push(widgetClass);
}
for (const widgetClass of widgetClasses) {
const state = (this.state.widgets || []).find(s => s.name === widgetClass.name);
const widget = new widgetClass(this.ctx, state);
this.widgets.push(widget);
try {
const widget = new widgetClass(this.ctx, state);
await widget.renderBody();
widget.renderBody(); // let it run in parallel
this.$widgetContainer.append(widget.getWidgetElement());
this.widgets.push(widget);
this.$widgetContainer.append(widget.getWidgetElement());
}
catch (e) {
messagingService.logError(`Error while loading widget ${widgetClass.name}: ${e.message}`);
}
}
}