ProjetRIOT/components/school.riot
2023-03-30 19:28:40 +02:00

127 lines
5.2 KiB
Plaintext

<school>
<div if={props.shouldShowInfos} class="box p-2 m-2">
<iframe width="100%" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"
src="https://www.openstreetmap.org/export/embed.html?bbox=-14.655761718750002%2C40.56389453066509%2C13.601074218750002%2C51.754240074033525&amp;layer=mapnik"
style="border-radius: 5px;"></iframe>
<br>
<div class="block control has-icons-left is-inline-block is-pulled-right">
<input class="input" type="search" placeholder="Établissement">
<span class="icon is-small is-left">
<i class="fas fa-search"></i>
</span>
</div>
<table class="table is-fullwidth is-hoverable">
<thead>
<tr>
<th each={sortField in state.sortFields}>
{sortField.name}
<a id={sortField.id} onclick={() => sortList(sortField.id)}>
<span class="icon"><i class="fas fa-sort"></i></span>
</a>
</th>
</tr>
</thead>
<tbody>
<tr each={etablissement in state.items}>
<td>{etablissement.fields.g_ea_lib_vx}</td>
<td>{etablissement.fields.ville_etab}</td>
<td>{etablissement.fields.dep}</td>
<td>{etablissement.fields.moyenne}</td>
<td>{etablissement.fields.taux_acces_ens}</td>
</tr>
</tbody>
</table>
</div>
<script>
import PAPI from '../javascript/parcoursup-link.js'
async function fetchEtablissement(course) {
return PAPI.fetchEtablissement(course.fili, course.sousfili, course.soussousfili);
}
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 function search() {
return {
updateList() {
fetchEtablissement(this.props.course).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({
items: response,
parentUpdate: this.props.parentUpdate
})
})
},
sortList(sortBy) {
//Si la liste est déjà triée par la bonne catégorie, on l'inverse
if (sortBy == this.state.sortBy) {
this.state.items.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: {
this.state.items.sort((a, b) => {
if (a.fields[sortBy] > b.fields[sortBy]) return 1
else return -1
})
break
}
default: {
this.state.items.sort((a, b) => {
return (a.fields[sortBy]).localeCompare(b.fields[sortBy])
})
break
}
}
}
this.update({
items: this.state.items
})
},
onBeforeMount(props, state) {
state = {
items: null,
breakCycle: false,
sortBy: null,
parentUpdate: null,
sortFields: null
}
},
onMounted(props, state) {
this.update({
sortFields: SORT_TABLE
})
},
onUpdated(props, state) {
if (!props.shouldShowInfos || state.parentUpdate == props.parentUpdate) return
this.updateList()
}
}
}
</script>
</school>