Sort fonctionnel

This commit is contained in:
The17thDoctor 2023-03-30 19:28:40 +02:00
parent 0613632b24
commit 71e3c478dc
8 changed files with 236 additions and 149 deletions

View File

@ -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
})
}
}

View File

@ -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()
}
this.state.ascOrder=!this.state.ascOrder
this.update()
//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()
}
}
}

View File

@ -11,7 +11,7 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/riot/7.1.0/riot+compiler.min.js" integrity="sha512-sSGKGR9MvL0bUx3CScaBb56crXwspwDkL/JnB0IrLFQfw3uvSUlITQtsTtDZctshhv5wdwIt+qZeN8zThRF4Dw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
</head>
<body class="pr-4">
<body class="pr-4 pl-4">
<main-controller>
</main-controller>
</body>

View File

@ -11,54 +11,54 @@ var filiInfo = {
},
onUpdated(props, state) {}
},
template: (template, expressionTypes, bindingTypes, getComponent) => template('<div expr1500="expr1500" class="box p-1 m-2"></div>', [{
template: (template, expressionTypes, bindingTypes, getComponent) => template('<div expr0="expr0" class="box p-1 m-2"></div>', [{
type: bindingTypes.IF,
evaluate: _scope => _scope.props.shouldShowInfos,
redundantAttribute: 'expr1500',
selector: '[expr1500]',
template: template('<h1 class="title is-4 m-2"><span expr1501="expr1501" style="color: #485FC7;"> </span> / \r\n <span expr1502="expr1502" style="color: #485FC7;"> </span> / \r\n <span expr1503="expr1503" style="color: #485FC7;"> </span></h1><div class="box mt-2" style="background-color: #EAEAEA; margin: auto; width: 60%;"><p>Moyenne des admis<span expr1504="expr1504" class="is-pulled-right"> </span></p><p>Nombre de formations<span expr1505="expr1505" class="is-pulled-right"> </span></p><p>Capacité<span expr1506="expr1506" class="is-pulled-right"> </span></p><p>Sélectivité</p></div><div class="m-4"><line-graph expr1507="expr1507" title="Répartition par genre" style="height: 6rem;"></line-graph></div><div class="m-4"><line-graph expr1508="expr1508" title="Répartition par bac" style="height: 6rem;"></line-graph></div><div class="m-4"><line-graph expr1509="expr1509" title="Répartition par mention au bac" style="height: 6rem;"></line-graph></div>', [{
redundantAttribute: 'expr1501',
selector: '[expr1501]',
redundantAttribute: 'expr0',
selector: '[expr0]',
template: template('<h1 class="title is-4 m-2"><span expr1="expr1" style="color: #485FC7;"> </span> / \r\n <span expr2="expr2" style="color: #485FC7;"> </span> / \r\n <span expr3="expr3" style="color: #485FC7;"> </span></h1><div class="box mt-2" style="background-color: #EAEAEA; margin: auto; width: 60%;"><p>Moyenne des admis<span expr4="expr4" class="is-pulled-right"> </span></p><p>Nombre de formations<span expr5="expr5" class="is-pulled-right"> </span></p><p>Capacité<span expr6="expr6" class="is-pulled-right"> </span></p><p>Sélectivité</p></div><div class="m-4"><line-graph expr7="expr7" title="Répartition par genre" style="height: 6rem;"></line-graph></div><div class="m-4"><line-graph expr8="expr8" title="Répartition par bac" style="height: 6rem;"></line-graph></div><div class="m-4"><line-graph expr9="expr9" title="Répartition par mention au bac" style="height: 6rem;"></line-graph></div>', [{
redundantAttribute: 'expr1',
selector: '[expr1]',
expressions: [{
type: expressionTypes.TEXT,
childNodeIndex: 0,
evaluate: _scope => _scope.props.course.fili
}]
}, {
redundantAttribute: 'expr1502',
selector: '[expr1502]',
redundantAttribute: 'expr2',
selector: '[expr2]',
expressions: [{
type: expressionTypes.TEXT,
childNodeIndex: 0,
evaluate: _scope => _scope.props.course.sousfili
}]
}, {
redundantAttribute: 'expr1503',
selector: '[expr1503]',
redundantAttribute: 'expr3',
selector: '[expr3]',
expressions: [{
type: expressionTypes.TEXT,
childNodeIndex: 0,
evaluate: _scope => _scope.props.course.soussousfili
}]
}, {
redundantAttribute: 'expr1504',
selector: '[expr1504]',
redundantAttribute: 'expr4',
selector: '[expr4]',
expressions: [{
type: expressionTypes.TEXT,
childNodeIndex: 0,
evaluate: _scope => _scope.state.average
}]
}, {
redundantAttribute: 'expr1505',
selector: '[expr1505]',
redundantAttribute: 'expr5',
selector: '[expr5]',
expressions: [{
type: expressionTypes.TEXT,
childNodeIndex: 0,
evaluate: _scope => _scope.state.courseNumber
}]
}, {
redundantAttribute: 'expr1506',
selector: '[expr1506]',
redundantAttribute: 'expr6',
selector: '[expr6]',
expressions: [{
type: expressionTypes.TEXT,
childNodeIndex: 0,
@ -70,24 +70,24 @@ var filiInfo = {
evaluate: _scope => 'line-graph',
slots: [],
attributes: [],
redundantAttribute: 'expr1507',
selector: '[expr1507]'
redundantAttribute: 'expr7',
selector: '[expr7]'
}, {
type: bindingTypes.TAG,
getComponent: getComponent,
evaluate: _scope => 'line-graph',
slots: [],
attributes: [],
redundantAttribute: 'expr1508',
selector: '[expr1508]'
redundantAttribute: 'expr8',
selector: '[expr8]'
}, {
type: bindingTypes.TAG,
getComponent: getComponent,
evaluate: _scope => 'line-graph',
slots: [],
attributes: [],
redundantAttribute: 'expr1509',
selector: '[expr1509]'
redundantAttribute: 'expr9',
selector: '[expr9]'
}])
}]),
name: 'fili-info'

View File

@ -5,17 +5,19 @@ var mainController = {
//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
});
}
},
template: (template, expressionTypes, bindingTypes, getComponent) => template('<div class="columns"><div class="column is-one-third"><div class="box p-3 m-2"><img class="mt-1 ml-5 mr-auto" style="margin: auto;" src="../resources/logo-parcoursup.svg"/></div><search expr1334="expr1334"></search></div><div class="column"><fili-info expr1335="expr1335"></fili-info><school expr1336="expr1336"></school></div></div><school-info expr1337="expr1337"></school-info>', [{
template: (template, expressionTypes, bindingTypes, getComponent) => template('<div class="columns"><div class="column is-one-third"><div class="box p-3 m-2"><img class="mt-1 ml-5 mr-auto" style="margin: auto;" src="../resources/logo-parcoursup.svg"/></div><search expr125="expr125"></search></div><div class="column"><fili-info expr126="expr126"></fili-info><school expr127="expr127"></school></div></div><school-info expr128="expr128"></school-info>', [{
type: bindingTypes.TAG,
getComponent: getComponent,
evaluate: _scope => 'search',
@ -25,8 +27,8 @@ var mainController = {
name: 'updateCourse',
evaluate: _scope => _scope.updateCourse
}],
redundantAttribute: 'expr1334',
selector: '[expr1334]'
redundantAttribute: 'expr125',
selector: '[expr125]'
}, {
type: bindingTypes.TAG,
getComponent: getComponent,
@ -41,14 +43,18 @@ var mainController = {
name: 'shouldShowInfos',
evaluate: _scope => _scope.state.shouldShowInfos
}],
redundantAttribute: 'expr1335',
selector: '[expr1335]'
redundantAttribute: 'expr126',
selector: '[expr126]'
}, {
type: bindingTypes.TAG,
getComponent: getComponent,
evaluate: _scope => 'school',
slots: [],
attributes: [{
type: expressionTypes.ATTRIBUTE,
name: 'parentUpdate',
evaluate: _scope => _scope.state.updating
}, {
type: expressionTypes.ATTRIBUTE,
name: 'course',
evaluate: _scope => _scope.state.course
@ -57,16 +63,16 @@ var mainController = {
name: 'shouldShowInfos',
evaluate: _scope => _scope.state.shouldShowInfos
}],
redundantAttribute: 'expr1336',
selector: '[expr1336]'
redundantAttribute: 'expr127',
selector: '[expr127]'
}, {
type: bindingTypes.TAG,
getComponent: getComponent,
evaluate: _scope => 'school-info',
slots: [],
attributes: [],
redundantAttribute: 'expr1337',
selector: '[expr1337]'
redundantAttribute: 'expr128',
selector: '[expr128]'
}]),
name: 'main-controller'
};

View File

@ -10,14 +10,14 @@ var schoolInfo = {
this.update();
}
},
template: (template, expressionTypes, bindingTypes, getComponent) => template('<div expr9="expr9" style="position: absolute; top: 0px; left: 0px; width: 100%; height: 100%; background: #000000DD;"></div>', [{
template: (template, expressionTypes, bindingTypes, getComponent) => template('<div expr10="expr10" style="position: absolute; top: 0px; left: 0px; width: 100%; height: 100%; background: #000000DD;"></div>', [{
type: bindingTypes.IF,
evaluate: _scope => _scope.state.enabled,
redundantAttribute: 'expr9',
selector: '[expr9]',
template: template('<div style="position: absolute; top: 10%; left: 10%; width: 80%; height: 80%; background: #FFFFFF"><button expr10="expr10" class="delete is-medium">X</button><p><h2></h2></p><line-graph expr11="expr11" style="height: 90px; margin: 10px;"></line-graph></div>', [{
redundantAttribute: 'expr10',
selector: '[expr10]',
redundantAttribute: 'expr10',
selector: '[expr10]',
template: template('<div style="position: absolute; top: 10%; left: 10%; width: 80%; height: 80%; background: #FFFFFF"><button expr11="expr11" class="delete is-medium">X</button><p><h2></h2></p><line-graph expr12="expr12" style="height: 90px; margin: 10px;"></line-graph></div>', [{
redundantAttribute: 'expr11',
selector: '[expr11]',
expressions: [{
type: expressionTypes.EVENT,
name: 'onclick',
@ -29,8 +29,8 @@ var schoolInfo = {
evaluate: _scope => 'line-graph',
slots: [],
attributes: [],
redundantAttribute: 'expr11',
selector: '[expr11]'
redundantAttribute: 'expr12',
selector: '[expr12]'
}])
}]),
name: 'school-info'

File diff suppressed because one or more lines are too long

View File

@ -144,9 +144,9 @@ var search = {
this.updateList();
}
},
template: (template, expressionTypes, bindingTypes, getComponent) => template('<div class="box p-1 m-2"><div class="columns m-1"><input expr626="expr626" class="input" type="input"/><button expr627="expr627" class="button ml-1">&lt;</button></div><div id="list-formations"><ul><li expr628="expr628" class="m-1"></li></ul></div></div>', [{
redundantAttribute: 'expr626',
selector: '[expr626]',
template: (template, expressionTypes, bindingTypes, getComponent) => template('<div class="box p-1 m-2"><div class="columns m-1"><input expr27="expr27" class="input" type="input"/><button expr28="expr28" class="button ml-1">&lt;</button></div><div id="list-formations"><ul><li expr29="expr29" class="m-1"></li></ul></div></div>', [{
redundantAttribute: 'expr27',
selector: '[expr27]',
expressions: [{
type: expressionTypes.EVENT,
name: 'onkeyup',
@ -157,8 +157,8 @@ var search = {
evaluate: _scope => _scope.state.placeholder
}]
}, {
redundantAttribute: 'expr627',
selector: '[expr627]',
redundantAttribute: 'expr28',
selector: '[expr28]',
expressions: [{
type: expressionTypes.ATTRIBUTE,
name: 'disabled',
@ -172,9 +172,9 @@ var search = {
type: bindingTypes.EACH,
getKey: null,
condition: null,
template: template('<button expr629="expr629" class="button is-fullwidth p-2"><span style="font-size: .75em; max-size: 90%"><strong expr630="expr630"> </strong></span><div style="margin-left: auto;"></div><span expr631="expr631" class="tag is-primary"> </span></button>', [{
redundantAttribute: 'expr629',
selector: '[expr629]',
template: template('<button expr30="expr30" class="button is-fullwidth p-2"><span style="font-size: .75em; max-size: 90%"><strong expr31="expr31"> </strong></span><div style="margin-left: auto;"></div><span expr32="expr32" class="tag is-primary"> </span></button>', [{
redundantAttribute: 'expr30',
selector: '[expr30]',
expressions: [{
type: expressionTypes.ATTRIBUTE,
name: 'disabled',
@ -185,24 +185,24 @@ var search = {
evaluate: _scope => () => _scope.cruiseForward(_scope.item.name)
}]
}, {
redundantAttribute: 'expr630',
selector: '[expr630]',
redundantAttribute: 'expr31',
selector: '[expr31]',
expressions: [{
type: expressionTypes.TEXT,
childNodeIndex: 0,
evaluate: _scope => _scope.item.name
}]
}, {
redundantAttribute: 'expr631',
selector: '[expr631]',
redundantAttribute: 'expr32',
selector: '[expr32]',
expressions: [{
type: expressionTypes.TEXT,
childNodeIndex: 0,
evaluate: _scope => _scope.item.count
}]
}]),
redundantAttribute: 'expr628',
selector: '[expr628]',
redundantAttribute: 'expr29',
selector: '[expr29]',
itemName: 'item',
indexName: null,
evaluate: _scope => _scope.state.items