|
12 | 12 | </div> |
13 | 13 | </div> |
14 | 14 |
|
15 | | - |
16 | | - <div v-if="!!exercise.url || !!exercise.file" class="sources"> |
17 | | - <h3>Sources</h3> |
18 | | - |
19 | | - <a v-if="!!exercise.url" :href="exercise.url" target="_blank" class="button-wrapper"> |
20 | | - <button class=" button--ternary-color-reverse"> |
21 | | - Lien vers l'exercice |
22 | | - </button> |
23 | | - </a> |
24 | | - |
25 | | - <div v-if="!!exercise.file" @click="downloadFile" class="button-wrapper"> |
26 | | - <button class="button--ternary-color-reverse"> |
27 | | - Télécharger l'exercice |
28 | | - </button> |
29 | | - </div> |
30 | | - |
31 | | - </div> |
32 | 15 | </div> |
33 | 16 | </div> |
34 | 17 | </template> |
35 | 18 |
|
36 | 19 | <script lang="ts"> |
37 | 20 | import {Component, Prop, Vue} from "vue-property-decorator"; |
38 | | - import {Exercise, ExerciseMetrics, ExerciseTag} from "../../../types"; |
| 21 | + import {Exercise, ExerciseTag} from "../../../types"; |
39 | 22 | import Icon from "~/components/Symbols/Icon.vue"; |
40 | 23 | import Rating from "~/components/Rating/Rating.vue"; |
41 | | - import {BusEvent} from "~/components/Event/BusEvent"; |
42 | 24 | import {AxiosError} from "axios"; |
43 | 25 |
|
44 | | - const download = require('downloadjs'); |
45 | | -
|
46 | 26 | @Component({ |
47 | 27 | components: {Rating, Icon} |
48 | 28 | }) |
|
61 | 41 | * The exercise containing details, tags,... |
62 | 42 | */ |
63 | 43 | @Prop({type: Object, required: true}) exercise!: Exercise; |
64 | | -
|
65 | | - private cdnLink!: string; |
66 | | -
|
| 44 | + |
67 | 45 | /** |
68 | 46 | * Classify all tags by categories and sorts the categories |
69 | 47 | */ |
|
93 | 71 | return arrayOfTagByCategories |
94 | 72 | } |
95 | 73 |
|
96 | | - async downloadFile() { |
97 | | - try { |
98 | | -
|
99 | | - const result:Blob = await this.$axios.$get(`/files/${this.exercise.file}`, {responseType: 'blob'}); |
100 | | -
|
101 | | - download(result, "archive.zip", result.type); |
102 | | -
|
103 | | - this.$displaySuccess("Téléchargement éffectué."); |
104 | | -
|
105 | | - } catch (e) { |
106 | | - const error = e as AxiosError; |
107 | | -
|
108 | | - if (error.response) { |
109 | | - const status: number = error.response.status; |
110 | | -
|
111 | | - if (status === 404) { |
112 | | - this.$displayError(`Ce fichier est introuvable`); |
113 | | - } else if (status === 500) { |
114 | | - this.$displayError(`Une erreur est survenue lors du téléchargement.`); |
115 | | - } |
116 | | - } else { |
117 | | - this.$displayError(`Une erreur est survenue lors du téléchargement.`); |
118 | | - } |
119 | | - } |
120 | | - } |
121 | | -
|
122 | | - created() { |
123 | | - const link: string | undefined = this.$accessor.sharedEnv.CDN_SERVER; |
124 | | - this.cdnLink = link ? link : '' |
125 | | - } |
126 | | -
|
127 | 74 | } |
128 | 75 | </script> |
129 | 76 |
|
|
0 commit comments