ProjetRIOT/components/search.riot

86 lines
3.2 KiB
Plaintext
Raw Normal View History

<search>
<label>
2023-03-26 22:12:11 +02:00
<input onkeydown={searchF} type="input" placeholder= {state.formation}>
<div id="list-formations">
2023-03-26 15:03:06 +02:00
<ul>
<li each={item in this.state.items}>
2023-03-27 11:16:06 +02:00
<span onclick={()=>filter(item.name)}>{item.name}</span>
2023-03-26 15:03:06 +02:00
<span>{item.count}</span>
</li>
</ul>
</div>
</label>
<script>
2023-03-26 15:03:06 +02:00
2023-03-27 11:16:06 +02:00
async function formation(whatToSearch){
let result = await fetch("https://data.enseignementsup-recherche.gouv.fr/api/records/1.0/search/?dataset=fr-esr-parcoursup&q=&sort=tri&facet="+whatToSearch+"&timezone=Europe%2FBerlin")
2023-03-26 15:03:06 +02:00
let resultats = await result.json()
let table = resultats["facet_groups"][0]["facets"]
return table
}
export default function search(){
2023-03-26 15:03:06 +02:00
return {
onBeforeMount(props, state) {
// initial state
this.state = {
formation: props.formation,
2023-03-26 22:12:11 +02:00
items: null,
2023-03-27 11:16:06 +02:00
allitems: null,
whatToSearch: "fili"
2023-03-26 15:03:06 +02:00
}
2023-03-27 11:16:06 +02:00
formation(this.state.whatToSearch).then((response) => {
2023-03-26 15:03:06 +02:00
this.update({
2023-03-26 22:12:11 +02:00
items: response,
allitems: response
2023-03-26 15:03:06 +02:00
})
})
},
2023-03-26 22:12:11 +02:00
searchF(e){
let responseFiltered=[]
this.state.allitems.forEach(formation => {
2023-03-27 11:16:06 +02:00
if (formation.name.toUpperCase().includes(e.target.value.toUpperCase())) {
2023-03-26 22:12:11 +02:00
responseFiltered.push(formation)
}
});
this.update({
items: responseFiltered
})
2023-03-27 11:16:06 +02:00
},
filter(fili){
console.log("filter! "+fili)
if (this.state.whatToSearch==="form_lib_voe_acc"){
this.update({
formation: "Filière de formation détaillée",
whatToSearch: "lib_for_voe_ins"
})
} else {
this.update({
formation: "Filière de formation",
whatToSearch: "form_lib_voe_acc"
})
}
formation(this.state.whatToSearch).then((response) => {
this.update({
allitems: response,
item: response
})
console.log(this.state.items)
})
let responseFiltered=[]
this.state.allitems.forEach(formation => {
if (formation.name.includes(fili)) {
responseFiltered.push(formation)
}
});
this.update({
allitems: responseFiltered,
items: responseFiltered
})
}
}
}
2023-03-26 15:03:06 +02:00
</script>
</search>