diff --git a/src/services/feature-api.js b/src/services/feature-api.js new file mode 100644 index 0000000000000000000000000000000000000000..4a8f181fef71b9ce64e107d62d676467176754e6 --- /dev/null +++ b/src/services/feature-api.js @@ -0,0 +1,52 @@ +import axios from 'axios'; +import store from '../store' + +const baseUrl = store.state.configuration.VUE_APP_DJANGO_API_BASE; + +const featureAPI = { + async getFeatureAttachments(featureId) { + const response = await axios.get( + `${baseUrl}features/${featureId}/attachments/` + ); + if ( + response.status === 200 && + response.data + ) { + return response.data; + } else { + return null; + } + }, + + async postComment({ featureId, comment }) { + const response = await axios.get( + `${baseUrl}features/${featureId}/comments/`, { comment } + ); + console.log(response) + if ( + response.status === 200 && + response.data + ) { + return response.data; + } else { + return null; + } + }, + + /* async subscribeProject({ projectSlug, suscribe }) { + const response = await axios.put( + `${baseUrl}projects/${projectSlug}/subscription/`, + { is_suscriber: suscribe } + ); + if ( + response.status === 200 && + response.data + ) { + return response.data; + } else { + return null; + } + }, */ +} + +export default featureAPI; diff --git a/src/views/feature/Feature_detail.vue b/src/views/feature/Feature_detail.vue index 42eeec306a63a0e53b82e4f47796c02a5bfecdf8..b894f3b31c48bb6c94459cddffe805fae4eadadf 100644 --- a/src/views/feature/Feature_detail.vue +++ b/src/views/feature/Feature_detail.vue @@ -274,11 +274,7 @@ method="POST" enctype="multipart/form-data" > - <!-- action="{% url 'geocontrib:add_comment' slug=feature.project.slug feature_type_slug=feature.feature_type.slug feature_id=feature.feature_id%}" --> - <!-- {% for hidden in comment_form.hidden_fields %} - {{ hidden }} - {% endfor %} --> - <div + <!-- <div v-if="comment_form.non_field_errors" class="alert alert-danger" role="alert" @@ -286,7 +282,7 @@ <span v-for="error in comment_form.non_field_errors" :key="error"> {{ error }} </span> - </div> + </div> --> <div class="required field"> <label :for="comment_form.comment.id_for_label" >Ajouter un commentaire</label @@ -309,7 +305,6 @@ : "Sélectionner un fichier ..." }}</span> </label> - <!-- // todo : get image from "C:\\fakepath\..." --> <input type="file" accept="application/pdf, image/jpeg, image/png" @@ -318,7 +313,7 @@ id="attachment_file" @change="getAttachmentFileData($event)" /> - {{ comment_form.attachment_file.errors }} + <!-- {{ comment_form.attachment_file.errors }} --> </div> <div class="field"> <input @@ -444,6 +439,10 @@ export default { computed: { ...mapState(["user"]), + DJANGO_BASE_URL: function () { + return this.$store.state.configuration.VUE_APP_DJANGO_BASE; + }, + feature: function () { return ( this.$store.state.feature.features.find( @@ -451,6 +450,7 @@ export default { ) || [] ); }, + linked_features: function () { // todo: vérifier avec données réels si ça fonctionne correctement //return this.mock_linked_features.filter((el) => el.feature_to); @@ -460,14 +460,12 @@ export default { methods: { postComment() { - /* const data = { + featureAPI.postComment({ + featureId: this.$route.params.slug_signal, comment: this.comment_form.comment.value, - title: this.comment_form.title.value, - attachment_file: this.comment_form.attachment_file.value, - }; */ - this.$store.dispatch("feature/POST_COMMENT"); - //console.log("POST comment", data); + }); }, + getAttachmentFileData(evt) { const files = evt.target.files || evt.dataTransfer.files; const period = files[0].name.lastIndexOf("."); @@ -477,12 +475,14 @@ export default { this.comment_form.attachment_file.value = shortName; this.comment_form.title.value = shortName; }, + deleteFeature() { this.$store.dispatch( "feature/DELETE_FEATURE", this.$route.params.slug_signal ); }, + initMap() { var mapDefaultViewCenter = this.$store.state.configuration.DEFAULT_MAP_VIEW.center;