From 027af48f0b19f37a34b261289bdbddd66268d033 Mon Sep 17 00:00:00 2001
From: Timm Fitschen <t.fitschen@indiscale.com>
Date: Thu, 24 Mar 2022 11:59:55 +0100
Subject: [PATCH 1/3] ENH: add "show" option to map config

---
 CHANGELOG.md                       |  6 ++++++
 src/core/js/ext_map.js             | 27 ++++++++++++++++++++-------
 test/core/js/modules/ext_map.js.js | 26 ++++++++++++++++++++++++--
 3 files changed, 50 insertions(+), 9 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0d26f755..b926ed15 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Changed (for changes in existing functionality)
 
+* Added `show` option to caosdb_map.MapConfig for showing the map initially and
+  storing the state accross page reloads. Defaults to `false`. This also bumps
+  the version of the map to 0.4.1 as it changes the behavior but the change is
+  backwards-compatible for the map config. Clients need to update their
+  version string in their config file, tho.
+
 ### Deprecated (for soon-to-be removed features)
 
 ### Removed (for now removed features)
diff --git a/src/core/js/ext_map.js b/src/core/js/ext_map.js
index c20cdefc..e0b5fafd 100644
--- a/src/core/js/ext_map.js
+++ b/src/core/js/ext_map.js
@@ -25,7 +25,7 @@
 
 /**
  * @module caosdb_map
- * @version 0.4
+ * @version 0.4.1
  *
  * For displaying a geographical map which shows entities at their associated
  * geolocation.
@@ -34,7 +34,7 @@
  * `conf/ext/json/ext_map.json` and comply with the {@link MapConfig} type
  * which is described below.
  *
- * The current version is 0.4. It is not considered to be stable because
+ * The current version is 0.4.1. It is not considered to be stable because
  * implementation of the graticule still is not satisfactory.
  *
  * Apart from that the specification of the configuration and the
@@ -43,7 +43,7 @@
 var caosdb_map = new function () {
 
     var logger = log.getLogger("caosdb_map");
-    this.version = "0.4";
+    this.version = "0.4.1";
     this.dependencies = ["log", {
         "L": ["latlngGraticule", "Proj"]
     }, "navbar", "caosdb_utils"];
@@ -63,6 +63,9 @@ var caosdb_map = new function () {
      * integrated query generator.
      *
      * @typedef {object} MapConfig
+     * @property {boolean} [show=false] - show the map immediately when it is
+     *     ready. This configuration option is being stored locally for keeping
+     *     the map shown/hidden accross page reloads.
      * @property {string} version - the version of the map
      * @property {string} default_view - the view which is shown when the user
      *     opens the map and has no stored view from prior visits to the map.
@@ -336,6 +339,7 @@ var caosdb_map = new function () {
      */
     this._default_config = {
         "version": this.version,
+        "show": false,
         "datamodel": {
             "lat": "latitude",
             "lng": "longitude",
@@ -843,8 +847,10 @@ var caosdb_map = new function () {
          *
          * The map panel is the HTMLElement which contains the map. Is is
          * hidden or shown when the user clicks on the toggle map button.
+         *
+         * @param {boolean} show - show this panel immediately.
          */
-        this.init_map_panel = function () {
+        this.init_map_panel = function (show) {
             logger.trace("enter init_map_panel");
 
             // remove old
@@ -852,7 +858,9 @@ var caosdb_map = new function () {
 
             let panel = this.create_map_panel();
 
-            $(panel).hide();
+            if(!show) {
+              $(panel).hide();
+            }
             $('nav').first().after(panel);
 
             logger.trace("leave init_map_panel");
@@ -865,6 +873,7 @@ var caosdb_map = new function () {
          */
         this.toggle_map = function () {
             logger.trace("enter toggle_map");
+            sessionStorage["caosdb_map.show"] = !$(".caosdb-f-map-panel").is(":visible");
             $(".caosdb-f-map-panel").toggle(900, () => this
                 ._toggle_cb());
         }
@@ -983,14 +992,18 @@ var caosdb_map = new function () {
                     return;
                 }
                 this.config = config;
+                var show_map = config.show;
+                if(sessionStorage["caosdb_map.show"]) {
+                  show_map = JSON.parse(sessionStorage["caosdb_map.show"]);
+                }
                 this.init_select_handler();
                 this.init_view_change_handler();
-                panel = this.init_map_panel();
+                panel = this.init_map_panel(show_map);
 
                 // TODO split in smaller pieces and move callback to separate function
                 this.change_map_view = (view) => {
                     if (this._map) {
-			this._map._container.remove();
+                        this._map._container.remove();
                         this._map.remove();
                     }
 
diff --git a/test/core/js/modules/ext_map.js.js b/test/core/js/modules/ext_map.js.js
index 9b6b0102..0c9ed800 100644
--- a/test/core/js/modules/ext_map.js.js
+++ b/test/core/js/modules/ext_map.js.js
@@ -51,7 +51,7 @@ QUnit.module("ext_map.js", {
 });
 
 QUnit.test("availability", function (assert) {
-    assert.equal(caosdb_map.version, "0.4", "test version");
+    assert.equal(caosdb_map.version, "0.4.1", "test version");
     assert.ok(caosdb_map.init, "init available");
 });
 
@@ -119,10 +119,32 @@ QUnit.test("create_map", function (assert) {
 
 QUnit.test("create_map_panel", function (assert) {
     assert.ok(caosdb_map.create_map_panel, "available");
-    let panel = caosdb_map.create_map_panel();
+    let panel = caosdb_map.create_map_panel(true);
+    $(document.body).append(panel);
     assert.equal(panel.tagName, "DIV", "is div");
     assert.ok($(panel).hasClass("caosdb-f-map-panel"), "has class caosdb-f-map-panel");
     assert.ok($(panel).hasClass("container"), "has class container");
+    assert.ok($(panel).is(":visible"), "Panel is visible");
+
+    panel = caosdb_map.create_map_panel(true);
+    assert.notOk($(panel).is(":visible"), "Panel is not visible");
+    $(document.body).append(panel);
+
+    panel.remove();
+});
+
+QUnit.test("init_map_panel", function (assert) {
+    assert.ok(caosdb_map.init_map_panel, "available");
+    const dummy_nav = $("<nav/>");
+    $(document.body).append(dummy_nav);
+    let panel = caosdb_map.init_map_panel(true);
+
+    assert.ok($(panel).is(":visible"), "Panel is visible");
+
+    panel = caosdb_map.create_map_panel(true);
+    assert.notOk($(panel).is(":visible"), "Panel is not visible");
+
+    dummy_nav.remove();
 });
 
 QUnit.test("create_map_view", function (assert) {
-- 
GitLab


From 90205845465472c2cc3b74a91a1e23cb6df47a26 Mon Sep 17 00:00:00 2001
From: Timm Fitschen <t.fitschen@indiscale.com>
Date: Thu, 24 Mar 2022 12:03:38 +0100
Subject: [PATCH 2/3] EHN: add "show" option to map config

---
 src/core/js/ext_map.js | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/core/js/ext_map.js b/src/core/js/ext_map.js
index e0b5fafd..c810163d 100644
--- a/src/core/js/ext_map.js
+++ b/src/core/js/ext_map.js
@@ -881,6 +881,7 @@ var caosdb_map = new function () {
 
         this.show_map = function () {
             logger.trace("enter show_map");
+            sessionStorage["caosdb_map.show"] = "true";
             $(".caosdb-f-map-panel").show(900, () => this
                 ._toggle_cb());
         }
-- 
GitLab


From 02468783bf774ba3333a6325d424ea0ea7e116fc Mon Sep 17 00:00:00 2001
From: Timm Fitschen <t.fitschen@indiscale.com>
Date: Thu, 24 Mar 2022 12:14:34 +0100
Subject: [PATCH 3/3] TST: remove unnecessary test assertions in ext_map

---
 test/core/js/modules/ext_map.js.js | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/test/core/js/modules/ext_map.js.js b/test/core/js/modules/ext_map.js.js
index 0c9ed800..4425b2e7 100644
--- a/test/core/js/modules/ext_map.js.js
+++ b/test/core/js/modules/ext_map.js.js
@@ -119,18 +119,10 @@ QUnit.test("create_map", function (assert) {
 
 QUnit.test("create_map_panel", function (assert) {
     assert.ok(caosdb_map.create_map_panel, "available");
-    let panel = caosdb_map.create_map_panel(true);
-    $(document.body).append(panel);
+    let panel = caosdb_map.create_map_panel();
     assert.equal(panel.tagName, "DIV", "is div");
     assert.ok($(panel).hasClass("caosdb-f-map-panel"), "has class caosdb-f-map-panel");
     assert.ok($(panel).hasClass("container"), "has class container");
-    assert.ok($(panel).is(":visible"), "Panel is visible");
-
-    panel = caosdb_map.create_map_panel(true);
-    assert.notOk($(panel).is(":visible"), "Panel is not visible");
-    $(document.body).append(panel);
-
-    panel.remove();
 });
 
 QUnit.test("init_map_panel", function (assert) {
-- 
GitLab