diff --git a/src/assets/js/map-util.js b/src/assets/js/map-util.js index f673e00ca6f3b97116c71f5a9b2005222a5b612d..89acc5e36ddc956b36bb996065b2988299592335 100644 --- a/src/assets/js/map-util.js +++ b/src/assets/js/map-util.js @@ -177,7 +177,31 @@ const mapUtil = { return map; }, + addGeocoders: function(configuration){ + let geocoder; + const geocoderLabel = configuration.SELECTED_GEOCODER.PROVIDER; + if (geocoderLabel) { + const LIMIT_RESULTS = 5; + if ( + geocoderLabel === configuration.GEOCODER_PROVIDERS.ADDOK + ) { + geocoder = L.Control.Geocoder.addok({ limit: LIMIT_RESULTS }); + } else if ( + geocoderLabel === configuration.GEOCODER_PROVIDERS.PHOTON + ) { + geocoder = L.Control.Geocoder.photon(); + } else if ( + geocoderLabel === configuration.GEOCODER_PROVIDERS.NOMINATIM + ) { + geocoder = L.Control.Geocoder.nominatim(); + } + L.Control.geocoder({ + placeholder: "Chercher une adresse...", + geocoder: geocoder, + }).addTo(map); + } + }, addLayers: function (layers, serviceMap, optionsMap) { if (layers) { layers.forEach((layer) => { diff --git a/src/store/index.js b/src/store/index.js index c06634cca67454fca4fc7d97ac608ab078ee22f6..b06d4c1ba1693bf467648882e13e6620af190cee 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -104,12 +104,12 @@ export default new Vuex.Store({ }, actions: { - async GET_ALL_PROJECTS({ commit }) { + GET_ALL_PROJECTS({ commit }) { function parseDate(date) { let dateArr = date.split("/").reverse(); return new Date(dateArr[0], dateArr[1] - 1, dateArr[2]); } - await axios + return axios .get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}projects/`) .then((response) => { if (response.status === 200 && response.data) { @@ -121,8 +121,8 @@ export default new Vuex.Store({ throw error; }); }, - async GET_STATIC_PAGES({ commit }) { - await axios + GET_STATIC_PAGES({ commit }) { + return axios .get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}flat-pages/`) .then((response) => (commit("SET_STATIC_PAGES", response.data))) .catch((error) => { @@ -163,7 +163,7 @@ export default new Vuex.Store({ }, USER_INFO({ commit }) { - axios + return axios .get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}user_info/`) .then((response) => { if (response && response.status === 200) { @@ -205,7 +205,7 @@ export default new Vuex.Store({ }); }, GET_USER_LEVEL_PROJECTS({ commit }) { - axios + return axios .get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}user-level-projects/`) .then((response) => { if (response && response.status === 200) { @@ -218,7 +218,7 @@ export default new Vuex.Store({ }, GET_USER_LEVEL_PERMISSIONS({ commit }) { - axios + return axios .get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}user-permissions/`) .then((response) => { if (response && response.status === 200) { @@ -232,14 +232,17 @@ export default new Vuex.Store({ GET_PROJECT_INFO({ commit, dispatch }, slug) { commit("SET_PROJECT_SLUG", slug); - dispatch("GET_PROJECT_LAST_MESSAGES", slug); - dispatch("feature_type/GET_PROJECT_FEATURE_TYPES", slug); - dispatch("feature/GET_PROJECT_FEATURES", slug); - dispatch("map/GET_BASEMAPS", slug); + return Promise.all([ + dispatch("GET_PROJECT_LAST_MESSAGES", slug), + dispatch("feature_type/GET_PROJECT_FEATURE_TYPES", slug), + dispatch("feature/GET_PROJECT_FEATURES", slug), + dispatch("map/GET_BASEMAPS", slug), + ]); + }, GET_PROJECT_LAST_MESSAGES({ commit }, project_slug) { - axios + return axios .get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}projects/${project_slug}/comments/`) .then((response) => { if (response && response.status === 200) { diff --git a/src/store/modules/feature_type.js b/src/store/modules/feature_type.js index f4148c1783d7d4c6ecc97ea7186b0bb418d12296..68ef9d09cb92ca9acb634d1faf87b83cb28593c4 100644 --- a/src/store/modules/feature_type.js +++ b/src/store/modules/feature_type.js @@ -71,7 +71,7 @@ const feature_type = { }, actions: { GET_PROJECT_FEATURE_TYPES({ commit }, project_slug) { - axios + return axios .get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}projects/${project_slug}/feature-types/`) .then((response) => commit("SET_FEATURE_TYPES", response.data.feature_types)) .catch((error) => { diff --git a/src/store/modules/map.js b/src/store/modules/map.js index f29ef9f4d128729e027c6364005edcad240fce6c..4a84a098f5bb2347b321b27cd09956360c87b3a7 100644 --- a/src/store/modules/map.js +++ b/src/store/modules/map.js @@ -88,7 +88,7 @@ const map = { actions: { GET_LAYERS({ commit }) { - axios + return axios .get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}layers/`) .then((response) => (commit("SET_LAYERS", response.data))) .catch((error) => { @@ -97,7 +97,7 @@ const map = { }, GET_BASEMAPS({ commit }, project_slug) { - axios + return axios .get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}base-maps/?project__slug=${project_slug}`) .then((response) => (commit("SET_BASEMAPS", response.data))) .catch((error) => { diff --git a/src/views/feature/Feature_edit.vue b/src/views/feature/Feature_edit.vue index 42ba0792215865860090715cd1356f391af04aa4..1b591450d85bd9dc055db6d3c259775502fc6667 100644 --- a/src/views/feature/Feature_edit.vue +++ b/src/views/feature/Feature_edit.vue @@ -1,5 +1,6 @@ <template> <div v-frag> + <script type="application/javascript" :src="baseUrl+'/resources/leaflet-control-geocoder-1.13.0/Control.Geocoder.js'"></script> <div class="fourteen wide column"> <h1 v-if="feature && currentRouteName === 'editer-signalement'"> Mise à jour du signalement "{{ feature.title || feature.feature_id }}" @@ -226,7 +227,7 @@ <script> import frag from "vue-frag"; -import { mapGetters, mapState } from "vuex"; +import { mapState } from "vuex"; import FeatureAttachmentForm from "@/components/feature/FeatureAttachmentForm"; import FeatureLinkedForm from "@/components/feature/FeatureLinkedForm"; import FeatureExtraForm from "@/components/feature/FeatureExtraForm"; @@ -265,6 +266,8 @@ export default { data() { return { map: null, + feature_type:null, + baseUrl:this.$store.state.configuration.BASE_URL, file: null, showGeoRef: false, showGeoPositionBtn: true, @@ -336,8 +339,6 @@ export default { "features", "extra_form", ]), - ...mapGetters("feature_type", ["feature_type"]), - field_title() { if (this.feature_type) { if (this.feature_type.title_optional) { @@ -369,11 +370,6 @@ export default { }, watch: { - feature_type() { - this.onFeatureTypeLoaded(); - this.initExtraForms(); - }, - feature(newValue) { if (this.$route.name === "editer-signalement") { this.initForm(); @@ -823,8 +819,6 @@ export default { }, initMap() { - //console.log(drawnItems); - //console.log(configuration); var mapDefaultViewCenter = this.$store.state.configuration.DEFAULT_MAP_VIEW.center; var mapDefaultViewZoom = @@ -882,11 +876,12 @@ export default { }, created() { + if (!this.project) { this.project = this.$store.state.projects.find((project) => project.slug === this.$store.state.project_slug); this.makeStatusChoicesFilter(); - this.$store.dispatch("GET_PROJECT_INFO", this.$route.params.slug); } + this.$store.commit( "feature_type/SET_CURRENT_FEATURE_TYPE_SLUG", this.$route.params.slug_type_signal @@ -904,8 +899,25 @@ export default { }, mounted() { - this.initForm(); - this.initMap(); + let ftSlug=this.$route.params.slug_type_signal; + this.$store.dispatch("GET_PROJECT_INFO", this.$route.params.slug).then(data=>{ + console.log(data) + this.initForm(); + this.initMap(); + this.feature_type=this.$store.state.feature_type.feature_types.find( + (el) => el.slug === ftSlug + ); + this.onFeatureTypeLoaded(); + this.initExtraForms(); + + setTimeout( + function () { + mapUtil.addGeocoders(this.$store.state.configuration); + }.bind(this), 1000); + }) + + + }, }; </script> diff --git a/src/views/feature/Feature_list.vue b/src/views/feature/Feature_list.vue index bc344e616ace60039371adea7be87026a52ee7e4..ad790844bbaefd7005a43b0484d01e1c94874490 100644 --- a/src/views/feature/Feature_list.vue +++ b/src/views/feature/Feature_list.vue @@ -276,8 +276,8 @@ <!-- |date:'Ymd' --> {{ feature.properties.updated_on }} </td> - <td class="center" v-if="user"> - {{ feature.properties.display_creator }} + <td class="center" v-if="user"> + {{ feature.properties.creator.username }} </td> </tr> <tr v-if="getFilteredFeatures().length === 0" class="odd"> @@ -365,8 +365,6 @@ <script> import { mapGetters, mapState } from "vuex"; - -import L from "leaflet"; import { mapUtil } from "@/assets/js/map-util.js"; import SidebarLayers from "@/components/map-layers/SidebarLayers"; import Dropdown from "@/components/Dropdown.vue"; @@ -630,37 +628,6 @@ export default { ), //* use Set to eliminate duplicate values ]; }, - addGeocoders() { - let geocoder; - - // Get the settings.py variable SELECTED_GEOCODER_PROVIDER. This way avoids XCC attacks - const geocoderLabel = - this.$store.state.configuration.SELECTED_GEOCODER.PROVIDER; - if (geocoderLabel) { - const LIMIT_RESULTS = 5; - if ( - geocoderLabel === - this.$store.state.configuration.GEOCODER_PROVIDERS.ADDOK - ) { - geocoder = L.Control.Geocoder.addok({ limit: LIMIT_RESULTS }); - } else if ( - geocoderLabel === - this.$store.state.configuration.GEOCODER_PROVIDERS.PHOTON - ) { - geocoder = L.Control.Geocoder.photon(); - } else if ( - geocoderLabel === - this.$store.state.configuration.GEOCODER_PROVIDERS.NOMINATIM - ) { - geocoder = L.Control.Geocoder.nominatim(); - } - - L.Control.geocoder({ - placeholder: "Chercher une adresse...", - geocoder: geocoder, - }).addTo(this.map); - } - }, }, created() { @@ -693,10 +660,8 @@ export default { }); // --------- End sidebar events ---------- - if(this.$route.params.slug != this.project.slug){ - if(this.$store.state.map.geojsonFeatures){ - this.loadFeatures(this.$store.state.map.geojsonFeatures); - } + if(this.$store.state.map.geojsonFeatures){ + this.loadFeatures(this.$store.state.map.geojsonFeatures); } else{ const url=`${this.$store.state.configuration.VUE_APP_DJANGO_API_BASE}projects/${this.$route.params.slug}/feature/?output=geojson`; @@ -713,13 +678,11 @@ export default { }); } - setTimeout( function () { - this.addGeocoders(); - }.bind(this), - 1000 - ); + mapUtil.addGeocoders(this.$store.state.configuration); + }.bind(this), 1000); + }, }; </script>