Mercurial > gemma
annotate client/src/store/bottlenecks.js @ 1480:9b81ac91a43e
fix: linting
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Tue, 04 Dec 2018 10:02:31 +0100 |
parents | b350b0b5cb6c |
children | 53fdbe1d9678 |
rev | line source |
---|---|
1362
ca33ad696594
remove the first empyty lines
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1296
diff
changeset
|
1 /* This is Free Software under GNU Affero General Public License v >= 3.0 |
1096
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
2 * without warranty, see README.md and license for details. |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
3 * |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
4 * SPDX-License-Identifier: AGPL-3.0-or-later |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
5 * License-Filename: LICENSES/AGPL-3.0.txt |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
6 * |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
7 * Copyright (C) 2018 by via donau |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
8 * – Österreichische Wasserstraßen-Gesellschaft mbH |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
9 * Software engineering by Intevation GmbH |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
10 * |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
11 * Author(s): |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
12 * Markus Kottländer <markuks.kottlaender@intevation.de> |
1363 | 13 * Thomas Junk <thomas.junk@intevation.de> |
1096
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
14 */ |
1272
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
1114
diff
changeset
|
15 import { HTTP } from "../lib/http"; |
1096
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
16 import { WFS } from "ol/format.js"; |
1272
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
1114
diff
changeset
|
17 import { displayError } from "../lib/errors.js"; |
1096
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
18 |
1296
99c039e86624
replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents:
1272
diff
changeset
|
19 // initial state |
99c039e86624
replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents:
1272
diff
changeset
|
20 const init = () => { |
99c039e86624
replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents:
1272
diff
changeset
|
21 return { |
1111
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
22 bottlenecks: [], |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
23 selectedBottleneck: null, |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
24 surveys: [], |
1372
553aadd97087
new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
1363
diff
changeset
|
25 selectedSurvey: null, |
553aadd97087
new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
1363
diff
changeset
|
26 surveysLoading: false |
1296
99c039e86624
replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents:
1272
diff
changeset
|
27 }; |
99c039e86624
replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents:
1272
diff
changeset
|
28 }; |
99c039e86624
replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents:
1272
diff
changeset
|
29 |
99c039e86624
replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents:
1272
diff
changeset
|
30 export default { |
99c039e86624
replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents:
1272
diff
changeset
|
31 init, |
99c039e86624
replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents:
1272
diff
changeset
|
32 namespaced: true, |
99c039e86624
replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents:
1272
diff
changeset
|
33 state: init(), |
1096
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
34 mutations: { |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
35 setBottlenecks: (state, bottlenecks) => { |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
36 state.bottlenecks = bottlenecks; |
1111
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
37 }, |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
38 setSelectedBottleneck: (state, name) => { |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
39 state.selectedBottleneck = name; |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
40 }, |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
41 setSurveys(state, surveys) { |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
42 state.surveys = surveys; |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
43 }, |
1394
b350b0b5cb6c
refactored fairwayprofile cross cuts
Markus Kottlaender <markus@intevation.de>
parents:
1386
diff
changeset
|
44 selectedSurvey(state, survey) { |
1111
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
45 state.selectedSurvey = survey; |
1372
553aadd97087
new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
1363
diff
changeset
|
46 }, |
553aadd97087
new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
1363
diff
changeset
|
47 surveysLoading: (state, loading) => { |
553aadd97087
new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
1363
diff
changeset
|
48 state.surveysLoading = loading; |
1096
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
49 } |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
50 }, |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
51 actions: { |
1386
752b6bb2bee5
close splitscreen and clear cut tool when changing bottleneck
Markus Kottlaender <markus@intevation.de>
parents:
1372
diff
changeset
|
52 setSelectedBottleneck( |
752b6bb2bee5
close splitscreen and clear cut tool when changing bottleneck
Markus Kottlaender <markus@intevation.de>
parents:
1372
diff
changeset
|
53 { state, commit, dispatch, rootState, rootGetters }, |
752b6bb2bee5
close splitscreen and clear cut tool when changing bottleneck
Markus Kottlaender <markus@intevation.de>
parents:
1372
diff
changeset
|
54 name |
752b6bb2bee5
close splitscreen and clear cut tool when changing bottleneck
Markus Kottlaender <markus@intevation.de>
parents:
1372
diff
changeset
|
55 ) { |
1111
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
56 if (name !== state.selectedBottleneck) { |
1394
b350b0b5cb6c
refactored fairwayprofile cross cuts
Markus Kottlaender <markus@intevation.de>
parents:
1386
diff
changeset
|
57 commit("selectedSurvey", null); |
1111
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
58 commit("fairwayprofile/clearCurrentProfile", null, { root: true }); |
1386
752b6bb2bee5
close splitscreen and clear cut tool when changing bottleneck
Markus Kottlaender <markus@intevation.de>
parents:
1372
diff
changeset
|
59 commit("application/showSplitscreen", false, { root: true }); |
752b6bb2bee5
close splitscreen and clear cut tool when changing bottleneck
Markus Kottlaender <markus@intevation.de>
parents:
1372
diff
changeset
|
60 rootState.map.cutTool.setActive(false); |
752b6bb2bee5
close splitscreen and clear cut tool when changing bottleneck
Markus Kottlaender <markus@intevation.de>
parents:
1372
diff
changeset
|
61 rootGetters["map/getVSourceByName"]("Cut Tool").clear(); |
1111
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
62 } |
1372
553aadd97087
new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
1363
diff
changeset
|
63 if (name) { |
553aadd97087
new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
1363
diff
changeset
|
64 commit("application/showProfiles", true, { root: true }); |
553aadd97087
new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
1363
diff
changeset
|
65 } |
1111
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
66 commit("setSelectedBottleneck", name); |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
67 dispatch("querySurveys", name); |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
68 }, |
1096
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
69 loadBottlenecks({ commit }) { |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
70 var bottleneckFeatureCollectionRequest = new WFS().writeGetFeature({ |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
71 srsName: "EPSG:4326", |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
72 featureNS: "gemma", |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
73 featurePrefix: "gemma", |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
74 featureTypes: ["bottleneck_overview"], |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
75 outputFormat: "application/json" |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
76 }); |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
77 |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
78 HTTP.post( |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
79 "/internal/wfs", |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
80 new XMLSerializer().serializeToString( |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
81 bottleneckFeatureCollectionRequest |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
82 ), |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
83 { |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
84 headers: { |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
85 "X-Gemma-Auth": localStorage.getItem("token"), |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
86 "Content-type": "text/xml; charset=UTF-8" |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
87 } |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
88 } |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
89 ).then(response => { |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
90 commit("setBottlenecks", response.data.features); |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
91 }); |
1111
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
92 }, |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
93 querySurveys({ commit }, name) { |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
94 if (name) { |
1372
553aadd97087
new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
1363
diff
changeset
|
95 commit("surveysLoading", true); |
1111
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
96 HTTP.get("/surveys/" + name, { |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
97 headers: { |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
98 "X-Gemma-Auth": localStorage.getItem("token"), |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
99 "Content-type": "text/xml; charset=UTF-8" |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
100 } |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
101 }) |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
102 .then(response => { |
1480 | 103 const surveys = response.data.surveys.sort((a, b) => |
104 a.date_info < b.date_info ? 1 : -1 | |
1372
553aadd97087
new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
1363
diff
changeset
|
105 ); |
1394
b350b0b5cb6c
refactored fairwayprofile cross cuts
Markus Kottlaender <markus@intevation.de>
parents:
1386
diff
changeset
|
106 commit("selectedSurvey", surveys[0]); |
1372
553aadd97087
new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
1363
diff
changeset
|
107 commit("setSurveys", surveys); |
1111
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
108 }) |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
109 .catch(error => { |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
110 commit("setSurveys", []); |
1394
b350b0b5cb6c
refactored fairwayprofile cross cuts
Markus Kottlaender <markus@intevation.de>
parents:
1386
diff
changeset
|
111 commit("selectedSurvey", null); |
1111
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
112 const { status, data } = error.response; |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
113 displayError({ |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
114 title: "Backend Error", |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
115 message: `${status}: ${data.message || data}` |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
116 }); |
1372
553aadd97087
new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
1363
diff
changeset
|
117 }) |
553aadd97087
new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
1363
diff
changeset
|
118 .finally(() => commit("surveysLoading", false)); |
1111
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
119 } else { |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
120 commit("setSurveys", []); |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
121 } |
1096
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
122 } |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
123 } |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
124 }; |