Mercurial > gemma
view client/src/store/diagram.js @ 3196:0d76a0476a5b
diagram_store: fix encodeURIComponent
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Wed, 08 May 2019 14:35:40 +0200 |
parents | 88c31298eba8 |
children | b0328646e34f |
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"; const MOCKDATA = `#label,# >= LDC [h],# < 200.00 [h],# >= 200.00 [h],# >= 230.00 [h],# >= 250.00 [h] 01-2019, 22.000,1.000, 4.000,6.000, 20.000 02-2019, 24.000,0.000,0.000,0.000, 23.000 03-2019, 30.000,0.000,0.000,0.000, 30.000 04-2019, 30.000,0.000,0.000,0.000, 30.000 05-2019, 30.000,0.000,0.000,0.000, 30.000`; const init = () => { return { selectedFairwayAvailabilityFeature: null, from: null, to: null, frequency: null, fwData: null, legend: null }; }; const diagram = { init, namespaced: true, state: init(), mutations: { 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 } = options; const start = encodeURIComponent("00:00:00+07:00"); const end = encodeURIComponent("23:59:59+07:00"); const URL = `/data/bottleneck/fairway-depth/${encodeURIComponent( feature.properties.name )}?from=${from}T${start}&to=${to}T${end}&mode=${frequency}`; HTTP.get(URL, { headers: { "X-Gemma-Auth": localStorage.getItem("token") } }) .then(response => { const data = MOCKDATA; 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); }); }); } } }; export { diagram };