110 lines
4.3 KiB
Plaintext
110 lines
4.3 KiB
Plaintext
<search>
|
|
<label>
|
|
<input onkeydown={searchF} type="input" placeholder= {state.placeholder}>
|
|
<button onclick={back}><</button>
|
|
<div id="list-formations">
|
|
<ul>
|
|
<li each={item in this.state.items}>
|
|
<span onclick={()=>filter(item.name)}>{item.name}</span>
|
|
<span>{item.count}</span>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</label>
|
|
<script>
|
|
import PAPI from '../javascript/parcoursup-link.js'
|
|
|
|
const searchURL = `https://data.enseignementsup-recherche.gouv.fr/api/records/1.0/search/?dataset=fr-esr-parcoursup&timezone=Europe%2FBerlin`
|
|
|
|
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}`)
|
|
} 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}`)
|
|
} else if (!state.fili&&!state.sousfili){
|
|
return PAPI.fetchFilieres()
|
|
//var request = await fetch(`${searchURL}&rows=0&sort=tri&facet=fili`)
|
|
}
|
|
|
|
//let result = await request.json()
|
|
//return result["facet_groups"][0]["facets"]
|
|
}
|
|
|
|
export default function search(){
|
|
return {
|
|
onBeforeMount(props, state) {
|
|
// initial state
|
|
this.state = {
|
|
placeholder: "Formation",
|
|
items: null,
|
|
allitems: null,
|
|
fili: null,
|
|
sousfili: null
|
|
}
|
|
fetchFiliere(this.state).then((response) => {
|
|
this.update({
|
|
items: response,
|
|
allitems: response
|
|
})
|
|
})
|
|
},
|
|
searchF(e){
|
|
let responseFiltered=[]
|
|
this.state.allitems.forEach(formation => {
|
|
if (formation.name.toUpperCase().includes(e.target.value.toUpperCase())) {
|
|
responseFiltered.push(formation)
|
|
}
|
|
});
|
|
this.update({
|
|
items: responseFiltered
|
|
})
|
|
},
|
|
filter(fili){
|
|
console.log("filter! "+fili)
|
|
if (this.state.placeholder==="Filière de formation"){
|
|
this.update({
|
|
placeholder: "Filière de formation détaillée",
|
|
sousfili: fili,
|
|
})
|
|
} else if (this.state.placeholder="Formation"){
|
|
this.update({
|
|
placeholder: "Filière de formation",
|
|
fili: fili
|
|
})
|
|
}
|
|
fetchFiliere(this.state).then((response) => {
|
|
this.update({
|
|
allitems: response,
|
|
items: response
|
|
})
|
|
console.log(this.state.items)
|
|
})
|
|
},
|
|
back(){
|
|
console.log("back")
|
|
if (this.state.placeholder==="Filière de formation"){
|
|
this.update({
|
|
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
|
|
})
|
|
}
|
|
fetchFiliere(this.state).then((response) => {
|
|
this.update({
|
|
allitems: response,
|
|
items: response
|
|
})
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
</script>
|
|
</search> |