diff client/src/store/fairwayavailability.js @ 3207:ba7bc3740fb3

client: renamed store modules to better reflect their context
author Markus Kottlaender <markus@intevation.de>
date Wed, 08 May 2019 17:43:18 +0200
parents
children 3b36bb33f5b0
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/client/src/store/fairwayavailability.js	Wed May 08 17:43:18 2019 +0200
@@ -0,0 +1,101 @@
+/* This is Free Software under GNU Affero General Public License v >= 3.0
+ * without warranty, see README.md and license for details.
+ *
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ * License-Filename: LICENSES/AGPL-3.0.txt
+ *
+ * Copyright (C) 2018 by via donau
+ *   – Österreichische Wasserstraßen-Gesellschaft mbH
+ * Software engineering by Intevation GmbH
+ *
+ * Author(s):
+ * Thomas Junk <thomas.junk@intevation.de>
+ */
+
+import { HTTP } from "@/lib/http";
+
+const init = () => {
+  return {
+    type: "bottlenecks",
+    selectedFairwayAvailabilityFeature: null,
+    from: null,
+    to: null,
+    frequency: null,
+    fwData: null,
+    legend: null,
+    LOS: null
+  };
+};
+
+export default {
+  init,
+  namespaced: true,
+  state: init(),
+  mutations: {
+    type: (state, type) => {
+      state.type = type;
+    },
+    setLOS: (state, LOS) => {
+      state.LOS = LOS;
+    },
+    setFrequency: (state, frequency) => {
+      state.frequency = frequency;
+    },
+    setFrom: (state, from) => {
+      state.from = from;
+    },
+    setTo: (state, to) => {
+      state.to = to;
+    },
+    setSelectedFairwayAvailability: (state, feature) => {
+      state.selectedFairwayAvailabilityFeature = feature;
+    },
+    setFwData: (state, fwData) => {
+      state.fwData = fwData;
+    },
+    setLegend: (state, header) => {
+      const headerEntries = header.split(",");
+      headerEntries.shift();
+      state.legend = headerEntries.map(x => {
+        return x.split("#")[1].trim();
+      });
+    }
+  },
+  actions: {
+    loadAvailableFairwayDepth: ({ commit }, options) => {
+      return new Promise((resolve, reject) => {
+        const { feature, from, to, frequency, LOS } = options;
+        const start = encodeURIComponent("00:00:00+00:00");
+        const end = encodeURIComponent("23:59:59+00:00");
+        const URL = `/data/bottleneck/fairway-depth/${encodeURIComponent(
+          feature.properties.name
+        )}?from=${from}T${start}&to=${to}T${end}&mode=${frequency}&los=${LOS}`;
+        HTTP.get(URL, {
+          headers: { "X-Gemma-Auth": localStorage.getItem("token") }
+        })
+          .then(response => {
+            const { data } = response;
+            const csv = data.split("\n");
+            commit("setLegend", csv.shift());
+            let transformed = csv.map(e => {
+              const result = e.split(",");
+              const label = result.shift();
+              const ldc = result.shift();
+              const highestLevel = result.pop();
+              return {
+                label: label,
+                ldc: ldc,
+                highestLevel: highestLevel,
+                lowerLevels: result
+              };
+            });
+            commit("setFwData", transformed);
+            resolve(response);
+          })
+          .catch(error => {
+            reject(error);
+          });
+      });
+    }
+  }
+};