# HG changeset patch # User Thomas Junk # Date 1544100017 -3600 # Node ID 6b3756676bbe68419fc3d75446c88c85f244ba3f # Parent 43a32358a016f5784cf239ccd3e064b6ad635dca refac: bottlenecks and surveydata are now retrieved via promises diff -r 43a32358a016 -r 6b3756676bbe client/src/components/map/contextbox/Bottlenecks.vue --- a/client/src/components/map/contextbox/Bottlenecks.vue Thu Dec 06 12:38:08 2018 +0100 +++ b/client/src/components/map/contextbox/Bottlenecks.vue Thu Dec 06 13:40:17 2018 +0100 @@ -209,19 +209,38 @@ }); }, selectSurvey(survey, bottleneck) { - this.selectBottleneck(bottleneck); - this.$store.commit("bottlenecks/selectedSurvey", survey); + this.$store + .dispatch( + "bottlenecks/setSelectedBottleneck", + bottleneck.properties.name + ) + .then(() => { + this.$store.commit("bottlenecks/selectedSurvey", survey); + }) + .then(() => { + this.$store.commit("map/moveMap", { + coordinates: bottleneck.geometry.coordinates, + zoom: 17, + preventZoomOut: true + }); + }); }, selectBottleneck(bottleneck) { - this.$store.dispatch( - "bottlenecks/setSelectedBottleneck", - bottleneck.properties.name - ); - this.$store.commit("map/moveMap", { - coordinates: bottleneck.geometry.coordinates, - zoom: 17, - preventZoomOut: true - }); + this.$store + .dispatch( + "bottlenecks/setSelectedBottleneck", + bottleneck.properties.name + ) + .then(() => { + this.$store.commit("bottlenecks/setFirstSurveySelected"); + }) + .then(() => { + this.$store.commit("map/moveMap", { + coordinates: bottleneck.geometry.coordinates, + zoom: 17, + preventZoomOut: true + }); + }); }, sortBy(column) { this.sortColumn = column; diff -r 43a32358a016 -r 6b3756676bbe client/src/components/map/contextbox/Staging.vue --- a/client/src/components/map/contextbox/Staging.vue Thu Dec 06 12:38:08 2018 +0100 +++ b/client/src/components/map/contextbox/Staging.vue Thu Dec 06 13:40:17 2018 +0100 @@ -188,11 +188,11 @@ zoom: 17, preventZoomOut: true }); - this.$store.dispatch( - "bottlenecks/setSelectedBottleneck", - bottleneck, - date - ); + this.$store + .dispatch("bottlenecks/setSelectedBottleneck", bottleneck) + .then(() => { + this.$store.commit("bottlenecks/setSelectedSurveyByDate", date); + }); }, toggleApproval(id, newStatus) { this.$store.commit("imports/toggleApproval", { diff -r 43a32358a016 -r 6b3756676bbe client/src/store/bottlenecks.js --- a/client/src/store/bottlenecks.js Thu Dec 06 12:38:08 2018 +0100 +++ b/client/src/store/bottlenecks.js Thu Dec 06 13:40:17 2018 +0100 @@ -41,6 +41,13 @@ setSurveys(state, surveys) { state.surveys = surveys; }, + setSelectedSurveyByDate(state, date) { + const survey = state.surveys.filter(x => x.date_info === date)[0]; + state.selectedSurvey = survey; + }, + setFirstSurveySelected(state) { + state.selectedSurvey = state.surveys[0]; + }, selectedSurvey(state, survey) { state.selectedSurvey = survey; }, @@ -49,83 +56,80 @@ } }, actions: { - setSelectedBottleneck( - { state, commit, dispatch, rootState, rootGetters }, - name, - date - ) { - if (name !== state.selectedBottleneck) { - commit("selectedSurvey", null); - commit("fairwayprofile/clearCurrentProfile", null, { root: true }); - commit("application/showSplitscreen", false, { root: true }); - rootState.map.cutTool.setActive(false); - rootGetters["map/getVSourceByName"]("Cut Tool").clear(); - } - if (name) { - commit("application/showProfiles", true, { root: true }); - } - commit("setSelectedBottleneck", name); - dispatch("querySurveys", name, date); + setSelectedBottleneck({ state, commit, rootState, rootGetters }, name) { + return new Promise((resolve, reject) => { + if (name !== state.selectedBottleneck) { + commit("selectedSurvey", null); + commit("fairwayprofile/clearCurrentProfile", null, { root: true }); + commit("application/showSplitscreen", false, { root: true }); + rootState.map.cutTool.setActive(false); + rootGetters["map/getVSourceByName"]("Cut Tool").clear(); + } + if (name) { + commit("application/showProfiles", true, { root: true }); + } + commit("setSelectedBottleneck", name); + if (name) { + commit("surveysLoading", true); + HTTP.get("/surveys/" + name, { + headers: { + "X-Gemma-Auth": localStorage.getItem("token"), + "Content-type": "text/xml; charset=UTF-8" + } + }) + .then(response => { + const surveys = response.data.surveys.sort((a, b) => + a.date_info < b.date_info ? 1 : -1 + ); + commit("setSurveys", surveys); + resolve(response); + }) + .catch(error => { + commit("setSurveys", []); + commit("selectedSurvey", null); + const { status, data } = error.response; + displayError({ + title: "Backend Error", + message: `${status}: ${data.message || data}` + }); + reject(error); + }) + .finally(() => commit("surveysLoading", false)); + } else { + commit("setSurveys", []); + resolve(); + } + }); }, loadBottlenecks({ commit }) { - var bottleneckFeatureCollectionRequest = new WFS().writeGetFeature({ - srsName: "EPSG:4326", - featureNS: "gemma", - featurePrefix: "gemma", - featureTypes: ["bottleneck_overview"], - outputFormat: "application/json" - }); - - HTTP.post( - "/internal/wfs", - new XMLSerializer().serializeToString( - bottleneckFeatureCollectionRequest - ), - { - headers: { - "X-Gemma-Auth": localStorage.getItem("token"), - "Content-type": "text/xml; charset=UTF-8" + return new Promise((resolve, reject) => { + var bottleneckFeatureCollectionRequest = new WFS().writeGetFeature({ + srsName: "EPSG:4326", + featureNS: "gemma", + featurePrefix: "gemma", + featureTypes: ["bottleneck_overview"], + outputFormat: "application/json" + }); + HTTP.post( + "/internal/wfs", + new XMLSerializer().serializeToString( + bottleneckFeatureCollectionRequest + ), + { + headers: { + "X-Gemma-Auth": localStorage.getItem("token"), + "Content-type": "text/xml; charset=UTF-8" + } } - } - ).then(response => { - commit("setBottlenecks", response.data.features); - }); - }, - querySurveys({ commit }, name, date) { - if (name) { - commit("surveysLoading", true); - HTTP.get("/surveys/" + name, { - headers: { - "X-Gemma-Auth": localStorage.getItem("token"), - "Content-type": "text/xml; charset=UTF-8" - } - }) + ) .then(response => { - const surveys = response.data.surveys.sort((a, b) => - a.date_info < b.date_info ? 1 : -1 - ); - if (date) { - const survey = surveys.filter(x => x.date_info === date)[0]; - commit("selectedSurvey", survey); - } else { - commit("selectedSurvey", surveys[0]); - } - - commit("setSurveys", surveys); + commit("setBottlenecks", response.data.features); + resolve(response); }) .catch(error => { - commit("setSurveys", []); - commit("selectedSurvey", null); - const { status, data } = error.response; - displayError({ - title: "Backend Error", - message: `${status}: ${data.message || data}` - }); - }) - .finally(() => commit("surveysLoading", false)); - } else { - commit("setSurveys", []); - } + reject(error); + }); + }); } } };