changeset 2441:9de710bdb535

client: improved identify box formatter
author Markus Kottlaender <markus@intevation.de>
date Fri, 01 Mar 2019 10:53:52 +0100
parents 999bb511ef67
children 9b7138751f5b 3cf5d27a6c8b
files client/src/components/identify/Identify.vue client/src/components/identify/formatter.js
diffstat 2 files changed, 26 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/identify/Identify.vue	Fri Mar 01 10:52:32 2019 +0100
+++ b/client/src/components/identify/Identify.vue	Fri Mar 01 10:53:52 2019 +0100
@@ -135,6 +135,8 @@
       return this.featureId(feature);
     },
     featureProps(feature) {
+      let featureId = this.featureId(feature);
+
       // create array with {key, val} objects
       let propsArray = [];
       Object.keys(feature.getProperties()).forEach(key => {
@@ -156,11 +158,17 @@
       });
 
       // change labels and remove unneeded properties
-      if (formatter.hasOwnProperty(this.featureId(feature))) {
-        propsArray = propsArray
-          .map(formatter[this.featureId(feature)].props)
-          .filter(p => p); // remove empty entries
+      // for all features
+      propsArray = propsArray.map(formatter.all);
+      // feature specific
+      if (
+        formatter.hasOwnProperty(featureId) &&
+        formatter[featureId].hasOwnProperty("props")
+      ) {
+        propsArray = propsArray.map(formatter[featureId].props);
       }
+      // remove empty entries
+      propsArray = propsArray.filter(p => p);
 
       // remove underscores in labels that where not previously changed already
       propsArray = propsArray.map(prop => {
--- a/client/src/components/identify/formatter.js	Fri Mar 01 10:52:32 2019 +0100
+++ b/client/src/components/identify/formatter.js	Fri Mar 01 10:53:52 2019 +0100
@@ -1,13 +1,17 @@
 const formatter = {
+  all(p) {
+    if (p.key === "objnam") p.key = "Name";
+    if (p.key === "staging_done") p.val = p.val ? "yes" : "no";
+    if (p.key === "date_info") {
+      p.val = new Date(p.val).toLocaleString();
+    }
+    return p;
+  },
   bottlenecks_geoserver: {
     label: "Bottleneck",
     props: p => {
       if (p.key === "bottleneck_id") p.key = "ID";
-      if (p.key === "objnam") p.key = "Name";
       if (p.key === "responsible_country") p.key = "Responsible Country";
-      if (p.key === "date_info") {
-        p.val = new Date(p.val).toLocaleString();
-      }
 
       // remove certain props
       let propsToRemove = ["nobjnm", "reference_water_levels"];
@@ -17,60 +21,22 @@
     }
   },
   fairway_dimensions: {
-    label: "Fairway Dimensions",
-    props: p => {
-      if (p.key === "staging_done") p.val = p.val ? "yes" : "no";
-      if (p.key === "date_info") {
-        p.val = new Date(p.val).toLocaleString();
-      }
-
-      // remove certain props
-      let propsToRemove = [];
-      if (propsToRemove.indexOf(p.key) !== -1) return null;
-
-      return p;
-    }
+    label: "Fairway Dimensions"
   },
   waterway_area: {
-    label: "Waterway Area",
-    props: p => p
+    label: "Waterway Area"
   },
   distance_marks_geoserver: {
-    label: "Distance Mark",
-    props: p => p
+    label: "Distance Mark"
   },
   waterway_axis: {
-    label: "Waterway Axis",
-    props: p => {
-      if (p.key === "objnam") p.key = "Name";
-      return p;
-    }
+    label: "Waterway Axis"
   },
   waterway_profiles: {
-    label: "Waterway Profile",
-    props: p => {
-      if (p.key === "staging_done") p.val = p.val ? "yes" : "no";
-      if (p.key === "date_info") {
-        p.key = "Date info";
-        p.val = new Date(p.val).toLocaleString();
-      }
-
-      // remove certain props
-      let propsToRemove = [];
-      if (propsToRemove.indexOf(p.key) !== -1) return null;
-
-      return p;
-    }
+    label: "Waterway Profile"
   },
   stretches_geoserver: {
-    label: "Stretch",
-    props: p => {
-      if (p.key === "date_info") {
-        p.key = "Date info";
-        p.val = new Date(p.val).toLocaleString();
-      }
-      return p;
-    }
+    label: "Stretch"
   }
 };