annotate client/src/fairway/store.js @ 1013:15c3cc6f29a4

refac: fairwayprofile store cleanup
author Thomas Junk <thomas.junk@intevation.de>
date Tue, 23 Oct 2018 12:08:49 +0200
parents b9aaa093a9fb
children d2f30a784fb3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
767
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
1 import { HTTP } from "../application/lib/http";
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
2 import { prepareProfile } from "../application/lib/geo";
646
4450f2ab41e0 refac: Fairwawprofile view adapted
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
3
849
d63e60b868bf WIP Fairwayprofile
Thomas Junk <thomas.junk@intevation.de>
parents: 841
diff changeset
4 const DEMOLEVEL = 149.345;
d63e60b868bf WIP Fairwayprofile
Thomas Junk <thomas.junk@intevation.de>
parents: 841
diff changeset
5
646
4450f2ab41e0 refac: Fairwawprofile view adapted
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
6 const FairwayProfile = {
4450f2ab41e0 refac: Fairwawprofile view adapted
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
7 namespaced: true,
4450f2ab41e0 refac: Fairwawprofile view adapted
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
8 state: {
1013
15c3cc6f29a4 refac: fairwayprofile store cleanup
Thomas Junk <thomas.junk@intevation.de>
parents: 896
diff changeset
9 availableSurveys: null,
767
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
10 totalLength: 0,
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
11 minAlt: 0,
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
12 maxAlt: 0,
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
13 currentProfile: [],
896
b9aaa093a9fb fix: splitbutton only visible when result is visible
Thomas Junk <thomas.junk@intevation.de>
parents: 849
diff changeset
14 waterLevels: [{ year: "2016", level: DEMOLEVEL, color: "#005DFF" }],
849
d63e60b868bf WIP Fairwayprofile
Thomas Junk <thomas.junk@intevation.de>
parents: 841
diff changeset
15 selectedWaterLevel: DEMOLEVEL,
802
327aa4a18a1c Fairway profile WIP
Thomas Junk <thomas.junk@intevation.de>
parents: 786
diff changeset
16 fairwayCoordinates: [],
767
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
17 startPoint: null,
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
18 endPoint: null
646
4450f2ab41e0 refac: Fairwawprofile view adapted
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
19 },
4450f2ab41e0 refac: Fairwawprofile view adapted
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
20 getters: {
767
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
21 length: state => {
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
22 return state.totalLength;
646
4450f2ab41e0 refac: Fairwawprofile view adapted
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
23 }
4450f2ab41e0 refac: Fairwawprofile view adapted
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
24 },
767
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
25 mutations: {
1013
15c3cc6f29a4 refac: fairwayprofile store cleanup
Thomas Junk <thomas.junk@intevation.de>
parents: 896
diff changeset
26 setAvailableSurveys: (state, surveys) => {
15c3cc6f29a4 refac: fairwayprofile store cleanup
Thomas Junk <thomas.junk@intevation.de>
parents: 896
diff changeset
27 state.availableSurveys = surveys;
15c3cc6f29a4 refac: fairwayprofile store cleanup
Thomas Junk <thomas.junk@intevation.de>
parents: 896
diff changeset
28 },
841
07be3e5f99a9 WIP Fairwayprofile
Thomas Junk <thomas.junk@intevation.de>
parents: 802
diff changeset
29 setSelectedWaterLevel: (state, level) => {
07be3e5f99a9 WIP Fairwayprofile
Thomas Junk <thomas.junk@intevation.de>
parents: 802
diff changeset
30 state.selectedWaterLevel = level;
07be3e5f99a9 WIP Fairwayprofile
Thomas Junk <thomas.junk@intevation.de>
parents: 802
diff changeset
31 },
767
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
32 profileLoaded: (state, response) => {
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
33 const { data } = response;
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
34 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
35 if (!coordinates) return;
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
36 const startPoint = state.startPoint;
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
37 const endPoint = state.endPoint;
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
38 const geoJSON = data;
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
39 const result = prepareProfile({ geoJSON, startPoint, endPoint });
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
40 state.currentProfile = result.points;
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
41 state.minAlt = result.minAlt;
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
42 state.maxAlt = result.maxAlt;
780
c98f88ac08a4 Fairwayprofile WIP
Thomas Junk <thomas.junk@intevation.de>
parents: 767
diff changeset
43 state.totalLength = result.lengthPolyLine;
767
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
44 },
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
45 setStartPoint: (state, start) => {
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
46 state.startPoint = start;
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
47 },
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
48 setEndPoint: (state, end) => {
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
49 state.endPoint = end;
802
327aa4a18a1c Fairway profile WIP
Thomas Junk <thomas.junk@intevation.de>
parents: 786
diff changeset
50 },
327aa4a18a1c Fairway profile WIP
Thomas Junk <thomas.junk@intevation.de>
parents: 786
diff changeset
51 setFairwayCoordinates: (state, coordinates) => {
327aa4a18a1c Fairway profile WIP
Thomas Junk <thomas.junk@intevation.de>
parents: 786
diff changeset
52 state.fairwayCoordinates = coordinates;
767
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
53 }
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
54 },
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
55
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
56 actions: {
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
57 loadProfile({ commit }, geoJSON) {
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
58 return new Promise((resolve, reject) => {
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
59 HTTP.post("/cross", geoJSON, {
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
60 headers: { "X-Gemma-Auth": localStorage.getItem("token") }
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
61 })
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
62 .then(response => {
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
63 commit("profileLoaded", response);
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
64 resolve(response);
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
65 })
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
66 .catch(error => {
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
67 reject(error);
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
68 });
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
69 });
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
70 }
dedf252b3e01 feat: fairwayprofile partially with retrieved data from the server
Thomas Junk <thomas.junk@intevation.de>
parents: 646
diff changeset
71 }
646
4450f2ab41e0 refac: Fairwawprofile view adapted
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
72 };
4450f2ab41e0 refac: Fairwawprofile view adapted
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
73
4450f2ab41e0 refac: Fairwawprofile view adapted
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
74 export default FairwayProfile;