Mercurial > gemma
view client/src/store/fairwayavailability.js @ 3288:c2d753ef5aa1
fairway_availability: sane defaults and ISC colors for diagram
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Thu, 16 May 2019 12:48:23 +0200 |
parents | 3b36bb33f5b0 |
children | ef52926ce2fc |
line wrap: on
line source
/* 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"; import { format, subYears } from "date-fns"; const init = () => { return { type: "bottlenecks", selectedFairwayAvailabilityFeature: null, to: format(new Date(), "YYYY-MM-DD"), from: format(subYears(new Date(), 1), "YYYY-MM-DD"), frequency: "monthly", fwData: null, legend: null, LOS: 3 }; }; 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").filter(x => x !== ""); //omit empty lines 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); }); }); } } };