From 28cb3976e5035100a733ae195b7edd5b951ba17f Mon Sep 17 00:00:00 2001 From: zadam Date: Mon, 12 Oct 2020 23:15:53 +0200 Subject: [PATCH] add explicit button to show/hide right pane widgets, #1299 --- .idea/codeStyles/Project.xml | 18 +++++++ .../app/layouts/desktop_main_window_layout.js | 11 ++++ src/public/app/widgets/collapsible_widget.js | 53 +++++++++++++++---- 3 files changed, 72 insertions(+), 10 deletions(-) diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index cbf929386..042c7e7c1 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -9,5 +9,23 @@ + + + + \ No newline at end of file diff --git a/src/public/app/layouts/desktop_main_window_layout.js b/src/public/app/layouts/desktop_main_window_layout.js index 4ba9cf127..60c1d82ef 100644 --- a/src/public/app/layouts/desktop_main_window_layout.js +++ b/src/public/app/layouts/desktop_main_window_layout.js @@ -77,6 +77,17 @@ const RIGHT_PANE_CSS = ` text-decoration: none; } +#right-pane .widget-toggle-button { + cursor: pointer; + color: var(--main-text-color) !important; + position: relative; + top: 2px; +} + +#right-pane .widget-toggle-button:hover { + text-decoration: none !important; +} + #right-pane .body-wrapper { overflow: auto; } diff --git a/src/public/app/widgets/collapsible_widget.js b/src/public/app/widgets/collapsible_widget.js index 1784d4a2a..414f850b4 100644 --- a/src/public/app/widgets/collapsible_widget.js +++ b/src/public/app/widgets/collapsible_widget.js @@ -5,14 +5,20 @@ const WIDGET_TPL = `
- - - + + +
-
+
+ +   + +
@@ -38,13 +44,18 @@ export default class CollapsibleWidget extends TabAwareWidget { // not using constructor name because of webpack mangling class names ... this.widgetName = this.widgetTitle.replace(/[^[a-zA-Z0-9]/g, "_"); - if (!options.is(this.widgetName + 'Collapsed')) { + this.$toggleButton = this.$widget.find('.widget-toggle-button'); + + const collapsed = options.is(this.widgetName + 'Collapsed'); + if (!collapsed) { this.$bodyWrapper.collapse("show"); } + this.updateToggleButton(collapsed); + // using immediate variants of the event so that the previous collapse is not caught - this.$bodyWrapper.on('hide.bs.collapse', () => this.saveCollapsed(true)); - this.$bodyWrapper.on('show.bs.collapse', () => this.saveCollapsed(false)); + this.$bodyWrapper.on('hide.bs.collapse', () => this.toggleCollapsed(true)); + this.$bodyWrapper.on('show.bs.collapse', () => this.toggleCollapsed(false)); this.$body = this.$bodyWrapper.find('.card-body'); @@ -66,19 +77,41 @@ export default class CollapsibleWidget extends TabAwareWidget { } this.$headerActions = this.$widget.find('.widget-header-actions'); - this.$headerActions.append(...this.headerActions); + let headerActions = this.headerActions; + + if (headerActions.length > 0) { + headerActions = ["(", ...headerActions, ")"]; + } + + this.$headerActions.append(...headerActions); this.initialized = this.doRenderBody(); this.decorateWidget(); } - saveCollapsed(collapse) { + toggleCollapsed(collapse) { + this.updateToggleButton(collapse); + options.save(this.widgetName + 'Collapsed', collapse.toString()); this.triggerEvent(`widgetCollapsedStateChanged`, {widgetName: this.widgetName, collapse}); } + updateToggleButton(collapse) { + if (collapse) { + this.$toggleButton + .addClass("bx-window") + .removeClass("bx-minus") + .attr("title", "Show"); + } else { + this.$toggleButton + .addClass("bx-minus") + .removeClass("bx-window") + .attr("title", "Hide"); + } + } + /** * This event is used to synchronize collapsed state of all the tab-cached widgets since they are all rendered * separately but should behave uniformly for the user.