annotate client/src/store/bottlenecks.js @ 1372:553aadd97087

new cross profile workflow (WIP) Needs fixing of some bugs and not so nice looks.
author Markus Kottlaender <markus@intevation.de>
date Tue, 27 Nov 2018 12:59:26 +0100
parents d0c4d17ee7ab
children 752b6bb2bee5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
d0c4d17ee7ab add missing authors
Fadi Abbud <fadi.abbud@intevation.de>
parents: 1362
diff changeset
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 },
f106aee673e7 selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents: 1096
diff changeset
44 setSelectedSurvey(state, survey) {
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: {
1111
f106aee673e7 selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents: 1096
diff changeset
52 setSelectedBottleneck({ state, commit, dispatch }, name) {
f106aee673e7 selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents: 1096
diff changeset
53 if (name !== state.selectedBottleneck) {
f106aee673e7 selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents: 1096
diff changeset
54 commit("setSelectedSurvey", null);
f106aee673e7 selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents: 1096
diff changeset
55 commit("fairwayprofile/clearCurrentProfile", null, { root: true });
f106aee673e7 selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents: 1096
diff changeset
56 }
1372
553aadd97087 new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents: 1363
diff changeset
57 if (name) {
553aadd97087 new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents: 1363
diff changeset
58 commit("application/showProfiles", true, { root: true });
553aadd97087 new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents: 1363
diff changeset
59 }
1111
f106aee673e7 selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents: 1096
diff changeset
60 commit("setSelectedBottleneck", name);
f106aee673e7 selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents: 1096
diff changeset
61 dispatch("querySurveys", name);
f106aee673e7 selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents: 1096
diff changeset
62 },
1096
aa1f5daf6fc9 refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
63 loadBottlenecks({ commit }) {
aa1f5daf6fc9 refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
64 var bottleneckFeatureCollectionRequest = new WFS().writeGetFeature({
aa1f5daf6fc9 refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
65 srsName: "EPSG:4326",
aa1f5daf6fc9 refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
66 featureNS: "gemma",
aa1f5daf6fc9 refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
67 featurePrefix: "gemma",
aa1f5daf6fc9 refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
68 featureTypes: ["bottleneck_overview"],
aa1f5daf6fc9 refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
69 outputFormat: "application/json"
aa1f5daf6fc9 refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
70 });
aa1f5daf6fc9 refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
71
aa1f5daf6fc9 refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
72 HTTP.post(
aa1f5daf6fc9 refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
73 "/internal/wfs",
aa1f5daf6fc9 refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
74 new XMLSerializer().serializeToString(
aa1f5daf6fc9 refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
75 bottleneckFeatureCollectionRequest
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 headers: {
aa1f5daf6fc9 refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
79 "X-Gemma-Auth": localStorage.getItem("token"),
aa1f5daf6fc9 refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
80 "Content-type": "text/xml; charset=UTF-8"
aa1f5daf6fc9 refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
81 }
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 ).then(response => {
aa1f5daf6fc9 refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
84 commit("setBottlenecks", response.data.features);
aa1f5daf6fc9 refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
85 });
1111
f106aee673e7 selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents: 1096
diff changeset
86 },
f106aee673e7 selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents: 1096
diff changeset
87 querySurveys({ commit }, name) {
f106aee673e7 selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents: 1096
diff changeset
88 if (name) {
1372
553aadd97087 new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents: 1363
diff changeset
89 commit("surveysLoading", true);
1111
f106aee673e7 selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents: 1096
diff changeset
90 HTTP.get("/surveys/" + name, {
f106aee673e7 selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents: 1096
diff changeset
91 headers: {
f106aee673e7 selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents: 1096
diff changeset
92 "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
93 "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
94 }
f106aee673e7 selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents: 1096
diff changeset
95 })
f106aee673e7 selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents: 1096
diff changeset
96 .then(response => {
1372
553aadd97087 new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents: 1363
diff changeset
97 const surveys = response.data.surveys.sort(
553aadd97087 new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents: 1363
diff changeset
98 (a, b) => (a.date_info < b.date_info ? 1 : -1)
553aadd97087 new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents: 1363
diff changeset
99 );
553aadd97087 new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents: 1363
diff changeset
100 commit("setSelectedSurvey", surveys[0]);
553aadd97087 new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents: 1363
diff changeset
101 commit("setSurveys", surveys);
1111
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 .catch(error => {
f106aee673e7 selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents: 1096
diff changeset
104 commit("setSurveys", []);
1372
553aadd97087 new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents: 1363
diff changeset
105 commit("setSelectedSurvey", null);
1111
f106aee673e7 selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents: 1096
diff changeset
106 const { status, data } = error.response;
f106aee673e7 selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents: 1096
diff changeset
107 displayError({
f106aee673e7 selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents: 1096
diff changeset
108 title: "Backend Error",
f106aee673e7 selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents: 1096
diff changeset
109 message: `${status}: ${data.message || data}`
f106aee673e7 selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents: 1096
diff changeset
110 });
1372
553aadd97087 new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents: 1363
diff changeset
111 })
553aadd97087 new cross profile workflow (WIP)
Markus Kottlaender <markus@intevation.de>
parents: 1363
diff changeset
112 .finally(() => commit("surveysLoading", false));
1111
f106aee673e7 selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents: 1096
diff changeset
113 } else {
f106aee673e7 selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents: 1096
diff changeset
114 commit("setSurveys", []);
f106aee673e7 selected bottleneck and surveys now handled by bottleneck store
Markus Kottlaender <markus@intevation.de>
parents: 1096
diff changeset
115 }
1096
aa1f5daf6fc9 refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
116 }
aa1f5daf6fc9 refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
117 }
aa1f5daf6fc9 refac: centralized stores
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
118 };