search.riot refactor (presque terminé)

This commit is contained in:
HORVILLE 2023-03-29 17:42:04 +02:00
parent ea62bb9d3f
commit 59e30c88ba
7 changed files with 232 additions and 97 deletions

View File

@ -34,14 +34,13 @@
</div>
<script>
import PAPI from '../javascript/parcoursup-link.js'
async function fetchEtablissement(state) {
return PAPI.fetchEtablissement(state.fili, state.sousfili, state.soussousfili);
}
export default function search(){
export default function search() {
return {
onBeforeMount(props, state) {
this.state = {
@ -65,7 +64,7 @@
// On prend la moyenne des moyennes comprises dans la mention
// Exemple : Assez bien est entre 12 et 14 donc 13.
let moyenne = ((pct_TBF*19)+(pct_TB*17)+(pct_B*15)+(pct_AB*13)+(pct_sansmention*11g))/100
let moyenne = ((pct_TBF*19)+(pct_TB*17)+(pct_B*15)+(pct_AB*13)+(pct_sansmention*11))/100
etablissement.fields.moyenne=moyenne
//console.log(etablissement.fields)
@ -76,6 +75,4 @@
}
}
</script>
</school>

View File

@ -1,13 +1,13 @@
<search>
<div class="box p-1 m-2">
<div class="columns m-1">
<input onkeydown={filterSearch} onfocusout={filterSearch} class="input" type="input" placeholder={state.placeholder}>
<button class="button ml-1" disabled={!state.currentStep} onclick={cruiseBack}>&lt;</button>
<input onkeyup={filterSearch} class="input" type="input" placeholder={state.placeholder}>
<button class="button ml-1" disabled={!state.currentStep || state.updating} onclick={cruiseBack}>&lt;</button>
</div>
<div id="list-formations">
<ul>
<li class="m-1" each={item in this.state.items}>
<button class="button is-fullwidth" onclick={()=>cruiseForward(item.name)}>
<button class="button is-fullwidth" disabled={state.updating} onclick={()=>cruiseForward(item.name)}>
<span style="font-size: .75em;"><strong>{item.name}</strong></span>
<div style="margin-left: auto;"></div>
<span class="tag is-primary">{item.count}</span>
@ -19,36 +19,108 @@
<script>
import PAPI from '../javascript/parcoursup-link.js'
function cruiseBack() {
}
function cruiseForward() {
}
function filterSearch() {
}
const PLACEHOLDERS = [
"Formation",
"Filière",
"Spécialité"
]
export default {
updateList() {
let promise
this.update({
updating: true
})
switch (this.state.currentStep) {
case 0:
promise = PAPI.fetchFilieres()
break
case 1:
promise = PAPI.fetchFiliere(this.state.filiere)
break
case 2:
promise = PAPI.fetchSpecialites(this.state.specialite)
break
}
promise.then((response) => {
this.state.allItems = response
this.filterSearch()
this.update({
updating: false
})
})
},
filterSearch() {
let input = this.$("input")
if (!input) return
let finalArray = []
//On évite de trier avant d'avoir plus de 1 lettres.
if (input.value.length > 1) {
finalArray = this.state.allItems.filter((item) => {
return item.name.toLowerCase().includes(input.value.toLowerCase())
})
} else {
finalArray = this.state.allItems
}
this.update({
items: finalArray
})
},
cruiseForward(selection) {
if (this.state.currentStep >= 2) return
switch (this.state.currentStep) {
case 0:
this.state.filiere = selection
break
case 1:
this.state.specialite = selection
break
}
this.state.currentStep++
this.updateList()
this.update({
placeholder: PLACEHOLDERS[this.state.currentStep]
})
},
cruiseBack() {
if (!this.state.currentStep) return
this.state.currentStep--
this.updateList()
this.update({
placeholder: PLACEHOLDERS[this.state.currentStep]
})
},
onBeforeMount(props, state) {
//Initial state
this.state = {
placeholder: "Formation",
placeholder: PLACEHOLDERS[0],
currentStep: 0,
allItems: null,
filter: null,
items: null
items: null,
filiere: null,
specialite: null,
updating: false
}
},
PAPI.fetchFilieres().then((response) => {
this.state.allItems = response
this.update({
items: filterSearch(this.state.allItems)
})
})
onMounted() {
this.updateList()
}
}

View File

@ -1,30 +1,30 @@
var filiInfo = {
css: null,
exports: null,
template: (template, expressionTypes, bindingTypes, getComponent) => template('<div class="box p-1 m-2"><h1 class="title is-4 m-2"><a>BUT</a> / <a>BUT - Production</a> / <a>Informatique</a></h1><div class="box mt-2" style="background-color: #EAEAEA; margin: auto; width: 60%;"><p>Moyenne des admis<span class="is-pulled-right">19.3</span></p><p>Nombre de formations<span class="is-pulled-right">5</span></p><p>Capacité<span class="is-pulled-right">90</span></p><p>Sélectivité</p></div><div class="m-4"><line-graph expr4="expr4" style="height: 6rem;"></line-graph></div><div class="m-4"><line-graph expr5="expr5" style="height: 6rem;"></line-graph></div><div class="m-4"><line-graph expr6="expr6" style="height: 6rem;"></line-graph></div></div>', [{
template: (template, expressionTypes, bindingTypes, getComponent) => template('<div class="box p-1 m-2"><h1 class="title is-4 m-2"><a>BUT</a> / <a>BUT - Production</a> / <a>Informatique</a></h1><div class="box mt-2" style="background-color: #EAEAEA; margin: auto; width: 60%;"><p>Moyenne des admis<span class="is-pulled-right">19.3</span></p><p>Nombre de formations<span class="is-pulled-right">5</span></p><p>Capacité<span class="is-pulled-right">90</span></p><p>Sélectivité</p></div><div class="m-4"><line-graph expr0="expr0" style="height: 6rem;"></line-graph></div><div class="m-4"><line-graph expr1="expr1" style="height: 6rem;"></line-graph></div><div class="m-4"><line-graph expr2="expr2" style="height: 6rem;"></line-graph></div></div>', [{
type: bindingTypes.TAG,
getComponent: getComponent,
evaluate: _scope => 'line-graph',
slots: [],
attributes: [],
redundantAttribute: 'expr4',
selector: '[expr4]'
redundantAttribute: 'expr0',
selector: '[expr0]'
}, {
type: bindingTypes.TAG,
getComponent: getComponent,
evaluate: _scope => 'line-graph',
slots: [],
attributes: [],
redundantAttribute: 'expr5',
selector: '[expr5]'
redundantAttribute: 'expr1',
selector: '[expr1]'
}, {
type: bindingTypes.TAG,
getComponent: getComponent,
evaluate: _scope => 'line-graph',
slots: [],
attributes: [],
redundantAttribute: 'expr6',
selector: '[expr6]'
redundantAttribute: 'expr2',
selector: '[expr2]'
}]),
name: 'fili-info'
};

View File

@ -1,38 +1,38 @@
var mainController = {
css: null,
exports: {},
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 expr0="expr0"></search></div><div class="column"><fili-info expr1="expr1"></fili-info><school expr2="expr2"></school></div></div><school-info expr3="expr3"></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 expr12="expr12"></search></div><div class="column"><fili-info expr13="expr13"></fili-info><school expr14="expr14"></school></div></div><school-info expr15="expr15"></school-info>', [{
type: bindingTypes.TAG,
getComponent: getComponent,
evaluate: _scope => 'search',
slots: [],
attributes: [],
redundantAttribute: 'expr0',
selector: '[expr0]'
redundantAttribute: 'expr12',
selector: '[expr12]'
}, {
type: bindingTypes.TAG,
getComponent: getComponent,
evaluate: _scope => 'fili-info',
slots: [],
attributes: [],
redundantAttribute: 'expr1',
selector: '[expr1]'
redundantAttribute: 'expr13',
selector: '[expr13]'
}, {
type: bindingTypes.TAG,
getComponent: getComponent,
evaluate: _scope => 'school',
slots: [],
attributes: [],
redundantAttribute: 'expr2',
selector: '[expr2]'
redundantAttribute: 'expr14',
selector: '[expr14]'
}, {
type: bindingTypes.TAG,
getComponent: getComponent,
evaluate: _scope => 'school-info',
slots: [],
attributes: [],
redundantAttribute: 'expr3',
selector: '[expr3]'
redundantAttribute: 'expr15',
selector: '[expr15]'
}]),
name: 'main-controller'
};

View File

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

View File

@ -47,7 +47,7 @@ var school = {
this.update({
items: response
});
console.log(this.state.items);
//console.log(this.state.items)
this.state.items.forEach(etablissement => {
// calcul la moyenne
let pct_sansmention = etablissement.fields.pct_sansmention;
@ -60,60 +60,61 @@ var school = {
// Exemple : Assez bien est entre 12 et 14 donc 13.
let moyenne = (pct_TBF * 19 + pct_TB * 17 + pct_B * 15 + pct_AB * 13 + pct_sansmention * 11) / 100;
etablissement.fields.moyenne = moyenne;
console.log(etablissement.fields);
//console.log(etablissement.fields)
});
this.update();
});
}
};
},
template: (template, expressionTypes, bindingTypes, getComponent) => template('<div 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><abbr title="name">Nom</abbr></th><th><abbr title="city">Ville</abbr></th><th><abbr title="dept">Dpt</abbr></th><th><abbr title="moyenne">Moyenne</abbr></th><th><abbr title="selectivite">Sélectivité</abbr></th></tr></thead><tbody><tr expr34="expr34"></tr></tbody></table></div>', [{
template: (template, expressionTypes, bindingTypes, getComponent) => template('<div 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><abbr title="name">Nom</abbr></th><th><abbr title="city">Ville</abbr></th><th><abbr title="dept">Dpt</abbr></th><th><abbr title="moyenne">Moyenne</abbr></th><th><abbr title="selectivite">Sélectivité</abbr></th></tr></thead><tbody><tr expr16="expr16"></tr></tbody></table></div>', [{
type: bindingTypes.EACH,
getKey: null,
condition: null,
template: template('<td expr35="expr35"> </td><td expr36="expr36"> </td><td expr37="expr37"> </td><td expr38="expr38"> </td><td expr39="expr39"> </td>', [{
redundantAttribute: 'expr35',
selector: '[expr35]',
template: template('<td expr17="expr17"> </td><td expr18="expr18"> </td><td expr19="expr19"> </td><td expr20="expr20"> </td><td expr21="expr21"> </td>', [{
redundantAttribute: 'expr17',
selector: '[expr17]',
expressions: [{
type: expressionTypes.TEXT,
childNodeIndex: 0,
evaluate: _scope => _scope.etablissement.fields.g_ea_lib_vx
}]
}, {
redundantAttribute: 'expr36',
selector: '[expr36]',
redundantAttribute: 'expr18',
selector: '[expr18]',
expressions: [{
type: expressionTypes.TEXT,
childNodeIndex: 0,
evaluate: _scope => _scope.etablissement.fields.ville_etab
}]
}, {
redundantAttribute: 'expr37',
selector: '[expr37]',
redundantAttribute: 'expr19',
selector: '[expr19]',
expressions: [{
type: expressionTypes.TEXT,
childNodeIndex: 0,
evaluate: _scope => _scope.etablissement.fields.dep
}]
}, {
redundantAttribute: 'expr38',
selector: '[expr38]',
redundantAttribute: 'expr20',
selector: '[expr20]',
expressions: [{
type: expressionTypes.TEXT,
childNodeIndex: 0,
evaluate: _scope => _scope.etablissement.fields.moyenne
}]
}, {
redundantAttribute: 'expr39',
selector: '[expr39]',
redundantAttribute: 'expr21',
selector: '[expr21]',
expressions: [{
type: expressionTypes.TEXT,
childNodeIndex: 0,
evaluate: _scope => _scope.etablissement.fields.taux_acces_ens
}]
}]),
redundantAttribute: 'expr34',
selector: '[expr34]',
redundantAttribute: 'expr16',
selector: '[expr16]',
itemName: 'etablissement',
indexName: null,
evaluate: _scope => _scope.state.items

View File

@ -29,37 +29,98 @@ class PAPI {
}
}
function filterSearch() {}
const PLACEHOLDERS = ["Formation", "Filière", "Spécialité"];
var search = {
css: null,
exports: {
updateList() {
let promise;
this.update({
updating: true
});
switch (this.state.currentStep) {
case 0:
promise = PAPI.fetchFilieres();
break;
case 1:
promise = PAPI.fetchFiliere(this.state.filiere);
break;
case 2:
promise = PAPI.fetchSpecialites(this.state.specialite);
break;
}
promise.then(response => {
this.state.allItems = response;
this.filterSearch();
this.update({
updating: false
});
});
},
filterSearch() {
let input = this.$("input");
if (!input) return;
let finalArray = [];
//On évite de trier avant d'avoir plus de 1 lettres.
if (input.value.length > 1) {
finalArray = this.state.allItems.filter(item => {
return item.name.toLowerCase().includes(input.value.toLowerCase());
});
} else {
finalArray = this.state.allItems;
}
this.update({
items: finalArray
});
},
cruiseForward(selection) {
if (this.state.currentStep >= 2) return;
switch (this.state.currentStep) {
case 0:
this.state.filiere = selection;
break;
case 1:
this.state.specialite = selection;
break;
}
this.state.currentStep++;
this.updateList();
this.update({
placeholder: PLACEHOLDERS[this.state.currentStep]
});
},
cruiseBack() {
if (!this.state.currentStep) return;
this.state.currentStep--;
this.updateList();
this.update({
placeholder: PLACEHOLDERS[this.state.currentStep]
});
},
onBeforeMount(props, state) {
//Initial state
this.state = {
placeholder: "Formation",
placeholder: PLACEHOLDERS[0],
currentStep: 0,
allItems: null,
filter: null,
items: null
items: null,
filiere: null,
specialite: null,
updating: false
};
PAPI.fetchFilieres().then(response => {
this.state.allItems = response;
this.update({
items: filterSearch(this.state.allItems)
});
});
},
onMounted() {
this.updateList();
}
},
template: (template, expressionTypes, bindingTypes, getComponent) => template('<div class="box p-1 m-2"><div class="columns m-1"><input expr10="expr10" class="input" type="input"/><button expr11="expr11" class="button ml-1">&lt;</button></div><div id="list-formations"><ul><li expr12="expr12" class="m-1"></li></ul></div></div>', [{
redundantAttribute: 'expr10',
selector: '[expr10]',
template: (template, expressionTypes, bindingTypes, getComponent) => template('<div class="box p-1 m-2"><div class="columns m-1"><input expr304="expr304" class="input" type="input"/><button expr305="expr305" class="button ml-1">&lt;</button></div><div id="list-formations"><ul><li expr306="expr306" class="m-1"></li></ul></div></div>', [{
redundantAttribute: 'expr304',
selector: '[expr304]',
expressions: [{
type: expressionTypes.EVENT,
name: 'onkeydown',
evaluate: _scope => _scope.filterSearch
}, {
type: expressionTypes.EVENT,
name: 'onfocusout',
name: 'onkeyup',
evaluate: _scope => _scope.filterSearch
}, {
type: expressionTypes.ATTRIBUTE,
@ -67,12 +128,12 @@ var search = {
evaluate: _scope => _scope.state.placeholder
}]
}, {
redundantAttribute: 'expr11',
selector: '[expr11]',
redundantAttribute: 'expr305',
selector: '[expr305]',
expressions: [{
type: expressionTypes.ATTRIBUTE,
name: 'disabled',
evaluate: _scope => !_scope.state.currentStep
evaluate: _scope => !_scope.state.currentStep || _scope.state.updating
}, {
type: expressionTypes.EVENT,
name: 'onclick',
@ -82,33 +143,37 @@ var search = {
type: bindingTypes.EACH,
getKey: null,
condition: null,
template: template('<button expr13="expr13" class="button is-fullwidth"><span style="font-size: .75em;"><strong expr14="expr14"> </strong></span><div style="margin-left: auto;"></div><span expr15="expr15" class="tag is-primary"> </span></button>', [{
redundantAttribute: 'expr13',
selector: '[expr13]',
template: template('<button expr307="expr307" class="button is-fullwidth"><span style="font-size: .75em;"><strong expr308="expr308"> </strong></span><div style="margin-left: auto;"></div><span expr309="expr309" class="tag is-primary"> </span></button>', [{
redundantAttribute: 'expr307',
selector: '[expr307]',
expressions: [{
type: expressionTypes.ATTRIBUTE,
name: 'disabled',
evaluate: _scope => _scope.state.updating
}, {
type: expressionTypes.EVENT,
name: 'onclick',
evaluate: _scope => () => _scope.cruiseForward(_scope.item.name)
}]
}, {
redundantAttribute: 'expr14',
selector: '[expr14]',
redundantAttribute: 'expr308',
selector: '[expr308]',
expressions: [{
type: expressionTypes.TEXT,
childNodeIndex: 0,
evaluate: _scope => _scope.item.name
}]
}, {
redundantAttribute: 'expr15',
selector: '[expr15]',
redundantAttribute: 'expr309',
selector: '[expr309]',
expressions: [{
type: expressionTypes.TEXT,
childNodeIndex: 0,
evaluate: _scope => _scope.item.count
}]
}]),
redundantAttribute: 'expr12',
selector: '[expr12]',
redundantAttribute: 'expr306',
selector: '[expr306]',
itemName: 'item',
indexName: null,
evaluate: _scope => _scope.state.items