ProjetRIOT/components/search.riot

115 lines
4.6 KiB
Plaintext
Raw Normal View History

<search>
2023-03-28 13:06:28 +02:00
<div class="box p-1 m-2">
<div class="columns m-1">
<input onkeydown={searchF} class="input" type="input" placeholder={state.placeholder}>
<button class="button ml-1" onclick={back}>&lt;</button>
</div>
<div id="list-formations">
2023-03-26 15:03:06 +02:00
<ul>
2023-03-28 13:06:28 +02:00
<li class="m-1" each={item in this.state.items}>
<button class="button is-fullwidth" onclick={()=>filter(item.name)}>
2023-03-28 13:42:53 +02:00
<span style="font-size: .75em;"><strong>{item.name}</strong></span>
2023-03-28 13:06:28 +02:00
<div style="margin-left: auto;"></div>
<span class="tag is-primary">{item.count}</span>
</button>
2023-03-26 15:03:06 +02:00
</li>
</ul>
</div>
2023-03-28 13:06:28 +02:00
</div>
<script>
import PAPI from '../javascript/parcoursup-link.js'
2023-03-26 15:03:06 +02:00
2023-03-27 20:19:59 +02:00
const searchURL = `https://data.enseignementsup-recherche.gouv.fr/api/records/1.0/search/?dataset=fr-esr-parcoursup&timezone=Europe%2FBerlin`
2023-03-27 21:22:11 +02:00
async function fetchFiliere(state) {
if (state.sousfili){
return PAPI.fetchSpecialites(state.sousfili)
//var request = await fetch(`${searchURL}&rows=0&sort=tri&facet=fil_lib_voe_acc&refine.form_lib_voe_acc=${state.sousfili}`)
2023-03-27 21:22:11 +02:00
} else if (state.fili&&!state.sousfili){
return PAPI.fetchFiliere(state.fili)
//var request = await fetch(`${searchURL}&rows=0&sort=tri&facet=form_lib_voe_acc&refine.fili=${state.fili}`)
2023-03-27 21:22:11 +02:00
} else if (!state.fili&&!state.sousfili){
return PAPI.fetchFilieres()
//var request = await fetch(`${searchURL}&rows=0&sort=tri&facet=fili`)
2023-03-27 21:22:11 +02:00
}
//let result = await request.json()
//return result["facet_groups"][0]["facets"]
2023-03-26 15:03:06 +02:00
}
export default function search(){
2023-03-26 15:03:06 +02:00
return {
onBeforeMount(props, state) {
// initial state
this.state = {
2023-03-27 16:15:49 +02:00
placeholder: "Formation",
2023-03-26 22:12:11 +02:00
items: null,
2023-03-27 11:16:06 +02:00
allitems: null,
2023-03-27 16:15:49 +02:00
fili: null,
sousfili: null
2023-03-26 15:03:06 +02:00
}
2023-03-27 21:22:11 +02:00
fetchFiliere(this.state).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)
2023-03-27 16:15:49 +02:00
if (this.state.placeholder==="Filière de formation"){
2023-03-27 11:16:06 +02:00
this.update({
2023-03-27 16:15:49 +02:00
placeholder: "Filière de formation détaillée",
sousfili: fili,
})
2023-03-27 20:19:59 +02:00
} else if (this.state.placeholder="Formation"){
2023-03-27 11:16:06 +02:00
this.update({
2023-03-27 16:15:49 +02:00
placeholder: "Filière de formation",
2023-03-27 20:19:59 +02:00
fili: fili
})
2023-03-27 11:16:06 +02:00
}
2023-03-27 21:22:11 +02:00
fetchFiliere(this.state).then((response) => {
this.update({
allitems: response,
items: response
})
console.log(this.state.items)
})
2023-03-27 20:19:59 +02:00
},
back(){
console.log("back")
if (this.state.placeholder==="Filière de formation"){
2023-03-27 11:16:06 +02:00
this.update({
2023-03-27 20:19:59 +02:00
placeholder: "Formation",
fili: null,
})
} else if (this.state.placeholder="Filière de formation détaillée"){
this.update({
placeholder: "Filière de formation",
sousfili: null
})
}
2023-03-27 21:22:11 +02:00
fetchFiliere(this.state).then((response) => {
this.update({
allitems: response,
items: response
})
})
}
}
}
2023-03-26 15:03:06 +02:00
</script>
</search>