ProjetRIOT/components/main-controller.riot

92 lines
3.3 KiB
Plaintext

<main-controller>
<div class="columns">
<div class="column is-one-third">
<div class="box p-3 m-2" style="display: flex">
<img class="m-auto" src="./resources/logo-parcoursup.svg"/>
</div>
<search updateCourse={updateCourse}></search>
<button class="button is-danger ml-2 is-outlined" onclick={clearCache}>Vider le cache</button>
</div>
<div class="column pl-0">
<fili-info schoolList={state.schoolList} course={state.course} shouldShowInfos={state.shouldShowInfos}></fili-info>
<school popup={popup} schoolList={state.schoolList} schoolListUpdating={state.schoolListUpdating} course={state.course} shouldShowInfos={state.shouldShowInfos}></school>
</div>
</div>
<school-info closeWindow={closePopup} popupEnabled={state.popupEnabled} school={state.school}></school-info>
<script>
import PAPI from '../javascript/parcoursup-link.js'
export default {
updateCourse(course){
this.updateList(course)
this.update({
course: course,
shouldShowInfos: course != null
})
},
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({
schoolListUpdating: true,
schoolList: response
})
this.update({
schoolListUpdating: false
})
})
},
onMounted(props, state) {
this.update({
course: null,
schoolList: [],
shouldShowInfos: false
})
},
clearCache(e) {
localStorage.clear()
e.target.textContent = "Cache vidé !"
setTimeout(() => {
e.target.textContent = "Vider le cache"
}, 3000)
},
popup(school){
this.update({
school: school,
popupEnabled: true
})
console.log("popup!")
},
closePopup(){
this.update({
popupEnabled: false
})
console.log("closed!")
}
}
</script>
</main-controller>