ProjetRIOT/components/school.riot

127 lines
5.2 KiB
Plaintext
Raw Normal View History

2023-03-28 10:15:32 +02:00
<school>
2023-03-30 00:54:13 +02:00
<div if={props.shouldShowInfos} class="box p-2 m-2">
2023-03-29 22:56:14 +02:00
<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>
2023-03-29 16:50:48 +02:00
<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>
2023-03-28 10:15:32 +02:00
<table class="table is-fullwidth is-hoverable">
<thead>
<tr>
2023-03-30 19:28:40 +02:00
<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>
2023-03-28 10:15:32 +02:00
</tr>
</thead>
2023-03-28 16:51:44 +02:00
<tbody>
2023-03-30 16:00:54 +02:00
<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>
2023-03-28 21:30:56 +02:00
<td>{etablissement.fields.moyenne}</td>
<td>{etablissement.fields.taux_acces_ens}</td>
2023-03-28 16:51:44 +02:00
</tr>
</tbody>
</table>
2023-03-29 16:50:48 +02:00
</div>
2023-03-28 16:51:44 +02:00
2023-03-28 10:15:32 +02:00
<script>
2023-03-28 16:51:44 +02:00
import PAPI from '../javascript/parcoursup-link.js'
2023-03-30 00:54:13 +02:00
async function fetchEtablissement(course) {
return PAPI.fetchEtablissement(course.fili, course.sousfili, course.soussousfili);
2023-03-28 16:51:44 +02:00
}
2023-03-30 19:28:40 +02:00
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() {
2023-03-28 16:51:44 +02:00
return {
2023-03-30 19:28:40 +02:00
updateList() {
fetchEtablissement(this.props.course).then((response) => {
2023-03-30 00:54:13 +02:00
response.forEach(etablissement => {
2023-03-28 16:54:41 +02:00
// 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
2023-03-29 16:50:48 +02:00
// On prend la moyenne des moyennes comprises dans la mention
// Exemple : Assez bien est entre 12 et 14 donc 13.
2023-03-30 00:54:13 +02:00
etablissement.fields.moyenne = ((pct_TBF*19)+(pct_TB*17)+(pct_B*15)+(pct_AB*13)+(pct_sansmention*11))/100
})
this.update({
2023-03-30 19:28:40 +02:00
items: response,
parentUpdate: this.props.parentUpdate
2023-03-28 16:54:41 +02:00
})
2023-03-28 16:51:44 +02:00
})
2023-03-30 17:26:23 +02:00
},
2023-03-30 19:28:40 +02:00
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
2023-03-30 17:26:23 +02:00
}
2023-03-30 19:28:40 +02:00
},
onMounted(props, state) {
this.update({
sortFields: SORT_TABLE
})
},
onUpdated(props, state) {
if (!props.shouldShowInfos || state.parentUpdate == props.parentUpdate) return
this.updateList()
2023-03-28 16:51:44 +02:00
}
2023-03-28 10:15:32 +02:00
}
}
</script>
</school>