Mercurial > gemma
annotate client/src/store/diagram.js @ 3191:c0cd5dfec153
statistics: persist fields to vuex
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Wed, 08 May 2019 11:25:11 +0200 |
parents | 505414dfe3e7 |
children | 88c31298eba8 |
rev | line source |
---|---|
3184
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
1 /* This is Free Software under GNU Affero General Public License v >= 3.0 |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
2 * without warranty, see README.md and license for details. |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
3 * |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
4 * SPDX-License-Identifier: AGPL-3.0-or-later |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
5 * License-Filename: LICENSES/AGPL-3.0.txt |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
6 * |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
7 * Copyright (C) 2018 by via donau |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
8 * – Österreichische Wasserstraßen-Gesellschaft mbH |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
9 * Software engineering by Intevation GmbH |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
10 * |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
11 * Author(s): |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
12 * Thomas Junk <thomas.junk@intevation.de> |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
13 */ |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
14 |
3185
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
15 import { HTTP } from "@/lib/http"; |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
16 |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
17 const MOCKDATA = `#label,# >= LDC [h],# < 200.00 [h],# >= 200.00 [h],# >= 230.00 [h],# >= 250.00 [h] |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
18 01-2019, 22.000,1.000, 4.000,6.000, 20.000 |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
19 02-2019, 24.000,0.000,0.000,0.000, 23.000 |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
20 03-2019, 30.000,0.000,0.000,0.000, 30.000 |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
21 04-2019, 30.000,0.000,0.000,0.000, 30.000 |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
22 05-2019, 30.000,0.000,0.000,0.000, 30.000`; |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
23 |
3184
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
24 const init = () => { |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
25 return { |
3185
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
26 selectedFairwayAvailabilityFeature: null, |
3191
c0cd5dfec153
statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents:
3185
diff
changeset
|
27 from: null, |
c0cd5dfec153
statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents:
3185
diff
changeset
|
28 to: null, |
c0cd5dfec153
statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents:
3185
diff
changeset
|
29 frequency: null, |
3185
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
30 fwData: null, |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
31 legend: null |
3184
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
32 }; |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
33 }; |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
34 |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
35 const diagram = { |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
36 init, |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
37 namespaced: true, |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
38 state: init(), |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
39 mutations: { |
3191
c0cd5dfec153
statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents:
3185
diff
changeset
|
40 setFrequency: (state, frequency) => { |
c0cd5dfec153
statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents:
3185
diff
changeset
|
41 state.frequency = frequency; |
c0cd5dfec153
statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents:
3185
diff
changeset
|
42 }, |
c0cd5dfec153
statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents:
3185
diff
changeset
|
43 setFrom: (state, from) => { |
c0cd5dfec153
statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents:
3185
diff
changeset
|
44 state.from = from; |
c0cd5dfec153
statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents:
3185
diff
changeset
|
45 }, |
c0cd5dfec153
statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents:
3185
diff
changeset
|
46 setTo: (state, to) => { |
c0cd5dfec153
statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents:
3185
diff
changeset
|
47 state.to = to; |
c0cd5dfec153
statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents:
3185
diff
changeset
|
48 }, |
3184
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
49 setSelectedFairwayAvailability: (state, feature) => { |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
50 state.selectedFairwayAvailabilityFeature = feature; |
3185
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
51 }, |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
52 setFwData: (state, fwData) => { |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
53 state.fwData = fwData; |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
54 }, |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
55 setLegend: (state, header) => { |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
56 const headerEntries = header.split(","); |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
57 headerEntries.shift(); |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
58 state.legend = headerEntries.map(x => { |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
59 return x.split("#")[1].trim(); |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
60 }); |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
61 } |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
62 }, |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
63 actions: { |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
64 loadAvailableFairwayDepth: ({ commit }, options) => { |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
65 return new Promise((resolve, reject) => { |
3191
c0cd5dfec153
statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents:
3185
diff
changeset
|
66 const { feature, from, to, frequency } = options; |
c0cd5dfec153
statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents:
3185
diff
changeset
|
67 const URL = `/data/bottleneck/fairway-depth/${ |
c0cd5dfec153
statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents:
3185
diff
changeset
|
68 feature.properties.name |
c0cd5dfec153
statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents:
3185
diff
changeset
|
69 }?from=${from}T00:00:00%2b00:00&to=${to}T23:59:59%2b07:00&mode=${frequency}`; |
3185
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
70 HTTP.get(URL, { |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
71 headers: { "X-Gemma-Auth": localStorage.getItem("token") } |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
72 }) |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
73 .then(response => { |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
74 const data = MOCKDATA; |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
75 const csv = data.split("\n"); |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
76 commit("setLegend", csv.shift()); |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
77 let transformed = csv.map(e => { |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
78 const result = e.split(","); |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
79 const label = result.shift(); |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
80 const ldc = result.shift(); |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
81 const highestLevel = result.pop(); |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
82 return { |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
83 label: label, |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
84 ldc: ldc, |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
85 highestLevel: highestLevel, |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
86 lowerLevels: result |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
87 }; |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
88 }); |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
89 commit("setFwData", transformed); |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
90 resolve(response); |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
91 }) |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
92 .catch(error => { |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
93 reject(error); |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
94 }); |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
95 }); |
3184
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
96 } |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
97 } |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
98 }; |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
99 |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
100 export { diagram }; |