view client/src/components/identify/formatter.js @ 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 045bac575294
children c3c014435e88
line wrap: on
line source

const formatter = {
  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"];
      if (propsToRemove.indexOf(p.key) !== -1) return null;

      return p;
    }
  },
  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;
    }
  },
  waterway_area: {
    label: "Waterway Area",
    props: p => p
  },
  distance_marks_geoserver: {
    label: "Distance Mark",
    props: p => p
  },
  waterway_axis: {
    label: "Waterway Axis",
    props: p => {
      if (p.key === "objnam") p.key = "Name";
      return p;
    }
  },
  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;
    }
  }
};

export { formatter };