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 0efb50511d8f147b0c7f816a2a07fc8e589595ed..64791f0a7a06b86f164c2d088c9f13daf3dc115c 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -3,7 +3,6 @@ const axios = require("axios"); import Vue from 'vue'; import Vuex from 'vuex'; import router from '../router' -//import modules from './modules'; import feature_type from "./modules/feature_type" import feature from "./modules/feature" import map from "./modules/map" @@ -100,16 +99,16 @@ export default new Vuex.Store({ project: state => state.projects.find((project) => project.slug === state.project_slug), permissions: state => state.user_permissions ? state.user_permissions[state.project_slug] : noPermissions, project_types: state => state.projects.filter(projet => projet.is_project_type), - project_user: state => state.projects.filter(projet => projet.creator === state.user.id), // todo: add id to user in api + project_user: state => state.projects.filter(projet => projet.creator === state.user.id), }, 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 +120,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) => { @@ -179,12 +178,12 @@ export default new Vuex.Store({ } }, - LOGOUT({ commit }) { // ? logout se fait bien dans django ? + LOGOUT({ commit }) { axios .get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}logout/`) .then((response) => { if (response && response.status === 200) { - commit("SET_USER", false); // ? better false or null + commit("SET_USER", false); commit("SET_USER_LEVEL_PROJECTS", null); commit("SET_USER_PERMISSIONS", null); router.push("/"); @@ -209,7 +208,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) { @@ -222,7 +221,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) { @@ -243,7 +242,7 @@ export default new Vuex.Store({ }, 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) { @@ -254,52 +253,6 @@ export default new Vuex.Store({ throw error; }); }, - - /* GET_PROJECT_USER({ commit }, project_slug) { - axios - .get(`${DJANGO_API_BASE}projects/${project_slug}/utilisateurs`) - .then((response) => (commit("SET_PROJECT_MEMBERS", response.data.members))) - .catch((error) => { - throw error; - }); - }, */ - /* GET_PROJECT_FEATURES({ commit }, project_slug) { - axios - .get(`${DJANGO_API_BASE}projects/${project_slug}/feature`) - .then((response) => commit("feature/SET_FEATURES", response.data.features)) - .catch((error) => { - throw error; - }); - }, - */ - /* GET_PROJECT({ commit }, project_slug) { - axios - .get(`${DJANGO_API_BASE}projects/${project_slug}/project`) - .then((response) => commit("SET_PROJECT", response.data)) - .catch((error) => { - throw error; - }); - }, - */ - /* GET_COOKIE({ commit }, name) { - let cookieValue = null; - - if (document.cookie && document.cookie !== "") { - const cookies = document.cookie.split(";"); - for (let i = 0; i < cookies.length; i++) { - const cookie = cookies[i].trim(); - - // Does this cookie string begin with the name we want? - if (cookie.substring(0, name.length + 1) === name + "=") { - cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); - - break; - } - } - } - commit("SET_COOKIE", cookieValue); - }, */ - } }); 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>