|
7 | 7 |
|
8 | 8 | <div v-if="exercise" class="status"> |
9 | 9 | <template v-if="exercise.state === 'VALIDATED'"> |
10 | | - Valide <Icon type="check" theme="theme--green"/> |
| 10 | + Valide |
| 11 | + <Icon type="check" theme="theme--green"/> |
11 | 12 | </template> |
12 | 13 |
|
13 | 14 | <template v-else-if="exercise.state === 'NOT_VALIDATED'"> |
14 | | - Non valide <Icon type="close" theme="theme--red-light"/> |
| 15 | + Non valide |
| 16 | + <Icon type="close" theme="theme--red-light"/> |
15 | 17 | </template> |
16 | 18 |
|
17 | 19 | <template v-else-if="exercise.state === 'PENDING'"> |
18 | | - En attente <Icon type="send" theme="theme--yellow"/> |
| 20 | + En attente |
| 21 | + <Icon type="send" theme="theme--yellow"/> |
19 | 22 | </template> |
20 | 23 |
|
21 | 24 | <template v-else-if="exercise.state === 'DRAFT'"> |
22 | | - Brouillon <Icon title="Créé" type="paper" theme="theme--primary-color-light"/> |
| 25 | + Brouillon |
| 26 | + <Icon title="Créé" type="paper" theme="theme--primary-color-light"/> |
23 | 27 | </template> |
24 | 28 |
|
25 | 29 | <template v-else-if="exercise.state === 'ARCHIVED'"> |
26 | | - Archivé <Icon type="archive" theme="theme--red-light"/> |
| 30 | + Archivé |
| 31 | + <Icon type="archive" theme="theme--red-light"/> |
27 | 32 | </template> |
28 | 33 | </div> |
29 | 34 |
|
30 | 35 | <ValidationObserver ref="observer1" tag="form" @submit.prevent="validateBeforeSubmit()"> |
31 | | - <ValidationProvider tag="label" |
32 | | - name="titre" |
33 | | - rules="required|min:3|max:200" |
34 | | - v-slot="{ errors }"> |
35 | | - <span class="label__name"> |
| 36 | + <TextInput |
| 37 | + tag="label" |
| 38 | + name="titre" |
| 39 | + v-model="form.title" |
| 40 | + :value="form.title" |
| 41 | + @input="debounceInput" |
| 42 | + placeholder="Entrez le nom de votre exercice" |
| 43 | + rules="required|min:3|max:200"> |
| 44 | + <span class="label__name"> |
36 | 45 | Titre * |
37 | | - </span> |
38 | | - <input id="Title" placeholder="Entrez le nom de votre exercice" name="title" v-model="form.title" |
39 | | - v-on:input="debounceInput" class="input--grey" type="text"> |
40 | | - <span class="error-message">{{errors[0]}}</span> |
41 | | - </ValidationProvider> |
| 46 | + </span> |
| 47 | + </TextInput> |
42 | 48 |
|
43 | 49 | </ValidationObserver> |
44 | 50 |
|
|
101 | 107 | <span class="error-message">{{errors[0]}}</span> |
102 | 108 | </ValidationProvider> |
103 | 109 |
|
104 | | - <ValidationProvider tag="label" |
105 | | - name="tag" |
106 | | - rules="required|min:3|max:100" |
107 | | - v-slot="{ errors }"> |
108 | | - <input id="NewTagName" name="selectedNewTag.text" placeholder="Entrez votre nouveau tag" |
109 | | - v-model="selectedNewTag.text" |
110 | | - class="input--grey" type="text"> |
111 | | - <span class="error-message">{{errors[0]}}</span> |
112 | | - </ValidationProvider> |
| 110 | + <TextInput |
| 111 | + tag="label" |
| 112 | + name="tag" |
| 113 | + rules="required|min:3|max:100" |
| 114 | + v-model="selectedNewTag.text" |
| 115 | + placeholder="Entrez votre nouveau tag"> |
| 116 | + </TextInput> |
113 | 117 |
|
114 | 118 | <button :class="{'button--ternary-color-reverse': valid, 'button--ternary-color': !valid}" type="submit"> |
115 | 119 | Ajouter ce tag |
|
119 | 123 |
|
120 | 124 | <ValidationObserver ref="observer2" tag="form" |
121 | 125 | @submit.prevent="validateBeforeSubmit"> |
122 | | - <ValidationProvider tag="div" |
123 | | - name="archive zip" |
124 | | - rules="mimes:application/zip,application/x-zip,application/x-zip-compressed,application/octet-stream" |
125 | | - ref="fileObserver" |
126 | | - v-slot="{ errors, validate }"> |
127 | | - <span class="label__name"> |
| 126 | + <FileInput |
| 127 | + name="archive zip" |
| 128 | + rules="mimes:application/zip,application/x-zip,application/x-zip-compressed,application/octet-stream" |
| 129 | + :default-filename="filename" |
| 130 | + @input="updateFile" |
| 131 | + ref="fileObserver"> |
| 132 | + |
| 133 | + <span class="label__name"> |
128 | 134 | Uploadez votre archive (zip) |
129 | | - </span> |
130 | | - <input id="Archive" name="archive" ref="inputFile" @change="selectedFile" class="input--secondary-color" |
131 | | - type="file"> |
132 | | - <label for="Archive"> |
133 | | - <Icon type="archive" theme="theme--white"/> |
134 | | - {{labelFileText}}</label> |
135 | | - <span class="error-message">{{errors[0]}}</span> |
| 135 | + </span> |
| 136 | + |
| 137 | + <template v-slot:footer> |
136 | 138 | <span v-if="exercise && exercise.file && filename" @click="downloadFile" |
137 | | - class="message message--primary-color" |
138 | | - style="text-decoration: underline; cursor: pointer;">Télécharger le fichier</span> |
139 | | - <span class="message message--red" v-if="filename" |
140 | | - style="text-decoration: underline; cursor: pointer;" |
141 | | - @click="deleteFile">Supprimer le fichier</span> |
142 | | - </ValidationProvider> |
143 | | - |
144 | | - <ValidationProvider tag="label" |
145 | | - name="url" |
146 | | - rules="url" |
147 | | - v-slot="{ errors }"> |
148 | | - <span class="label__name"> |
| 139 | + class="message message--primary-color" |
| 140 | + style="text-decoration: underline; cursor: pointer;">Télécharger le fichier</span> |
| 141 | + |
| 142 | + </template> |
| 143 | + </FileInput> |
| 144 | + |
| 145 | + <TextInput |
| 146 | + tag="label" |
| 147 | + name="url" |
| 148 | + type="url" |
| 149 | + v-model="form.url" |
| 150 | + placeholder="Entrez l'url absolue vers votre exercice" |
| 151 | + rules="url"> |
| 152 | + <span class="label__name"> |
149 | 153 | Url vers l'exercice |
150 | | - </span> |
151 | | - <input id="Url" type="url" placeholder="Entrez l'url absolue vers votre exercice" name="url" v-model="form.url" |
152 | | - class="input--grey"> |
153 | | - <span class="error-message">{{errors[0]}}</span> |
154 | | - </ValidationProvider> |
| 154 | + </span> |
| 155 | + </TextInput> |
155 | 156 | </ValidationObserver> |
156 | 157 |
|
157 | 158 |
|
|
207 | 208 | import jsonFormData from 'json-form-data'; |
208 | 209 | import ExerciseFormMixins from "~/components/Mixins/ExerciseFormMixins"; |
209 | 210 | import TagColorLegend from "~/components/Tag/TagColorLegend.vue"; |
210 | | -
|
211 | | - const debounce = require('lodash.debounce'); |
| 211 | + import TextInput from "~/components/Input/TextInput.vue"; |
| 212 | + import FileInput from "~/components/Input/FileInput.vue"; |
212 | 213 |
|
213 | 214 | const download = require('downloadjs'); |
214 | 215 |
|
215 | 216 | @Component({ |
216 | | - components: {TagColorLegend, CustomSelect, ValidationObserver, ValidationProvider, RichTextEditor, Tag, Icon} |
| 217 | + components: { |
| 218 | + FileInput, |
| 219 | + TextInput, |
| 220 | + TagColorLegend, CustomSelect, ValidationObserver, ValidationProvider, RichTextEditor, Tag, Icon |
| 221 | + } |
217 | 222 | }) |
218 | 223 | export default class ExerciseForm extends Mixins(FilterPanelMixins, ExerciseFormMixins) { |
219 | 224 | @Prop({type: Object, default: undefined}) exercise!: Exercise | undefined; |
|
265 | 270 | exerciseBuild.url = this.form.url; |
266 | 271 | } |
267 | 272 |
|
268 | | - const file: File | null = this.file(); |
| 273 | + const file: File | null = this.file; |
269 | 274 |
|
270 | 275 | if (file !== null) { |
271 | 276 |
|
|
341 | 346 | } catch (e) { |
342 | 347 | const error = e as AxiosError; |
343 | 348 |
|
344 | | - if(error.response) { |
| 349 | + if (error.response) { |
345 | 350 | const status: number = error.response.status; |
346 | 351 |
|
347 | | - if(status === 400) { |
| 352 | + if (status === 400) { |
348 | 353 | this.$displayError(`Vous ne respectez pas les conditions pour publier la catégorie.`); |
349 | | - } else if(status === 401) { |
| 354 | + } else if (status === 401) { |
350 | 355 | this.$displayError("Vous devez vous connecter pour effectuer cette action.") |
351 | | - } else if(status === 403) { |
| 356 | + } else if (status === 403) { |
352 | 357 | this.$displayError(`Vous n'êtes pas autorisé à effectuer cette action !`); |
353 | | - } else if(status === 409) { |
| 358 | + } else if (status === 409) { |
354 | 359 | this.$displayError(`Un conflit a été détecté. Vérifiez vos données.`); |
355 | | - } else if(status === 500) { |
| 360 | + } else if (status === 500) { |
356 | 361 | this.$displayError(`Une erreur est survenue depuis nos serveurs, veuillez-nous en excuser.`); |
357 | 362 | } |
358 | 363 | } else { |
|
370 | 375 | } |
371 | 376 |
|
372 | 377 | async downloadFile() { |
373 | | - if(this.exercise) { |
| 378 | + if (this.exercise) { |
374 | 379 | try { |
375 | 380 |
|
376 | | - const result:Blob = await this.$axios.$get(`/files/${this.exercise.file}`, {responseType: 'blob'}); |
| 381 | + const result: Blob = await this.$axios.$get(`/files/${this.exercise.file}`, {responseType: 'blob'}); |
377 | 382 |
|
378 | 383 | download(result, "archive.zip", result.type); |
379 | 384 |
|
|
0 commit comments