diff --git a/src/services/feature-api.js b/src/services/feature-api.js index 988a0a3a3fca8c0923295ac0e0de67700aed09ef..49e40e12cb27cfe4043577a7cc66ca307cbf64a7 100644 --- a/src/services/feature-api.js +++ b/src/services/feature-api.js @@ -4,6 +4,20 @@ import store from '../store' const baseUrl = store.state.configuration.VUE_APP_DJANGO_API_BASE; const featureAPI = { + async getFeatureEvents(featureId) { + const response = await axios.get( + `${baseUrl}features/${featureId}/events/` + ); + if ( + response.status === 200 && + response.data + ) { + return response.data; + } else { + return null; + } + }, + async getFeatureAttachments(featureId) { const response = await axios.get( `${baseUrl}features/${featureId}/attachments/` diff --git a/src/store/modules/feature.js b/src/store/modules/feature.js index 37f00afd0454ec63f4e106fdd2ddfcc7d70acad0..e0d8fbc6875f6175824d3138b40114c2aa9cb8e7 100644 --- a/src/store/modules/feature.js +++ b/src/store/modules/feature.js @@ -7,6 +7,7 @@ axios.defaults.headers.common['X-CSRFToken'] = (name => { return (value != null) ? unescape(value[1]) : null; })('csrftoken'); +const DJANGO_API_BASE = process.env.VUE_APP_DJANGO_API_BASE const feature = { namespaced: true, @@ -100,7 +101,7 @@ const feature = { if (routeName === "editer-signalement") { axios - .put(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}features/${state.form.feature_id}/`, geojson) + .put(`${DJANGO_API_BASE}features/${state.form.feature_id}/`, geojson) .then((response) => { if (response.status === 200 && response.data) { router.push({ @@ -117,7 +118,7 @@ const feature = { }); } else { axios - .post(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}features/`, geojson) + .post(`${DJANGO_API_BASE}features/`, geojson) .then((response) => { if (response.status === 201 && response.data) { dispatch("SEND_ATTACHMENTS", response.data.id) @@ -146,7 +147,7 @@ const feature = { } formdata.append("data", JSON.stringify(data)); axios - .post(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}features/${featureId}/attachments/`, formdata) + .post(`${DJANGO_API_BASE}features/${featureId}/attachments/`, formdata) .then((response) => { if (response.status === 200 && response.data) { console.log(response, response.data) @@ -164,8 +165,17 @@ const feature = { .getlinked_features(featureId) .then((data) => commit("SET_FEATURE_LINKS", data)); } */ - //DELETE_FEATURE({ state }, feature_slug) { - //console.log("Deleting feature:", feature_slug, state) + DELETE_FEATURE({ state }, feature_id) { + console.log("Deleting feature:", feature_id, state) + const url=`${DJANGO_API_BASE}features/${feature_id}`; + axios + .delete(url, { + }) + .then() + .catch(() => { + return false; + }); + }, // POST_COMMENT({ state }, data) { //console.log("post comment", data, state) diff --git a/src/views/feature/Feature_detail.vue b/src/views/feature/Feature_detail.vue index 8b2c516d33814f65220cc0b7a795a4c281fc5060..49e6841fb31edc83772e457e8f2462d4fa0a4a6f 100644 --- a/src/views/feature/Feature_detail.vue +++ b/src/views/feature/Feature_detail.vue @@ -235,17 +235,15 @@ </div> <div class="extra text"> {{ event.related_comment.comment }} - <div v-frag v-if="event.related_comment.attachments"> - <div - v-frag - v-for="att in event.related_comment.attachments" - :key="att.title" + <div v-frag v-if="event.related_comment.attachment"> + <br /><a + :href=" + DJANGO_BASE_URL + event.related_comment.attachment.url + " + tarrget="_blank" + ><i class="paperclip fitted icon"></i> + {{ event.related_comment.attachment.title }}</a > - <br /><a :href="att.url" tarrget="_blank" - ><i class="paperclip fitted icon"></i> - {{ att.title }}</a - > - </div> </div> </div> </div> @@ -273,15 +271,6 @@ method="POST" enctype="multipart/form-data" > - <!-- <div - v-if="comment_form.non_field_errors" - class="alert alert-danger" - role="alert" - > - <span v-for="error in comment_form.non_field_errors" :key="error"> - {{ error }} - </span> - </div> --> <div class="required field"> <label :for="comment_form.comment.id_for_label" >Ajouter un commentaire</label @@ -459,12 +448,27 @@ export default { this.comment_form.attachment_file.value = shortName; this.comment_form.title.value = shortName; }, + goBackToProject(message) { + this.$router.push({ + name: "project_detail", + params: { + slug: this.$store.state.project_slug, + message, + }, + }); + }, deleteFeature() { this.$store.dispatch( "feature/DELETE_FEATURE", - this.$route.params.slug_signal - ); + this.feature.feature_id + ) + .then(() => { + this.$store.dispatch( + "feature/GET_PROJECT_FEATURES" + ) + this.goBackToProject(); + }); }, initMap() { @@ -539,6 +543,12 @@ export default { }); }, + getFeatureEvents() { + featureAPI + .getFeatureEvents(this.$route.params.slug_signal) + .then((data) => (this.events = data)); + }, + getFeatureAttachments() { featureAPI .getFeatureAttachments(this.$route.params.slug_signal) @@ -562,7 +572,7 @@ export default { "feature_type/SET_CURRENT_FEATURE_TYPE_SLUG", this.$route.params.slug_type_signal ); - + this.getFeatureEvents(); this.getFeatureAttachments(); this.getLinkedFeatures(); }, diff --git a/src/views/feature_type/Feature_type_detail.vue b/src/views/feature_type/Feature_type_detail.vue index cd18f5ec2fa0f784d0cf5452bbaef8081649ba32..e342caabe1dacdb531765fc2379fe99a0ec1d28f 100644 --- a/src/views/feature_type/Feature_type_detail.vue +++ b/src/views/feature_type/Feature_type_detail.vue @@ -29,7 +29,7 @@ <div class="ui basic segment"> <div class="ui horizontal tiny statistic"> <div class="value"> - {{ features.length }} + {{ feature_type_features.length }} </div> <div class="label"> Signalement{{ features.length > 1 ? "s" : "" }} @@ -222,8 +222,15 @@ export default { } return null; }, + + feature_type_features: function () { + return this.features.filter( + (el) => el.feature_type.slug === this.$route.params.feature_type_slug + ); + }, + lastFeatures: function () { - return this.features.slice(0, 5); + return this.feature_type_features.slice(0, 5); }, }, @@ -250,7 +257,7 @@ export default { }, exportFeatures() { const url = `${this.$store.state.configuration.VUE_APP_DJANGO_API_BASE}projects/${this.$route.params.slug}/feature-type/${this.$route.params.feature_type_slug}/export/`; - console.log(url) + console.log(url); window.open(url); }, },