ProjetRIOT/components/main-controller.riot

94 lines
3.3 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-31 11:36:19 +02:00
<div class="box p-3 m-2" style="display: flex">
2023-03-31 11:37:06 +02:00
<img class="m-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-31 17:07:25 +02:00
<button class="button is-danger ml-2 is-outlined" onclick={clearCache}>Vider le cache</button>
2023-03-28 13:42:53 +02:00
</div>
2023-03-31 17:07:25 +02:00
<div class="column pl-0">
<fili-info schoolList={state.schoolList} course={state.course} shouldShowInfos={state.shouldShowInfos}></fili-info>
2023-03-31 14:55:49 +02:00
<school popup={popup} schoolList={state.schoolList} schoolListUpdating={state.schoolListUpdating} course={state.course} shouldShowInfos={state.shouldShowInfos}></school>
2023-03-28 13:42:53 +02:00
</div>
</div>
2023-03-31 14:54:13 +02:00
<school-info closeWindow={closePopup} popupEnabled={state.popupEnabled} school={state.school}></school-info>
2023-03-28 13:42:53 +02:00
<script>
import PAPI from '../javascript/parcoursup-link.js'
export default {
2023-03-31 14:22:25 +02:00
updateCourse(course){
this.updateList(course)
2023-03-31 14:22:25 +02:00
this.update({
course: course,
2023-03-31 17:07:25 +02:00
shouldShowInfos: course != null
2023-03-31 14:22:25 +02:00
})
},
2023-03-31 14:22:25 +02:00
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
2023-03-31 14:22:25 +02:00
})
this.update({
2023-03-31 14:22:25 +02:00
schoolListUpdating: true,
schoolList: response
2023-03-31 14:22:25 +02:00
})
2023-03-31 14:22:25 +02:00
this.update({
schoolListUpdating: false
})
})
},
onMounted(props, state) {
this.update({
course: null,
2023-03-31 17:07:25 +02:00
schoolList: [],
2023-03-31 14:54:13 +02:00
school: null,
2023-03-31 17:20:19 +02:00
popupEnabled: false,
shouldShowInfos: false
2023-03-31 11:34:14 +02:00
})
2023-03-31 14:54:13 +02:00
},
2023-03-31 11:34:14 +02:00
2023-03-31 17:07:25 +02:00
clearCache(e) {
localStorage.clear()
e.target.textContent = "Cache vidé !"
2023-03-31 11:34:14 +02:00
2023-03-31 17:07:25 +02:00
setTimeout(() => {
e.target.textContent = "Vider le cache"
}, 3000)
2023-03-31 14:54:13 +02:00
},
popup(school){
this.update({
school: school,
popupEnabled: true
})
console.log("popup!")
},
closePopup(){
this.update({
popupEnabled: false
})
console.log("closed!")
2023-03-29 22:01:50 +02:00
}
2023-03-28 13:42:53 +02:00
}
</script>
</main-controller>