diff --git a/src/store/index.js b/src/store/index.js index 5035d682a0b278a2279c895d9deb3318b400fd56..3060f1beb6337b71f7bbe3058bf2fb65d0b082d3 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -235,12 +235,12 @@ export default new Vuex.Store({ }); }, - GET_PROJECT_INFO({ state, commit, dispatch }, slug) { + async GET_PROJECT_INFO({ state, 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); - if (state.user) dispatch("map/GET_BASEMAPS", slug); + await dispatch("GET_PROJECT_LAST_MESSAGES", slug); + await dispatch("feature_type/GET_PROJECT_FEATURE_TYPES", slug); + await dispatch("feature/GET_PROJECT_FEATURES", slug); + if (state.user) await dispatch("map/GET_BASEMAPS", slug); }, GET_PROJECT_LAST_MESSAGES({ commit }, project_slug) { diff --git a/src/store/modules/feature.js b/src/store/modules/feature.js index 60df940e2d32e0468710621e3c9e1bf6c21693ef..d57841b8e8036d417442e11ab0a978a0f7dcf3bd 100644 --- a/src/store/modules/feature.js +++ b/src/store/modules/feature.js @@ -68,7 +68,7 @@ const feature = { }, actions: { GET_PROJECT_FEATURES({ commit, rootState }, project_slug) { - axios + return axios .get(`${rootState.configuration.VUE_APP_DJANGO_API_BASE}projects/${project_slug}/feature/`) .then((response) => { if (response.status === 200 && response.data) { diff --git a/src/views/feature/Feature_edit.vue b/src/views/feature/Feature_edit.vue index da49900b25a1c4df3df16735e001afe25307738a..dc47e926c9e5f2b2a7b1e6db42841828225be906 100644 --- a/src/views/feature/Feature_edit.vue +++ b/src/views/feature/Feature_edit.vue @@ -1,6 +1,12 @@ <template> <div v-frag> - <script type="application/javascript" :src="baseUrl+'/resources/leaflet-control-geocoder-1.13.0/Control.Geocoder.js'"></script> + <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 }}" @@ -265,8 +271,8 @@ export default { data() { return { map: null, - feature_type:null, - baseUrl:this.$store.state.configuration.BASE_URL, + feature_type: null, + baseUrl: this.$store.state.configuration.BASE_URL, file: null, showGeoRef: false, showGeoPositionBtn: true, @@ -274,23 +280,23 @@ export default { erreurUploadMessage: null, attachmentDataKey: 0, linkedDataKey: 0, - statusChoicesFilter:[], + statusChoicesFilter: [], statusChoices: [ { name: "Brouillon", value: "draft", }, - { + { name: "Publié", - value: "published" + value: "published", }, - { + { name: "Archivé", - value: "archived" + value: "archived", }, - { + { name: "En attente de publication", - value: "pending" + value: "pending", }, ], form: { @@ -369,29 +375,29 @@ export default { }, }, - watch: { +/* watch: { feature(newValue) { if (this.$route.name === "editer-signalement") { this.initForm(); this.initExtraForms(newValue); } }, - }, + }, */ methods: { - makeStatusChoicesFilter(){ - let newStatusChoices = this.statusChoices - if (this.project){ - if (!this.project.moderation){ - newStatusChoices = [] - this.statusChoices.forEach(function(status) { - if (status.value !== 'pending') { - newStatusChoices.push(status) + makeStatusChoicesFilter() { + let newStatusChoices = this.statusChoices; + if (this.project) { + if (!this.project.moderation) { + newStatusChoices = []; + this.statusChoices.forEach(function (status) { + if (status.value !== "pending") { + newStatusChoices.push(status); } }); } } - this.statusChoicesFilter = newStatusChoices + this.statusChoicesFilter = newStatusChoices; }, initForm() { if (this.currentRouteName === "editer-signalement") { @@ -452,25 +458,24 @@ export default { }, }) .then(function (response) { - console.log("SUCCESS!!",response.data); - if(response.data.geom.indexOf('POINT')>=0){ - let regexp=/POINT\s\((.*)\s(.*)\)/; + console.log("SUCCESS!!", response.data); + if (response.data.geom.indexOf("POINT") >= 0) { + let regexp = /POINT\s\((.*)\s(.*)\)/; var arr = regexp.exec(response.data.geom); - - let json={ "type": "Feature", - "geometry": { - "type": "Point", - "coordinates": [arr[1], arr[2]] + + let json = { + type: "Feature", + geometry: { + type: "Point", + coordinates: [arr[1], arr[2]], }, - "properties": { - } + properties: {}, }; - self.updateMap(self.map, json) - self.updateGeomField(json) + self.updateMap(self.map, json); + self.updateGeomField(json); // Set Attachment //self.addAttachment(self.file) } - }) .catch(function (response) { console.log("FAILURE!!"); @@ -792,8 +797,8 @@ export default { ); }, - updateMap(map, geomFeatureJSON) { - this.drawnItems.clearLayers(); + updateMap(geomFeatureJSON) { + if (this.drawnItems) this.drawnItems.clearLayers(); console.log("update map"); var geomType = this.feature_type.geom_type; if (geomFeatureJSON) { @@ -837,7 +842,7 @@ export default { axios .get(url) .then((response) => { - //console.log(response); + console.log(response.data.features); const features = response.data.features; if (features) { const allFeaturesExceptCurrent = features.filter( @@ -891,7 +896,9 @@ export default { created() { if (!this.project) { - this.project = this.$store.state.projects.find((project) => project.slug === this.$store.state.project_slug); + this.project = this.$store.state.projects.find( + (project) => project.slug === this.$store.state.project_slug + ); this.makeStatusChoicesFilter(); } @@ -911,25 +918,27 @@ export default { }, mounted() { - let ftSlug=this.$route.params.slug_type_signal; - this.$store.dispatch("GET_PROJECT_INFO", this.$route.params.slug).then(data=>{ - console.log(data) + 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 - ); + console.log(this.$store.state.feature_type.feature_types) + 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); - }) - - - + }.bind(this), + 1000 + ); + }); }, }; </script>