annotate client/src/store/fairway.js @ 1096:aa1f5daf6fc9

refac: centralized stores
author Thomas Junk <thomas.junk@intevation.de>
date Tue, 30 Oct 2018 16:55:29 +0100
parents client/src/fairway/store.js@7242b5a427bc
children f106aee673e7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1019
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 1015
diff changeset
1 /*
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 1015
diff changeset
2 * This is Free Software under GNU Affero General Public License v >= 3.0
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 1015
diff changeset
3 * without warranty, see README.md and license for details.
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 1015
diff changeset
4 *
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 1015
diff changeset
5 * SPDX-License-Identifier: AGPL-3.0-or-later
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 1015
diff changeset
6 * License-Filename: LICENSES/AGPL-3.0.txt
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 1015
diff changeset
7 *
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 1015
diff changeset
8 * Copyright (C) 2018 by via donau
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 1015
diff changeset
9 * – Österreichische Wasserstraßen-Gesellschaft mbH
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 1015
diff changeset
10 * Software engineering by Intevation GmbH
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 1015
diff changeset
11 *
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 1015
diff changeset
12 * Author(s):
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 1015
diff changeset
13 * Thomas Junk <thomas.junk@intevation.de>
1044
f8a4ec146d47 fixed Vue reactivity issue (splitscreen button)
Markus Kottlaender <markus@intevation.de>
parents: 1038
diff changeset
14 * Markus Kottländer <markuks.kottlaender@intevation.de>
1019
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 1015
diff changeset
15 */
1044
f8a4ec146d47 fixed Vue reactivity issue (splitscreen button)
Markus Kottlaender <markus@intevation.de>
parents: 1038
diff changeset
16 import Vue from "vue";
1028
dd67e46366ef refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents: 1027
diff changeset
17 import { HTTP } from "../application/lib/http";
767
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
18 import { prepareProfile } from "../application/lib/geo";
1028
dd67e46366ef refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents: 1027
diff changeset
19 import LineString from "ol/geom/LineString.js";
dd67e46366ef refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents: 1027
diff changeset
20 import { generateFeatureRequest } from "../application/lib/geo.js";
646
4450f2ab41e0 refac: Fairwawprofile view adapted
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
21
849
d63e60b868bf WIP Fairwayprofile
Thomas Junk <thomas.junk@intevation.de>
parents: 841
diff changeset
22 const DEMOLEVEL = 149.345;
d63e60b868bf WIP Fairwayprofile
Thomas Junk <thomas.junk@intevation.de>
parents: 841
diff changeset
23
646
4450f2ab41e0 refac: Fairwawprofile view adapted
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
24 const FairwayProfile = {
4450f2ab41e0 refac: Fairwawprofile view adapted
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
25 namespaced: true,
4450f2ab41e0 refac: Fairwawprofile view adapted
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
26 state: {
1056
28eb62f7c676 additional survey as dynamic property
Thomas Junk <thomas.junk@intevation.de>
parents: 1044
diff changeset
27 additionalSurvey: "",
1013
15c3cc6f29a4 refac: fairwayprofile store cleanup
Thomas Junk <thomas.junk@intevation.de>
parents: 896
diff changeset
28 availableSurveys: null,
767
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
29 totalLength: 0,
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
30 minAlt: 0,
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
31 maxAlt: 0,
1025
a55f20dc8d8d refac: store profiles by date
Thomas Junk <thomas.junk@intevation.de>
parents: 1020
diff changeset
32 currentProfile: {},
896
b9aaa093a9fb fix: splitbutton only visible when result is visible
Thomas Junk <thomas.junk@intevation.de>
parents: 849
diff changeset
33 waterLevels: [{ year: "2016", level: DEMOLEVEL, color: "#005DFF" }],
849
d63e60b868bf WIP Fairwayprofile
Thomas Junk <thomas.junk@intevation.de>
parents: 841
diff changeset
34 selectedWaterLevel: DEMOLEVEL,
802
327aa4a18a1c Fairway profile WIP
Thomas Junk <thomas.junk@intevation.de>
parents: 786
diff changeset
35 fairwayCoordinates: [],
767
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
36 startPoint: null,
1027
04a9e78dcc5f refac: remove morphstore. not necessary
Thomas Junk <thomas.junk@intevation.de>
parents: 1025
diff changeset
37 endPoint: null,
04a9e78dcc5f refac: remove morphstore. not necessary
Thomas Junk <thomas.junk@intevation.de>
parents: 1025
diff changeset
38 selectedMorph: null
646
4450f2ab41e0 refac: Fairwawprofile view adapted
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
39 },
4450f2ab41e0 refac: Fairwawprofile view adapted
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
40 getters: {
767
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
41 length: state => {
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
42 return state.totalLength;
1056
28eb62f7c676 additional survey as dynamic property
Thomas Junk <thomas.junk@intevation.de>
parents: 1044
diff changeset
43 },
28eb62f7c676 additional survey as dynamic property
Thomas Junk <thomas.junk@intevation.de>
parents: 1044
diff changeset
44 additionalSurvey: state => {
28eb62f7c676 additional survey as dynamic property
Thomas Junk <thomas.junk@intevation.de>
parents: 1044
diff changeset
45 return state.additionalSurvey;
646
4450f2ab41e0 refac: Fairwawprofile view adapted
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
46 }
4450f2ab41e0 refac: Fairwawprofile view adapted
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
47 },
767
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
48 mutations: {
1056
28eb62f7c676 additional survey as dynamic property
Thomas Junk <thomas.junk@intevation.de>
parents: 1044
diff changeset
49 setAdditionalSurvey: (state, additionalSurvey) => {
28eb62f7c676 additional survey as dynamic property
Thomas Junk <thomas.junk@intevation.de>
parents: 1044
diff changeset
50 state.additionalSurvey = additionalSurvey;
28eb62f7c676 additional survey as dynamic property
Thomas Junk <thomas.junk@intevation.de>
parents: 1044
diff changeset
51 },
1027
04a9e78dcc5f refac: remove morphstore. not necessary
Thomas Junk <thomas.junk@intevation.de>
parents: 1025
diff changeset
52 setSelectedMorph: (state, selectedMorph) => {
04a9e78dcc5f refac: remove morphstore. not necessary
Thomas Junk <thomas.junk@intevation.de>
parents: 1025
diff changeset
53 state.selectedMorph = selectedMorph;
04a9e78dcc5f refac: remove morphstore. not necessary
Thomas Junk <thomas.junk@intevation.de>
parents: 1025
diff changeset
54 },
1013
15c3cc6f29a4 refac: fairwayprofile store cleanup
Thomas Junk <thomas.junk@intevation.de>
parents: 896
diff changeset
55 setAvailableSurveys: (state, surveys) => {
15c3cc6f29a4 refac: fairwayprofile store cleanup
Thomas Junk <thomas.junk@intevation.de>
parents: 896
diff changeset
56 state.availableSurveys = surveys;
15c3cc6f29a4 refac: fairwayprofile store cleanup
Thomas Junk <thomas.junk@intevation.de>
parents: 896
diff changeset
57 },
841
07be3e5f99a9 WIP Fairwayprofile
Thomas Junk <thomas.junk@intevation.de>
parents: 802
diff changeset
58 setSelectedWaterLevel: (state, level) => {
07be3e5f99a9 WIP Fairwayprofile
Thomas Junk <thomas.junk@intevation.de>
parents: 802
diff changeset
59 state.selectedWaterLevel = level;
07be3e5f99a9 WIP Fairwayprofile
Thomas Junk <thomas.junk@intevation.de>
parents: 802
diff changeset
60 },
1025
a55f20dc8d8d refac: store profiles by date
Thomas Junk <thomas.junk@intevation.de>
parents: 1020
diff changeset
61 profileLoaded: (state, answer) => {
a55f20dc8d8d refac: store profiles by date
Thomas Junk <thomas.junk@intevation.de>
parents: 1020
diff changeset
62 const { response, surveyDate } = answer;
767
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
63 const { data } = response;
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
64 const coordinates = data.geometry.coordinates;
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
65 if (!coordinates) return;
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
66 const startPoint = state.startPoint;
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
67 const endPoint = state.endPoint;
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
68 const geoJSON = data;
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
69 const result = prepareProfile({ geoJSON, startPoint, endPoint });
1044
f8a4ec146d47 fixed Vue reactivity issue (splitscreen button)
Markus Kottlaender <markus@intevation.de>
parents: 1038
diff changeset
70 // Use Vue.set() to make new object properties rective
f8a4ec146d47 fixed Vue reactivity issue (splitscreen button)
Markus Kottlaender <markus@intevation.de>
parents: 1038
diff changeset
71 // https://vuejs.org/v2/guide/reactivity.html#Change-Detection-Caveats
f8a4ec146d47 fixed Vue reactivity issue (splitscreen button)
Markus Kottlaender <markus@intevation.de>
parents: 1038
diff changeset
72 Vue.set(state.currentProfile, surveyDate, result.points);
1056
28eb62f7c676 additional survey as dynamic property
Thomas Junk <thomas.junk@intevation.de>
parents: 1044
diff changeset
73 if (!state.minAlt || state.minAlt > result.minAlt) {
28eb62f7c676 additional survey as dynamic property
Thomas Junk <thomas.junk@intevation.de>
parents: 1044
diff changeset
74 state.minAlt = result.minAlt;
28eb62f7c676 additional survey as dynamic property
Thomas Junk <thomas.junk@intevation.de>
parents: 1044
diff changeset
75 }
28eb62f7c676 additional survey as dynamic property
Thomas Junk <thomas.junk@intevation.de>
parents: 1044
diff changeset
76 if (!state.maxAlt || state.maxAlt < result.maxAlt) {
28eb62f7c676 additional survey as dynamic property
Thomas Junk <thomas.junk@intevation.de>
parents: 1044
diff changeset
77 state.maxAlt = result.maxAlt;
28eb62f7c676 additional survey as dynamic property
Thomas Junk <thomas.junk@intevation.de>
parents: 1044
diff changeset
78 }
1057
7242b5a427bc completely nulling the units
Thomas Junk <thomas.junk@intevation.de>
parents: 1056
diff changeset
79 if (!state.totalLength || state.totalLength < result.lengthPolyLine) {
1056
28eb62f7c676 additional survey as dynamic property
Thomas Junk <thomas.junk@intevation.de>
parents: 1044
diff changeset
80 state.totalLength = result.lengthPolyLine;
28eb62f7c676 additional survey as dynamic property
Thomas Junk <thomas.junk@intevation.de>
parents: 1044
diff changeset
81 }
767
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
82 },
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
83 setStartPoint: (state, start) => {
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
84 state.startPoint = start;
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
85 },
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
86 setEndPoint: (state, end) => {
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
87 state.endPoint = end;
802
327aa4a18a1c Fairway profile WIP
Thomas Junk <thomas.junk@intevation.de>
parents: 786
diff changeset
88 },
327aa4a18a1c Fairway profile WIP
Thomas Junk <thomas.junk@intevation.de>
parents: 786
diff changeset
89 setFairwayCoordinates: (state, coordinates) => {
327aa4a18a1c Fairway profile WIP
Thomas Junk <thomas.junk@intevation.de>
parents: 786
diff changeset
90 state.fairwayCoordinates = coordinates;
1015
d2f30a784fb3 feat: add selectfield to fairwayprofile
Thomas Junk <thomas.junk@intevation.de>
parents: 1013
diff changeset
91 },
d2f30a784fb3 feat: add selectfield to fairwayprofile
Thomas Junk <thomas.junk@intevation.de>
parents: 1013
diff changeset
92 clearCurrentProfile: state => {
1056
28eb62f7c676 additional survey as dynamic property
Thomas Junk <thomas.junk@intevation.de>
parents: 1044
diff changeset
93 state.additionalSurvey = "";
1025
a55f20dc8d8d refac: store profiles by date
Thomas Junk <thomas.junk@intevation.de>
parents: 1020
diff changeset
94 state.currentProfile = {};
1057
7242b5a427bc completely nulling the units
Thomas Junk <thomas.junk@intevation.de>
parents: 1056
diff changeset
95 state.minAlt = null;
7242b5a427bc completely nulling the units
Thomas Junk <thomas.junk@intevation.de>
parents: 1056
diff changeset
96 state.maxAlt = null;
7242b5a427bc completely nulling the units
Thomas Junk <thomas.junk@intevation.de>
parents: 1056
diff changeset
97 state.totalLength = null;
7242b5a427bc completely nulling the units
Thomas Junk <thomas.junk@intevation.de>
parents: 1056
diff changeset
98 state.fairwayCoordinates = [];
7242b5a427bc completely nulling the units
Thomas Junk <thomas.junk@intevation.de>
parents: 1056
diff changeset
99 state.startPoint = null;
7242b5a427bc completely nulling the units
Thomas Junk <thomas.junk@intevation.de>
parents: 1056
diff changeset
100 state.endPoint = null;
767
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
101 }
1028
dd67e46366ef refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents: 1027
diff changeset
102 },
dd67e46366ef refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents: 1027
diff changeset
103 actions: {
dd67e46366ef refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents: 1027
diff changeset
104 loadProfile({ commit, state }, date_info) {
dd67e46366ef refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents: 1027
diff changeset
105 return new Promise((resolve, reject) => {
dd67e46366ef refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents: 1027
diff changeset
106 const profileLine = new LineString([state.startPoint, state.endPoint]);
dd67e46366ef refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents: 1027
diff changeset
107 const geoJSON = generateFeatureRequest(
dd67e46366ef refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents: 1027
diff changeset
108 profileLine,
dd67e46366ef refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents: 1027
diff changeset
109 state.selectedMorph.bottleneck_id,
dd67e46366ef refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents: 1027
diff changeset
110 date_info
dd67e46366ef refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents: 1027
diff changeset
111 );
dd67e46366ef refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents: 1027
diff changeset
112 HTTP.post("/cross", geoJSON, {
dd67e46366ef refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents: 1027
diff changeset
113 headers: { "X-Gemma-Auth": localStorage.getItem("token") }
dd67e46366ef refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents: 1027
diff changeset
114 })
dd67e46366ef refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents: 1027
diff changeset
115 .then(response => {
dd67e46366ef refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents: 1027
diff changeset
116 commit("profileLoaded", {
dd67e46366ef refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents: 1027
diff changeset
117 response: response,
dd67e46366ef refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents: 1027
diff changeset
118 surveyDate: date_info
dd67e46366ef refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents: 1027
diff changeset
119 });
dd67e46366ef refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents: 1027
diff changeset
120 resolve(response);
dd67e46366ef refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents: 1027
diff changeset
121 })
dd67e46366ef refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents: 1027
diff changeset
122 .catch(error => {
dd67e46366ef refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents: 1027
diff changeset
123 reject(error);
dd67e46366ef refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents: 1027
diff changeset
124 });
dd67e46366ef refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents: 1027
diff changeset
125 });
dd67e46366ef refac: loading of profile data via fairwayprofile store
Thomas Junk <thomas.junk@intevation.de>
parents: 1027
diff changeset
126 }
767
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
127 }
646
4450f2ab41e0 refac: Fairwawprofile view adapted
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
128 };
4450f2ab41e0 refac: Fairwawprofile view adapted
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
129
4450f2ab41e0 refac: Fairwawprofile view adapted
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
130 export default FairwayProfile;