Mercurial > gemma
annotate client/src/store/diagram.js @ 3205:bf571429515f
client: fairway availability: moved component's type property to store to manipulate it from outside
author | Markus Kottlaender <markus@intevation.de> |
---|---|
date | Wed, 08 May 2019 17:15:08 +0200 |
parents | cb67ee72485b |
children |
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 |
3184
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
17 const init = () => { |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
18 return { |
3205
bf571429515f
client: fairway availability: moved component's type property to store to manipulate it from outside
Markus Kottlaender <markus@intevation.de>
parents:
3203
diff
changeset
|
19 type: "bottlenecks", |
3185
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
20 selectedFairwayAvailabilityFeature: null, |
3191
c0cd5dfec153
statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents:
3185
diff
changeset
|
21 from: null, |
c0cd5dfec153
statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents:
3185
diff
changeset
|
22 to: null, |
c0cd5dfec153
statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents:
3185
diff
changeset
|
23 frequency: null, |
3185
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
24 fwData: null, |
3198
b0328646e34f
statistics: include los selection
Thomas Junk <thomas.junk@intevation.de>
parents:
3196
diff
changeset
|
25 legend: null, |
b0328646e34f
statistics: include los selection
Thomas Junk <thomas.junk@intevation.de>
parents:
3196
diff
changeset
|
26 LOS: null |
3184
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
27 }; |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
28 }; |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
29 |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
30 const diagram = { |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
31 init, |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
32 namespaced: true, |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
33 state: init(), |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
34 mutations: { |
3205
bf571429515f
client: fairway availability: moved component's type property to store to manipulate it from outside
Markus Kottlaender <markus@intevation.de>
parents:
3203
diff
changeset
|
35 type: (state, type) => { |
bf571429515f
client: fairway availability: moved component's type property to store to manipulate it from outside
Markus Kottlaender <markus@intevation.de>
parents:
3203
diff
changeset
|
36 state.type = type; |
bf571429515f
client: fairway availability: moved component's type property to store to manipulate it from outside
Markus Kottlaender <markus@intevation.de>
parents:
3203
diff
changeset
|
37 }, |
3198
b0328646e34f
statistics: include los selection
Thomas Junk <thomas.junk@intevation.de>
parents:
3196
diff
changeset
|
38 setLOS: (state, LOS) => { |
b0328646e34f
statistics: include los selection
Thomas Junk <thomas.junk@intevation.de>
parents:
3196
diff
changeset
|
39 state.LOS = LOS; |
b0328646e34f
statistics: include los selection
Thomas Junk <thomas.junk@intevation.de>
parents:
3196
diff
changeset
|
40 }, |
3191
c0cd5dfec153
statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents:
3185
diff
changeset
|
41 setFrequency: (state, frequency) => { |
c0cd5dfec153
statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents:
3185
diff
changeset
|
42 state.frequency = frequency; |
c0cd5dfec153
statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents:
3185
diff
changeset
|
43 }, |
c0cd5dfec153
statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents:
3185
diff
changeset
|
44 setFrom: (state, from) => { |
c0cd5dfec153
statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents:
3185
diff
changeset
|
45 state.from = from; |
c0cd5dfec153
statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents:
3185
diff
changeset
|
46 }, |
c0cd5dfec153
statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents:
3185
diff
changeset
|
47 setTo: (state, to) => { |
c0cd5dfec153
statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents:
3185
diff
changeset
|
48 state.to = to; |
c0cd5dfec153
statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents:
3185
diff
changeset
|
49 }, |
3184
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
50 setSelectedFairwayAvailability: (state, feature) => { |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
51 state.selectedFairwayAvailabilityFeature = feature; |
3185
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
52 }, |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
53 setFwData: (state, fwData) => { |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
54 state.fwData = fwData; |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
55 }, |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
56 setLegend: (state, header) => { |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
57 const headerEntries = header.split(","); |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
58 headerEntries.shift(); |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
59 state.legend = headerEntries.map(x => { |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
60 return x.split("#")[1].trim(); |
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 }, |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
64 actions: { |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
65 loadAvailableFairwayDepth: ({ commit }, options) => { |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
66 return new Promise((resolve, reject) => { |
3198
b0328646e34f
statistics: include los selection
Thomas Junk <thomas.junk@intevation.de>
parents:
3196
diff
changeset
|
67 const { feature, from, to, frequency, LOS } = options; |
3203
cb67ee72485b
available_fairway_depth: use real data
Thomas Junk <thomas.junk@intevation.de>
parents:
3198
diff
changeset
|
68 const start = encodeURIComponent("00:00:00+00:00"); |
cb67ee72485b
available_fairway_depth: use real data
Thomas Junk <thomas.junk@intevation.de>
parents:
3198
diff
changeset
|
69 const end = encodeURIComponent("23:59:59+00:00"); |
3196
0d76a0476a5b
diagram_store: fix encodeURIComponent
Thomas Junk <thomas.junk@intevation.de>
parents:
3195
diff
changeset
|
70 const URL = `/data/bottleneck/fairway-depth/${encodeURIComponent( |
3191
c0cd5dfec153
statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents:
3185
diff
changeset
|
71 feature.properties.name |
3198
b0328646e34f
statistics: include los selection
Thomas Junk <thomas.junk@intevation.de>
parents:
3196
diff
changeset
|
72 )}?from=${from}T${start}&to=${to}T${end}&mode=${frequency}&los=${LOS}`; |
3185
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
73 HTTP.get(URL, { |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
74 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
|
75 }) |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
76 .then(response => { |
3203
cb67ee72485b
available_fairway_depth: use real data
Thomas Junk <thomas.junk@intevation.de>
parents:
3198
diff
changeset
|
77 const { data } = response; |
3185
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
78 const csv = data.split("\n"); |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
79 commit("setLegend", csv.shift()); |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
80 let transformed = csv.map(e => { |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
81 const result = e.split(","); |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
82 const label = result.shift(); |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
83 const ldc = result.shift(); |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
84 const highestLevel = result.pop(); |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
85 return { |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
86 label: label, |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
87 ldc: ldc, |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
88 highestLevel: highestLevel, |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
89 lowerLevels: result |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
90 }; |
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 commit("setFwData", transformed); |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
93 resolve(response); |
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 .catch(error => { |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
96 reject(error); |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
97 }); |
505414dfe3e7
available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents:
3184
diff
changeset
|
98 }); |
3184
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 } |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
101 }; |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
102 |
1ba2a7d22fbb
available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
103 export { diagram }; |