From 69937e06b945e393c491f99c327af40a31c478a5 Mon Sep 17 00:00:00 2001
From: Eugen Ciur <eugen@papermerge.com>
Date: Sun, 20 Mar 2022 07:00:25 +0100
Subject: [PATCH] show dual panel's action modes only when necessary

---
 app/components/panel_modes.hbs            | 18 ------------------
 app/components/panel_modes/index.hbs      | 20 ++++++++++++++++++++
 app/components/panel_modes/index.js       | 23 +++++++++++++++++++++++
 app/controllers/authenticated/document.js |  1 -
 4 files changed, 43 insertions(+), 19 deletions(-)
 delete mode 100644 app/components/panel_modes.hbs
 create mode 100644 app/components/panel_modes/index.hbs
 create mode 100644 app/components/panel_modes/index.js

diff --git a/app/components/panel_modes.hbs b/app/components/panel_modes.hbs
deleted file mode 100644
index c00cfec..0000000
--- a/app/components/panel_modes.hbs
+++ /dev/null
@@ -1,18 +0,0 @@
-{{#if @dualPanelMode}}
-  <button
-    type="button"
-    class="btn btn-light mx-1"
-    {{on 'click' @onDuplicatePanel}}>
-      {{#if (is_equal @hint "left")}}
-        <i class="bi-arrow-bar-right"></i>
-      {{else}}
-         <i class="bi-arrow-bar-left"></i>
-      {{/if}}
-  </button>
-
-  <button type="button"
-    class="btn btn-light mx-1"
-    {{on 'click' @onSwapPanels}}>
-      <i class="bi-arrow-left-right"></i>
-  </button>
-{{/if}}
diff --git a/app/components/panel_modes/index.hbs b/app/components/panel_modes/index.hbs
new file mode 100644
index 0000000..896a212
--- /dev/null
+++ b/app/components/panel_modes/index.hbs
@@ -0,0 +1,20 @@
+{{#if this.are_not_same_panels }}
+  {{#if @dualPanelMode}}
+    <button
+      type="button"
+      class="btn btn-light mx-1"
+      {{on 'click' @onDuplicatePanel}}>
+        {{#if (is_equal @hint "left")}}
+          <i class="bi-arrow-bar-right"></i>
+        {{else}}
+           <i class="bi-arrow-bar-left"></i>
+        {{/if}}
+    </button>
+
+    <button type="button"
+      class="btn btn-light mx-1"
+      {{on 'click' @onSwapPanels}}>
+        <i class="bi-arrow-left-right"></i>
+    </button>
+  {{/if}}
+{{/if}}
diff --git a/app/components/panel_modes/index.js b/app/components/panel_modes/index.js
new file mode 100644
index 0000000..4c213a7
--- /dev/null
+++ b/app/components/panel_modes/index.js
@@ -0,0 +1,23 @@
+import Component from '@glimmer/component';
+import { service } from '@ember/service';
+
+
+export default class PanelModesComponent extends Component {
+  @service router;
+
+  get are_not_same_panels() {
+    /* Returns true if both panels are not same (non empty) values */
+    let param, query_param, route;
+
+    route = this.router.currentRoute;
+
+    param = route.params.document_id || route.params.node_id;
+    query_param = route.queryParams.extra_id;
+
+    if (param && query_param) {
+      return param !== query_param;
+    }
+
+    return true;
+  }
+}
\ No newline at end of file
diff --git a/app/controllers/authenticated/document.js b/app/controllers/authenticated/document.js
index 918a92c..dd8f269 100644
--- a/app/controllers/authenticated/document.js
+++ b/app/controllers/authenticated/document.js
@@ -77,7 +77,6 @@ export default class DocumentController extends DualPanelBaseController {
         'extra_type': 'doc'
       }
     }
-
     if (this.extra_id) {
       this.router.transitionTo(
         'authenticated.document',
-- 
GitLab