changeset 2405:ef928c63388a

client: handle json values in identify box
author Markus Kottlaender <markus@intevation.de>
date Thu, 28 Feb 2019 08:37:41 +0100
parents fd248ede0251
children b72d3da6409c
files client/src/components/identify/Identify.vue client/src/components/identify/formatter.js
diffstat 2 files changed, 16 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/identify/Identify.vue	Thu Feb 28 07:45:34 2019 +0100
+++ b/client/src/components/identify/Identify.vue	Thu Feb 28 08:37:41 2019 +0100
@@ -138,9 +138,21 @@
       // create array with {key, val} objects
       let propsArray = [];
       Object.keys(feature.getProperties()).forEach(key => {
-        // avoid cyclic object value
-        if (key !== feature.getGeometryName())
-          propsArray.push({ key, val: feature.getProperties()[key] });
+        let val = feature.getProperties()[key];
+
+        // if val is a valid json string, parse it and spread its values into
+        // the array
+        try {
+          let json = JSON.parse(val);
+          Object.keys(json).forEach(key => {
+            propsArray.push({ key, val: json[key] });
+          });
+        } catch (e) {
+          // if val is not json then just put the key value pair into the array
+          // avoid cyclic object value (I didn't further investigate what's the
+          // problem here but feature.getGeometryName() needs to be skipped)
+          if (key !== feature.getGeometryName()) propsArray.push({ key, val });
+        }
       });
 
       // change labels and remove unneeded properties
--- a/client/src/components/identify/formatter.js	Thu Feb 28 07:45:34 2019 +0100
+++ b/client/src/components/identify/formatter.js	Thu Feb 28 08:37:41 2019 +0100
@@ -10,7 +10,7 @@
       }
 
       // remove certain props
-      let propsToRemove = ["nobjnm"];
+      let propsToRemove = ["nobjnm", "reference_water_levels"];
       if (propsToRemove.indexOf(p.key) !== -1) return null;
 
       return p;