Sort fonctionnel
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
|
||||
<div class="column">
|
||||
<fili-info course={state.course} shouldShowInfos={state.shouldShowInfos}></fili-info>
|
||||
<school course={state.course} shouldShowInfos={state.shouldShowInfos}></school>
|
||||
<school parentUpdate={state.updating} course={state.course} shouldShowInfos={state.shouldShowInfos}></school>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -21,13 +21,15 @@
|
||||
//Initial state
|
||||
this.state = {
|
||||
course: null,
|
||||
updating: false,
|
||||
shouldShowInfos: false
|
||||
}
|
||||
},
|
||||
updateCourse(course){
|
||||
this.update({
|
||||
course: course,
|
||||
shouldShowInfos: course != null
|
||||
shouldShowInfos: course != null,
|
||||
updating: !this.state.updating
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@@ -13,11 +13,12 @@
|
||||
<table class="table is-fullwidth is-hoverable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><abbr title="name">Nom</abbr></th><a id="g_ea_lib_vx" onclick={sort}><span class="icon"><i class="fas fa-sort"></i></span></a>
|
||||
<th><abbr title="city">Ville</abbr></th><a id="ville_etab" onclick={sort}><span class="icon"><i class="fas fa-sort"></i></span></a>
|
||||
<th><abbr title="dept">Dpt</abbr></th><a id="dep" onclick={sort}><span class="icon"><i class="fas fa-sort"></i></span></a>
|
||||
<th><abbr title="moyenne">Moyenne</abbr></th><a id="moyenne" onclick={sort}><span class="icon"><i class="fas fa-sort"></i></span></a>
|
||||
<th><abbr title="selectivite">Sélectivité</abbr></th><a id="taux_acces_ens" onclick={sort}><span class="icon"><i class="fas fa-sort"></i></span></a>
|
||||
<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>
|
||||
@@ -39,18 +40,18 @@
|
||||
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 {
|
||||
onBeforeMount(props, state) {
|
||||
state = {
|
||||
items: null,
|
||||
breakCycle: false,
|
||||
ascOrder: true
|
||||
}
|
||||
},
|
||||
onUpdated(props, state) {
|
||||
if (!props.shouldShowInfos || state.breakCycle) return
|
||||
fetchEtablissement(props.course).then((response) => {
|
||||
updateList() {
|
||||
fetchEtablissement(this.props.course).then((response) => {
|
||||
response.forEach(etablissement => {
|
||||
// calcul la moyenne
|
||||
let pct_sansmention = etablissement.fields.pct_sansmention
|
||||
@@ -64,23 +65,61 @@
|
||||
etablissement.fields.moyenne = ((pct_TBF*19)+(pct_TB*17)+(pct_B*15)+(pct_AB*13)+(pct_sansmention*11))/100
|
||||
})
|
||||
|
||||
state.breakCycle = true
|
||||
this.update({
|
||||
items: response
|
||||
items: response,
|
||||
parentUpdate: this.props.parentUpdate
|
||||
})
|
||||
state.breakCycle = false
|
||||
})
|
||||
},
|
||||
sort(e){
|
||||
console.log("sort")
|
||||
console.log(e.target)
|
||||
if (this.state.ascOrder){
|
||||
this.state.items.sort((etablissement1, etablissement2)=>etablissement2.fields[order]-etablissement1.fields[order]))
|
||||
} else {
|
||||
this.state.items.sort((etablissement1, etablissement2)=>etablissement1.fields[order]-etablissement2.fields[order]))
|
||||
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.state.ascOrder=!this.state.ascOrder
|
||||
this.update()
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user