diff --git a/src/public/javascripts/services/sidebar.js b/src/public/javascripts/services/sidebar.js index 030934f85..905c15f46 100644 --- a/src/public/javascripts/services/sidebar.js +++ b/src/public/javascripts/services/sidebar.js @@ -1,3 +1,23 @@ +import NoteInfoWidget from "../widgets/note_info.js"; + +const WIDGET_TPL = ` +
+`; + +let widgetIdCtr = 1; + class Sidebar { /** * @param {TabContext} ctx @@ -5,6 +25,7 @@ class Sidebar { constructor(ctx) { this.ctx = ctx; this.$sidebar = ctx.$tabContent.find(".note-detail-sidebar"); + this.$widgets = this.$sidebar.find(".note-detail-widgets"); this.$showSideBarButton = this.ctx.$tabContent.find(".show-sidebar-button"); this.$showSideBarButton.hide(); @@ -18,7 +39,35 @@ class Sidebar { this.$showSideBarButton.click(() => { this.$sidebar.show(); this.$showSideBarButton.hide(); - }) + }); + } + + async noteLoaded() { + this.$widgets.empty(); + + this.addNoteInfoWidget(); + this.addNoteInfoWidget(); + } + + async addNoteInfoWidget() { + const $widget = this.createWidgetElement(); + + const noteInfoWidget = new NoteInfoWidget(this.ctx, $widget); + await noteInfoWidget.renderBody(); + + console.log($widget); + + this.$widgets.append($widget); + } + + createWidgetElement() { + const widgetId = 'widget-' + widgetIdCtr++; + + const $widget = $(WIDGET_TPL); + $widget.find('[data-target]').attr('data-target', "#" + widgetId); + $widget.find('.body-wrapper').attr('id', widgetId); + + return $widget; } } diff --git a/src/public/javascripts/services/tab_context.js b/src/public/javascripts/services/tab_context.js index a12cf5908..5751a54f8 100644 --- a/src/public/javascripts/services/tab_context.js +++ b/src/public/javascripts/services/tab_context.js @@ -60,9 +60,9 @@ class TabContext { this.noteChangeDisabled = false; this.isNoteChanged = false; this.attributes = new Attributes(this); - this.sidebar = new Sidebar(this); if (utils.isDesktop()) { + this.sidebar = new Sidebar(this); this.noteType = new NoteTypeContext(this); } @@ -133,6 +133,10 @@ class TabContext { this.showPaths(); + if (this.sidebar) { + this.sidebar.noteLoaded(); + } + console.debug(`Switched tab ${this.tabId} to ${this.noteId}`); } diff --git a/src/public/javascripts/widgets/note_info.js b/src/public/javascripts/widgets/note_info.js new file mode 100644 index 000000000..d412a3ca2 --- /dev/null +++ b/src/public/javascripts/widgets/note_info.js @@ -0,0 +1,59 @@ +const TPL = ` +Note ID | ++ |
---|---|
Created | ++ |
Modified | ++ |
Type | ++ |
MIME | ++ |