widget can be also enabled/disabled using labels

This commit is contained in:
zadam 2019-09-01 09:52:07 +02:00
parent 0c78fda531
commit 3ca37b2f42
3 changed files with 14 additions and 6 deletions

View File

@ -14,7 +14,6 @@ class Sidebar {
widgets: [] widgets: []
}, state); }, state);
this.widgets = []; this.widgets = [];
this.rendered = false;
this.$sidebar = ctx.$tabContent.find(".note-detail-sidebar"); this.$sidebar = ctx.$tabContent.find(".note-detail-sidebar");
this.$widgetContainer = this.$sidebar.find(".note-detail-widget-container"); this.$widgetContainer = this.$sidebar.find(".note-detail-widget-container");
this.$showSideBarButton = this.ctx.$tabContent.find(".show-sidebar-button"); this.$showSideBarButton = this.ctx.$tabContent.find(".show-sidebar-button");
@ -54,8 +53,10 @@ class Sidebar {
} }
for (const widget of this.widgets) { for (const widget of this.widgets) {
if (widget.cleanup) {
widget.cleanup(); widget.cleanup();
} }
}
this.widgets = []; this.widgets = [];
this.$widgetContainer.empty(); this.$widgetContainer.empty();
@ -100,7 +101,7 @@ class Sidebar {
this.$widgetContainer.append($el); this.$widgetContainer.append($el);
} }
catch (e) { catch (e) {
ws.logError(`Error while loading widget ${widget.widgetName}: ${e.message}`); ws.logError(`Error while rendering widget ${widget.widgetName}: ${e.message}`);
} }
} }
} }

View File

@ -11,8 +11,6 @@ class SimilarNotesWidget extends StandardWidget {
async doRenderBody() { async doRenderBody() {
const similarNoteIds = await server.get('similar_notes/' + this.ctx.note.noteId); const similarNoteIds = await server.get('similar_notes/' + this.ctx.note.noteId);
console.log(similarNoteIds);
if (similarNoteIds.length === 0) { if (similarNoteIds.length === 0) {
this.$body.text("No similar notes found ..."); this.$body.text("No similar notes found ...");
return; return;

View File

@ -89,8 +89,17 @@ class StandardWidget {
async doRenderBody() {} async doRenderBody() {}
async isEnabled() { async isEnabled() {
const label = await this.ctx.note.getLabelValue(this.widgetName);
if (label === 'enabled') {
return true;
} else if (label === 'disabled') {
return false;
}
else {
return this.widgetOptions.enabled; return this.widgetOptions.enabled;
} }
}
isExpanded() { isExpanded() {
return this.$bodyWrapper.hasClass("show"); return this.$bodyWrapper.hasClass("show");