From 994f5585a3b7335e109b999c21a4776ba834afaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Poussard?= <tpoussard@neogeo.fr> Date: Tue, 21 Sep 2021 14:48:07 +0200 Subject: [PATCH] display attachments in feature_detail --- src/services/feature-api.js | 37 ++++++++++++++++++++++++++++ src/views/feature/Feature_detail.vue | 32 ++++++++++-------------- 2 files changed, 50 insertions(+), 19 deletions(-) create mode 100644 src/services/feature-api.js diff --git a/src/services/feature-api.js b/src/services/feature-api.js new file mode 100644 index 00000000..0968431c --- /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 42eeec30..246bebf5 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() { -- GitLab