Skip to content

Commit 6295fd8

Browse files
authored
Merge pull request #58 from SourceCodeOER/enhancement
feat: Enhancement
2 parents d93556e + 7894be4 commit 6295fd8

File tree

23 files changed

+175
-114
lines changed

23 files changed

+175
-114
lines changed

components/Exercise/ExercisesPanel.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@
244244
245245
header {
246246
.results {
247-
font-weight: lighter;
247+
font-weight: 500;
248248
}
249249
}
250250

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

components/Panel/Item/HistoricalPanel.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@
9999
}
100100
101101
await this.$accessor.exercises.fetch({data: {tags: tagsRequest, title: title, vote: historical.vote}});
102+
103+
this.$emit('refresh');
102104
}
103105
}
104106
</script>

components/Tag/Tag.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@
4949
5050
.tag {
5151
display: inline-block;
52-
padding: 10px 10px;
52+
padding: 12px 12px;
53+
letter-spacing: .5px;
5354
border-radius: 4px;
5455
background-color: white;
5556
color: darken($SECONDARY_COLOR, 12);
5657
border: 1px solid darken($SECONDARY_COLOR, 12);
57-
font-weight: lighter;
58+
font-weight: bold;
5859
font-size: .75em;
5960
margin-right: 5px;
6061
margin-bottom: 10px;

pages/administration/categories/index.vue

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<div class="header-wrapper">
1919
<div class="input-wrapper--with-icon">
2020
<Icon type="search"/>
21-
<input ref="inputText" class="input--primary-color" type="text" v-model="searchModel"
21+
<input ref="inputText" class="input--primary-color" type="text" @input="resetIfEmpty" @keypress.enter="debounceInput"
2222
placeholder="Rechercher">
2323
</div>
2424

@@ -165,6 +165,22 @@
165165
})
166166
}
167167
168+
/**
169+
* Event for the input html element
170+
* Search with the title entered and update the store
171+
*/
172+
debounceInput(e: any) {
173+
this.searchModel = e.target.value;
174+
}
175+
176+
resetIfEmpty(e:any) {
177+
const value:string = e.target.value;
178+
179+
if(value === '') {
180+
this.searchModel = "";
181+
}
182+
}
183+
168184
/**
169185
* Add or remove an id from the selected tags array
170186
* Add if state of the checkbox is true and the item is not in the array

pages/administration/exercices/_id.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
</PanelItem>
2323

2424
<PanelItem>
25-
<FilterPanel strategy="admin" :reset-button="true" :search-mode="true" mode="strict" title="Tags"/>
25+
<FilterPanel strategy="admin" :search-mode="true" mode="strict" title="Tags"/>
2626
</PanelItem>
2727
</Panel>
2828

pages/administration/exercices/creer-exercice.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
</PanelItem>
2323

2424
<PanelItem>
25-
<FilterPanel strategy="admin" :reset-button="true" :search-mode="true" mode="strict" title="Tags"/>
25+
<FilterPanel strategy="admin" :search-mode="true" mode="strict" title="Tags"/>
2626
</PanelItem>
2727
</Panel>
2828

pages/administration/exercices/index.vue

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,17 @@
1515
<PanelItem>
1616
<FilterPanel strategy="admin" :radio-button-rating="true"
1717
:radio-button-state="true"
18-
:reset-button="true"
1918
:favorite="true"
2019
:search-mode="true"
2120
:historical-mode="true"
2221
@reset="resetInput"/>
2322
</PanelItem>
2423
<PanelItem>
25-
<HistoricalPanel/>
24+
<HistoricalPanel @refresh="refreshInput"/>
2625
</PanelItem>
2726

2827
<PanelItem>
29-
<FavoritePanel/>
28+
<FavoritePanel @fetch="refreshInput"/>
3029
</PanelItem>
3130
</Panel>
3231

@@ -42,7 +41,7 @@
4241
<div class="header-wrapper">
4342
<div class="input-wrapper--with-icon">
4443
<Icon type="search"/>
45-
<input ref="inputText" class="input--primary-color" type="text" v-on:input="debounceInput"
44+
<input ref="inputText" class="input--primary-color" type="text" @input="resetIfEmpty" @keypress.enter="debounceInput"
4645
placeholder="Rechercher">
4746
</div>
4847

@@ -165,8 +164,6 @@
165164
import {User} from "~/assets/js/api/user";
166165
import {AxiosError} from "axios";
167166
168-
const debounce = require('lodash.debounce');
169-
170167
const ratio = .2;
171168
172169
const download = require('downloadjs');
@@ -359,11 +356,23 @@
359356
* Event for the input html element
360357
* Search with the title entered and update the store
361358
*/
362-
debounceInput = debounce((e: any) => {
359+
debounceInput(e: any) {
363360
const value = e.target.value;
364361
this.$accessor.exercises.fetch({data: {title: value}});
365362
this.$accessor.historical.addHistorical({tags: this.$accessor.tags.selectedTags, title: value})
366-
}, 300);
363+
}
364+
365+
resetIfEmpty(e:any) {
366+
const value:string = e.target.value;
367+
368+
if(value === '') {
369+
this.$accessor.exercises.fetch({data: {title: ''}});
370+
}
371+
}
372+
373+
refreshInput() {
374+
this.inputText.value = this.$accessor.exercises.search_criterion.title || '';
375+
}
367376
368377
/**
369378
* Reset the input value

pages/administration/tags/index.vue

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
<Panel>
1515
<PanelItem>
1616
<TagFilterPanel
17-
:reset-button="true"
1817
:search-mode="true"
1918
@reset="resetInput"/>
2019
</PanelItem>
@@ -27,7 +26,7 @@
2726
<div class="header-wrapper">
2827
<div class="input-wrapper--with-icon">
2928
<Icon type="search"/>
30-
<input ref="inputText" class="input--primary-color" type="text" v-model="searchModel"
29+
<input ref="inputText" class="input--primary-color" type="text" @input="resetIfEmpty" @keypress.enter="debounceInput"
3130
placeholder="Rechercher">
3231
</div>
3332

@@ -219,6 +218,23 @@
219218
this.$accessor.tags.addOrRemoveTag({...tag, isSelected: state})
220219
}
221220
221+
222+
/**
223+
* Event for the input html element
224+
* Search with the title entered and update the store
225+
*/
226+
debounceInput(e: any) {
227+
this.searchModel = e.target.value;
228+
}
229+
230+
resetIfEmpty(e:any) {
231+
const value:string = e.target.value;
232+
233+
if(value === '') {
234+
this.searchModel = "";
235+
}
236+
}
237+
222238
/**
223239
* Remove from the databases the tags and update the tag store
224240
*/

pages/exercices/_id.vue

Lines changed: 58 additions & 3 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,
@@ -175,7 +196,6 @@
175196
const metrics: ExerciseMetrics | undefined = this.exercise.metrics;
176197
177198
if (metrics) {
178-
console.log(metrics);
179199
return metrics.votes
180200
}
181201
@@ -219,6 +239,33 @@
219239
}
220240
}
221241
242+
async downloadFile() {
243+
try {
244+
245+
const result:Blob = await this.$axios.$get(`/files/${this.exercise.file}`, {responseType: 'blob'});
246+
247+
download(result, "archive.zip", result.type);
248+
249+
this.$displaySuccess("Téléchargement éffectué.");
250+
251+
} catch (e) {
252+
const error = e as AxiosError;
253+
254+
if (error.response) {
255+
const status: number = error.response.status;
256+
257+
if (status === 404) {
258+
this.$displayError(`Ce fichier est introuvable`);
259+
} else if (status === 500) {
260+
this.$displayError(`Une erreur est survenue lors du téléchargement.`);
261+
}
262+
} else {
263+
this.$displayError(`Une erreur est survenue lors du téléchargement.`);
264+
}
265+
}
266+
}
267+
268+
222269
mounted() {
223270
if (process.client) {
224271
const exercise: Element | null = document.querySelector("#Exercise");
@@ -283,11 +330,19 @@
283330
}
284331
}
285332
333+
.button-wrapper {
334+
text-align: left;
335+
}
336+
286337
button {
338+
font-size: .75em;
339+
min-width: 250px;
340+
}
341+
342+
button.modify-button {
287343
position: absolute;
288344
right: 20px;
289345
top: 20px;
290-
font-size: .75em;
291346
}
292347
}
293348

0 commit comments

Comments
 (0)