widgets are respecting positions

This commit is contained in:
zadam 2019-08-26 20:19:14 +02:00
parent 3e3d111d76
commit d039a5f24e
2 changed files with 15 additions and 4 deletions

View file

@ -79,14 +79,23 @@ class Sidebar {
const widget = new widgetClass(this.ctx, options, state);
if (await widget.isEnabled()) {
const $el = await widget.render();
this.widgets.push(widget);
this.$widgetContainer.append($el);
}
}
catch (e) {
messagingService.logError(`Error while loading widget ${widgetClass.name}: ${e.message}`);
messagingService.logError(`Error while creating widget ${widgetClass.name}: ${e.message}`);
}
}
this.widgets.sort((a, b) => a.getPosition() < b.getPosition() ? -1 : 1);
for (const widget of this.widgets) {
try {
const $el = await widget.render();
this.$widgetContainer.append($el);
}
catch (e) {
messagingService.logError(`Error while loading widget ${widget.widgetName}: ${e.message}`);
}
}
}

View file

@ -36,6 +36,8 @@ class StandardWidget {
getMaxHeight() { return null; }
getPosition() { return this.widgetOptions.position; }
async render() {
const widgetId = `tab-${this.ctx.tabId}-widget-${this.widgetName}`;