diff --git a/src/services/feature-api.js b/src/services/feature-api.js new file mode 100644 index 0000000000000000000000000000000000000000..0968431c33f4e194ecc4ca04a3ed7ad4e02b9203 --- /dev/null +++ b/src/services/feature-api.js @@ -0,0 +1,37 @@ +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 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..246bebf5fd1859d5e1b719e24de5cc7cc325076d 100644 --- a/src/views/feature/Feature_detail.vue +++ b/src/views/feature/Feature_detail.vue @@ -183,18 +183,15 @@ target="_blank" :href="pj.attachment_file.url" > - <img - v-if="pj.extension === '.pdf'" - src="{% static 'geocontrib/img/pdf.png' %}" - /> - <!-- // ? que faire ? --> - <img v-else :src="pj.attachment_file.url" /> + <!-- // ? que faire avec un pdf ? --> + <img v-if="pj.extension === '.pdf'" src="@/assets/img/pdf.png" /> + <img v-else :src="DJANGO_BASE_URL + pj.attachment_file" /> </a> <div class="middle aligned content"> <a class="header" target="_blank" - :href="pj.attachment_file.url" + :href="DJANGO_BASE_URL + pj.attachment_file.url" >{{ pj.title }}</a > <div class="description"> @@ -382,6 +379,7 @@ import frag from "vue-frag"; import { mapState } from "vuex"; import { mapUtil } from "@/assets/js/map-util.js"; +import featureAPI from "@/services/feature-api"; const axios = require("axios"); export default { @@ -407,18 +405,8 @@ export default { }, }, */ ], - attachments: [ - // TODO : Récupérer depuis l'api - /* { - attachment_file: { - url: "http://localhost:8000/media/user_1/albinoscom.jpg", - }, - extension: "jpg", - title: "albinos", - info: "Drôle de bête", - }, */ - ], - // TODO : Récupérer depuis l'api + attachments: [], + // TODO : Récupérer events depuis l'api events: [], comment_form: { attachment_file: { @@ -444,6 +432,9 @@ 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( @@ -564,6 +555,9 @@ export default { "feature_type/SET_CURRENT_FEATURE_TYPE_SLUG", this.$route.params.slug_type_signal ); + featureAPI + .getFeatureAttachments(this.$route.params.slug_signal) + .then((data) => (this.attachments = data)); }, mounted() {