ProjetRIOT/components/main-controller.riot

125 lines
4.7 KiB
Plaintext
Raw Normal View History

2023-03-28 13:42:53 +02:00
<main-controller>
<div class="columns">
<div class="column is-one-third">
2023-03-28 16:52:53 +02:00
<div class="box p-3 m-2">
2023-03-31 11:34:14 +02:00
<img class="mt-1 ml-5 mr-auto" style="margin: auto;" src="./resources/logo-parcoursup.svg"/>
2023-03-28 16:17:29 +02:00
</div>
2023-03-29 22:01:50 +02:00
<search updateCourse={updateCourse}></search>
2023-03-28 13:42:53 +02:00
</div>
<div class="column">
<fili-info schoolList={state.schoolList} course={state.course} shouldShowInfos={state.shouldShowInfos}></fili-info>
2023-03-31 11:34:14 +02:00
<school sortList={sortList} schoolList={state.filteredSchoolList} sortFields={state.sortFields} course={state.course} shouldShowInfos={state.shouldShowInfos}></school>
2023-03-28 13:42:53 +02:00
</div>
</div>
<school-info></school-info>
<script>
import PAPI from '../javascript/parcoursup-link.js'
const SORT_TABLE = [
{name: "Nom", id: "g_ea_lib_vx"},
{name: "Ville", id: "ville_etab"},
{name: "Département", id: "dep"},
{name: "Moyenne", id: "moyenne"},
{name: "Sélectivité", id: "taux_acces_ens"}
]
export default {
sortList(sortBy) {
//Si la liste est déjà triée par la bonne catégorie, on l'inverse
if (sortBy == this.state.sortBy) {
2023-03-31 11:34:14 +02:00
this.state.filteredSchoolList.reverse()
}
//Sinon on l'ordonne par la nouvelle catégorie (ascendant par défaut)
else {
this.state.sortBy = sortBy
switch (sortBy) {
case SORT_TABLE[3].id:
case SORT_TABLE[4].id: {
2023-03-31 11:34:14 +02:00
this.state.filteredSchoolList.sort((a, b) => {
if (a.fields[sortBy] > b.fields[sortBy]) return 1
else return -1
})
break
}
default: {
2023-03-31 11:34:14 +02:00
this.state.filteredSchoolList.sort((a, b) => {
return (a.fields[sortBy]).localeCompare(b.fields[sortBy])
})
break
}
}
2023-03-29 22:01:50 +02:00
}
2023-03-31 11:34:14 +02:00
this.update()
},
updateList(course) {
course = course || this.state.course
PAPI.fetchEtablissement(course.fili, course.sousfili, course.soussousfili).then((response) => {
response.forEach(etablissement => {
// calcul la moyenne
let pct_sansmention = etablissement.fields.pct_sansmention
let pct_AB = etablissement.fields.pct_ab
let pct_B = etablissement.fields.pct_b
let pct_TB = etablissement.fields.pct_tb
let pct_TBF = etablissement.fields.pct_tbf
// On prend la moyenne des moyennes comprises dans la mention
// Exemple : Assez bien est entre 12 et 14 donc 13.
etablissement.fields.moyenne = ((pct_TBF*19)+(pct_TB*17)+(pct_B*15)+(pct_AB*13)+(pct_sansmention*11))/100
})
this.update({
schoolList: response
2023-03-31 11:34:14 +02:00
})
this.filterSearch()
})
2023-03-29 22:01:50 +02:00
},
2023-03-30 00:54:13 +02:00
updateCourse(course){
this.updateList(course)
2023-03-29 22:01:50 +02:00
this.update({
2023-03-30 00:54:13 +02:00
course: course,
sortFields: SORT_TABLE,
2023-03-30 19:28:40 +02:00
shouldShowInfos: course != null,
})
},
onMounted(props, state) {
this.update({
course: null,
sortBy: null,
schoolList: null,
sortFields: SORT_TABLE,
2023-03-31 11:34:14 +02:00
filteredSchoolList: null,
shouldShowInfos: false
2023-03-29 22:01:50 +02:00
})
2023-03-31 11:34:14 +02:00
},
filterSearch() {
let input = this.$("input")
if (!input) return
let finalArray = []
//On évite de trier avant d'avoir plus de 1 lettres.
if (input.value.length > 1) {
finalArray = this.state.schoolList.filter((item) => {
return item.name.toLowerCase().includes(input.value.toLowerCase())
})
} else {
finalArray = this.state.schoolList
}
this.update({
filteredSchoolList: finalArray
})
2023-03-29 22:01:50 +02:00
}
2023-03-28 13:42:53 +02:00
}
</script>
</main-controller>