Mercurial > gemma
annotate client/src/store/bottlenecks.js @ 1511:53fdbe1d9678
fix: staging select according soundingresult
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Wed, 05 Dec 2018 15:51:26 +0100 |
parents | 9b81ac91a43e |
children | 6b3756676bbe |
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 }, |
1511
53fdbe1d9678
fix: staging select according soundingresult
Thomas Junk <thomas.junk@intevation.de>
parents:
1480
diff
changeset
|
54 name, |
53fdbe1d9678
fix: staging select according soundingresult
Thomas Junk <thomas.junk@intevation.de>
parents:
1480
diff
changeset
|
55 date |
1386
752b6bb2bee5
close splitscreen and clear cut tool when changing bottleneck
Markus Kottlaender <markus@intevation.de>
parents:
1372
diff
changeset
|
56 ) { |
1111
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
57 if (name !== state.selectedBottleneck) { |
1394
b350b0b5cb6c
refactored fairwayprofile cross cuts
Markus Kottlaender <markus@intevation.de>
parents:
1386
diff
changeset
|
58 commit("selectedSurvey", null); |
1111
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
59 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
|
60 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
|
61 rootState.map.cutTool.setActive(false); |
752b6bb2bee5
close splitscreen and clear cut tool when changing bottleneck
Markus Kottlaender <markus@intevation.de>
parents:
1372
diff
changeset
|
62 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
|
63 } |
1372
553aadd97087
new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
1363
diff
changeset
|
64 if (name) { |
553aadd97087
new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
1363
diff
changeset
|
65 commit("application/showProfiles", true, { root: true }); |
553aadd97087
new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
1363
diff
changeset
|
66 } |
1111
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
67 commit("setSelectedBottleneck", name); |
1511
53fdbe1d9678
fix: staging select according soundingresult
Thomas Junk <thomas.junk@intevation.de>
parents:
1480
diff
changeset
|
68 dispatch("querySurveys", name, date); |
1111
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
69 }, |
1096
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
70 loadBottlenecks({ commit }) { |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
71 var bottleneckFeatureCollectionRequest = new WFS().writeGetFeature({ |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
72 srsName: "EPSG:4326", |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
73 featureNS: "gemma", |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
74 featurePrefix: "gemma", |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
75 featureTypes: ["bottleneck_overview"], |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
76 outputFormat: "application/json" |
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 |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
79 HTTP.post( |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
80 "/internal/wfs", |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
81 new XMLSerializer().serializeToString( |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
82 bottleneckFeatureCollectionRequest |
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 { |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
85 headers: { |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
86 "X-Gemma-Auth": localStorage.getItem("token"), |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
87 "Content-type": "text/xml; charset=UTF-8" |
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 } |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
90 ).then(response => { |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
91 commit("setBottlenecks", response.data.features); |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
92 }); |
1111
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
93 }, |
1511
53fdbe1d9678
fix: staging select according soundingresult
Thomas Junk <thomas.junk@intevation.de>
parents:
1480
diff
changeset
|
94 querySurveys({ commit }, name, date) { |
1111
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
95 if (name) { |
1372
553aadd97087
new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
1363
diff
changeset
|
96 commit("surveysLoading", true); |
1111
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
97 HTTP.get("/surveys/" + name, { |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
98 headers: { |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
99 "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
|
100 "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
|
101 } |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
102 }) |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
103 .then(response => { |
1480 | 104 const surveys = response.data.surveys.sort((a, b) => |
105 a.date_info < b.date_info ? 1 : -1 | |
1372
553aadd97087
new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
1363
diff
changeset
|
106 ); |
1511
53fdbe1d9678
fix: staging select according soundingresult
Thomas Junk <thomas.junk@intevation.de>
parents:
1480
diff
changeset
|
107 if (date) { |
53fdbe1d9678
fix: staging select according soundingresult
Thomas Junk <thomas.junk@intevation.de>
parents:
1480
diff
changeset
|
108 const survey = surveys.filter(x => x.date_info === date)[0]; |
53fdbe1d9678
fix: staging select according soundingresult
Thomas Junk <thomas.junk@intevation.de>
parents:
1480
diff
changeset
|
109 commit("selectedSurvey", survey); |
53fdbe1d9678
fix: staging select according soundingresult
Thomas Junk <thomas.junk@intevation.de>
parents:
1480
diff
changeset
|
110 } else { |
53fdbe1d9678
fix: staging select according soundingresult
Thomas Junk <thomas.junk@intevation.de>
parents:
1480
diff
changeset
|
111 commit("selectedSurvey", surveys[0]); |
53fdbe1d9678
fix: staging select according soundingresult
Thomas Junk <thomas.junk@intevation.de>
parents:
1480
diff
changeset
|
112 } |
53fdbe1d9678
fix: staging select according soundingresult
Thomas Junk <thomas.junk@intevation.de>
parents:
1480
diff
changeset
|
113 |
1372
553aadd97087
new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
1363
diff
changeset
|
114 commit("setSurveys", surveys); |
1111
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
115 }) |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
116 .catch(error => { |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
117 commit("setSurveys", []); |
1394
b350b0b5cb6c
refactored fairwayprofile cross cuts
Markus Kottlaender <markus@intevation.de>
parents:
1386
diff
changeset
|
118 commit("selectedSurvey", null); |
1111
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
119 const { status, data } = error.response; |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
120 displayError({ |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
121 title: "Backend Error", |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
122 message: `${status}: ${data.message || data}` |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
123 }); |
1372
553aadd97087
new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
1363
diff
changeset
|
124 }) |
553aadd97087
new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
1363
diff
changeset
|
125 .finally(() => commit("surveysLoading", false)); |
1111
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
126 } else { |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
127 commit("setSurveys", []); |
f106aee673e7
selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents:
1096
diff
changeset
|
128 } |
1096
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
129 } |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
130 } |
aa1f5daf6fc9
refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
131 }; |