Skip to content

Commit 676bfed

Browse files
committed
refactor(Exercise): move sources part into the main content
1 parent 1c63316 commit 676bfed

File tree

2 files changed

+60
-57
lines changed

2 files changed

+60
-57
lines changed

components/Panel/Item/DetailsPanel.vue

Lines changed: 2 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,17 @@
1212
</div>
1313
</div>
1414

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>
3215
</div>
3316
</div>
3417
</template>
3518

3619
<script lang="ts">
3720
import {Component, Prop, Vue} from "vue-property-decorator";
38-
import {Exercise, ExerciseMetrics, ExerciseTag} from "../../../types";
21+
import {Exercise, ExerciseTag} from "../../../types";
3922
import Icon from "~/components/Symbols/Icon.vue";
4023
import Rating from "~/components/Rating/Rating.vue";
41-
import {BusEvent} from "~/components/Event/BusEvent";
4224
import {AxiosError} from "axios";
4325
44-
const download = require('downloadjs');
45-
4626
@Component({
4727
components: {Rating, Icon}
4828
})
@@ -61,9 +41,7 @@
6141
* The exercise containing details, tags,...
6242
*/
6343
@Prop({type: Object, required: true}) exercise!: Exercise;
64-
65-
private cdnLink!: string;
66-
44+
6745
/**
6846
* Classify all tags by categories and sorts the categories
6947
*/
@@ -93,37 +71,6 @@
9371
return arrayOfTagByCategories
9472
}
9573
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-
12774
}
12875
</script>
12976

pages/exercices/_id.vue

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,31 @@
6363
</div>
6464
</div>
6565
<button v-if="isTheCreator || isAdmin || isSuperAdmin" @click="modifyExercise"
66-
class="button--ternary-color-reverse">Modifier l'exercice
66+
class="button--ternary-color-reverse modify-button">Modifier l'exercice
6767
</button>
6868

6969
<h2 class="title--primary-color__light">Description</h2>
7070

7171
<article v-html="exercise.description" class="exercise-article"></article>
72+
73+
<template v-if="!!exercise.url || !!exercise.file">
74+
75+
<h2 class="title--primary-color__light">Sources</h2>
76+
77+
<a v-if="!!exercise.url" :href="exercise.url" target="_blank" class="button-wrapper">
78+
<button class=" button--ternary-color-reverse">
79+
Lien vers l'exercice
80+
</button>
81+
</a>
82+
83+
<div v-if="!!exercise.file" @click="downloadFile" class="button-wrapper">
84+
<button class="button--ternary-color-reverse">
85+
Télécharger l'exercice
86+
</button>
87+
</div>
88+
89+
</template>
90+
7291
</section>
7392
</div>
7493
</div>
@@ -99,6 +118,8 @@
99118
hljs.registerLanguage('cmake', cmake);
100119
hljs.registerLanguage('cs', cs);
101120
121+
const download = require('downloadjs');
122+
102123
@Component({
103124
components: {
104125
Rating,
@@ -219,6 +240,33 @@
219240
}
220241
}
221242
243+
async downloadFile() {
244+
try {
245+
246+
const result:Blob = await this.$axios.$get(`/files/${this.exercise.file}`, {responseType: 'blob'});
247+
248+
download(result, "archive.zip", result.type);
249+
250+
this.$displaySuccess("Téléchargement éffectué.");
251+
252+
} catch (e) {
253+
const error = e as AxiosError;
254+
255+
if (error.response) {
256+
const status: number = error.response.status;
257+
258+
if (status === 404) {
259+
this.$displayError(`Ce fichier est introuvable`);
260+
} else if (status === 500) {
261+
this.$displayError(`Une erreur est survenue lors du téléchargement.`);
262+
}
263+
} else {
264+
this.$displayError(`Une erreur est survenue lors du téléchargement.`);
265+
}
266+
}
267+
}
268+
269+
222270
mounted() {
223271
if (process.client) {
224272
const exercise: Element | null = document.querySelector("#Exercise");
@@ -283,11 +331,19 @@
283331
}
284332
}
285333
334+
.button-wrapper {
335+
text-align: left;
336+
}
337+
286338
button {
339+
font-size: .75em;
340+
min-width: 250px;
341+
}
342+
343+
button.modify-button {
287344
position: absolute;
288345
right: 20px;
289346
top: 20px;
290-
font-size: .75em;
291347
}
292348
}
293349

0 commit comments

Comments
 (0)