From 2d0dbafc09f12951893f57a6c2c4646f704275b9 Mon Sep 17 00:00:00 2001
From: Olivier Maury <Olivier.Maury@inrae.fr>
Date: Fri, 3 Nov 2023 15:23:34 +0100
Subject: [PATCH] =?UTF-8?q?Ne=20pas=20ouvrir=20le=20panneau=20de=20droite?=
 =?UTF-8?q?=20au=20d=C3=A9marrage=20ou=20s'il=20est=20ferm=C3=A9.=20fixes?=
 =?UTF-8?q?=20#12?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../client/presenter/RightPanelPresenter.java | 11 +++++++++-
 .../www/client/view/LayoutView.java           | 20 +++++++++++++++++++
 .../www/client/view/RightPanelView.java       |  5 +++++
 3 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/www-client/src/main/java/fr/agrometinfo/www/client/presenter/RightPanelPresenter.java b/www-client/src/main/java/fr/agrometinfo/www/client/presenter/RightPanelPresenter.java
index de4eeb9..e472bc7 100644
--- a/www-client/src/main/java/fr/agrometinfo/www/client/presenter/RightPanelPresenter.java
+++ b/www-client/src/main/java/fr/agrometinfo/www/client/presenter/RightPanelPresenter.java
@@ -4,6 +4,7 @@ import org.dominokit.domino.ui.utils.DominoElement;
 
 import com.google.gwt.core.client.GWT;
 
+import elemental2.dom.DomGlobal;
 import elemental2.dom.HTMLElement;
 import fr.agrometinfo.www.client.view.BaseView;
 import fr.agrometinfo.www.client.view.LayoutView;
@@ -28,6 +29,11 @@ public final class RightPanelPresenter implements Presenter {
          */
         void hide();
 
+        /**
+         * @return boolean, true if the panel is visible and open.
+         */
+        boolean isVisible();
+
         /**
          * Display summary data.
          *
@@ -74,7 +80,10 @@ public final class RightPanelPresenter implements Presenter {
         .onSuccess(view::setSummary)//
         .onFailed(layoutView::failureNotification)//
         .send();
-        view.show();
+        // Do not automatically open the panel on mobile or if it is closed
+        if (DomGlobal.screen.width > LayoutView.MIN_WIDTH_FOR_PANELS && view.isVisible()) {
+            view.show();
+        }
     }
 
     /**
diff --git a/www-client/src/main/java/fr/agrometinfo/www/client/view/LayoutView.java b/www-client/src/main/java/fr/agrometinfo/www/client/view/LayoutView.java
index 71a8400..8c172b6 100644
--- a/www-client/src/main/java/fr/agrometinfo/www/client/view/LayoutView.java
+++ b/www-client/src/main/java/fr/agrometinfo/www/client/view/LayoutView.java
@@ -62,6 +62,11 @@ import fr.agrometinfo.www.shared.dto.PeriodDTO;
  * @author Olivier Maury
  */
 public final class LayoutView extends AbstractBaseView<LayoutPresenter> implements LayoutPresenter.View {
+    /**
+     * The minimum screen width to display panels on startup.
+     */
+    public static final int MIN_WIDTH_FOR_PANELS = 1000;
+
     /**
      * Code of indicator to show by default.
      */
@@ -214,6 +219,14 @@ public final class LayoutView extends AbstractBaseView<LayoutPresenter> implemen
         initLeftPanel();
         initFooter();
         initMapView();
+
+        if (DomGlobal.screen.width < MIN_WIDTH_FOR_PANELS) {
+            layout.hideLeftPanel();
+            layout.hideRightPanel();
+        } else {
+            layout.showLeftPanel();
+            layout.showRightPanel();
+        }
     }
 
     private void initFooter() {
@@ -357,6 +370,13 @@ public final class LayoutView extends AbstractBaseView<LayoutPresenter> implemen
         addMenuItem(dotDropMenu, CSTS.logout(), Icons.ALL.exit_to_app_mdi(), () -> getPresenter().logout());
     }
 
+    /**
+     * @return boolean, true if the right panel is visible and open.
+     */
+    public boolean isRightPanelVisible() {
+        return layout.isRightPanelVisible();
+    }
+
     private Notification notification(final String msg) {
         DomGlobal.console.info("Notification!");
         return Notification.create(msg).setPosition(Notification.TOP_LEFT).show();
diff --git a/www-client/src/main/java/fr/agrometinfo/www/client/view/RightPanelView.java b/www-client/src/main/java/fr/agrometinfo/www/client/view/RightPanelView.java
index 25c86cb..d6d7644 100644
--- a/www-client/src/main/java/fr/agrometinfo/www/client/view/RightPanelView.java
+++ b/www-client/src/main/java/fr/agrometinfo/www/client/view/RightPanelView.java
@@ -148,6 +148,11 @@ public final class RightPanelView implements RightPanelPresenter.View {
         container.add(barChartContainer);
     }
 
+    @Override
+    public boolean isVisible() {
+        return layoutView.isRightPanelVisible();
+    }
+
     @Override
     public void setPresenter(final RightPanelPresenter p) {
         // Do nothing
-- 
GitLab