Mercurial > gemma
comparison 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 |
comparison
equal
deleted
inserted
replaced
3206:dffcf1cc8a8b | 3207:ba7bc3740fb3 |
---|---|
1 /* This is Free Software under GNU Affero General Public License v >= 3.0 | |
2 * without warranty, see README.md and license for details. | |
3 * | |
4 * SPDX-License-Identifier: AGPL-3.0-or-later | |
5 * License-Filename: LICENSES/AGPL-3.0.txt | |
6 * | |
7 * Copyright (C) 2018 by via donau | |
8 * – Österreichische Wasserstraßen-Gesellschaft mbH | |
9 * Software engineering by Intevation GmbH | |
10 * | |
11 * Author(s): | |
12 * Thomas Junk <thomas.junk@intevation.de> | |
13 */ | |
14 | |
15 import { HTTP } from "@/lib/http"; | |
16 | |
17 const init = () => { | |
18 return { | |
19 type: "bottlenecks", | |
20 selectedFairwayAvailabilityFeature: null, | |
21 from: null, | |
22 to: null, | |
23 frequency: null, | |
24 fwData: null, | |
25 legend: null, | |
26 LOS: null | |
27 }; | |
28 }; | |
29 | |
30 export default { | |
31 init, | |
32 namespaced: true, | |
33 state: init(), | |
34 mutations: { | |
35 type: (state, type) => { | |
36 state.type = type; | |
37 }, | |
38 setLOS: (state, LOS) => { | |
39 state.LOS = LOS; | |
40 }, | |
41 setFrequency: (state, frequency) => { | |
42 state.frequency = frequency; | |
43 }, | |
44 setFrom: (state, from) => { | |
45 state.from = from; | |
46 }, | |
47 setTo: (state, to) => { | |
48 state.to = to; | |
49 }, | |
50 setSelectedFairwayAvailability: (state, feature) => { | |
51 state.selectedFairwayAvailabilityFeature = feature; | |
52 }, | |
53 setFwData: (state, fwData) => { | |
54 state.fwData = fwData; | |
55 }, | |
56 setLegend: (state, header) => { | |
57 const headerEntries = header.split(","); | |
58 headerEntries.shift(); | |
59 state.legend = headerEntries.map(x => { | |
60 return x.split("#")[1].trim(); | |
61 }); | |
62 } | |
63 }, | |
64 actions: { | |
65 loadAvailableFairwayDepth: ({ commit }, options) => { | |
66 return new Promise((resolve, reject) => { | |
67 const { feature, from, to, frequency, LOS } = options; | |
68 const start = encodeURIComponent("00:00:00+00:00"); | |
69 const end = encodeURIComponent("23:59:59+00:00"); | |
70 const URL = `/data/bottleneck/fairway-depth/${encodeURIComponent( | |
71 feature.properties.name | |
72 )}?from=${from}T${start}&to=${to}T${end}&mode=${frequency}&los=${LOS}`; | |
73 HTTP.get(URL, { | |
74 headers: { "X-Gemma-Auth": localStorage.getItem("token") } | |
75 }) | |
76 .then(response => { | |
77 const { data } = response; | |
78 const csv = data.split("\n"); | |
79 commit("setLegend", csv.shift()); | |
80 let transformed = csv.map(e => { | |
81 const result = e.split(","); | |
82 const label = result.shift(); | |
83 const ldc = result.shift(); | |
84 const highestLevel = result.pop(); | |
85 return { | |
86 label: label, | |
87 ldc: ldc, | |
88 highestLevel: highestLevel, | |
89 lowerLevels: result | |
90 }; | |
91 }); | |
92 commit("setFwData", transformed); | |
93 resolve(response); | |
94 }) | |
95 .catch(error => { | |
96 reject(error); | |
97 }); | |
98 }); | |
99 } | |
100 } | |
101 }; |