search 3/3

This commit is contained in:
Haïssous Kayyissa 2023-03-27 20:19:59 +02:00
parent 77c36b7d8b
commit d4112402c1
4 changed files with 332 additions and 22 deletions

View File

@ -1,6 +1,7 @@
<search> <search>
<label> <label>
<input onkeydown={searchF} type="input" placeholder= {state.placeholder}> <input onkeydown={searchF} type="input" placeholder= {state.placeholder}>
<button onclick={back}><</button>
<div id="list-formations"> <div id="list-formations">
<ul> <ul>
<li each={item in this.state.items}> <li each={item in this.state.items}>
@ -12,11 +13,27 @@
</label> </label>
<script> <script>
async function apiLink(whatToSearch, whereToSearch){ const searchURL = `https://data.enseignementsup-recherche.gouv.fr/api/records/1.0/search/?dataset=fr-esr-parcoursup&timezone=Europe%2FBerlin`
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")
let resultats = await result.json() async function fetchFiliere0() {
let table = resultats["facet_groups"][whereToSearch]["facets"] let request = await fetch(`${searchURL}&rows=0&sort=tri&facet=fili`)
return table let result = await request.json()
return result["facet_groups"][0]["facets"]
}
async function fetchFiliere1(filiere) {
let request = await fetch(`${searchURL}&rows=0&sort=tri&facet=form_lib_voe_acc&refine.fili=${filiere}`)
let result = await request.json()
return result["facet_groups"][0]["facets"]
}
async function fetchFiliere2(sousfiliere) {
let request = await fetch(`${searchURL}&rows=0&sort=tri&facet=fil_lib_voe_acc&refine.form_lib_voe_acc=${sousfiliere}`)
let result = await request.json()
return result["facet_groups"][0]["facets"]
} }
export default function search(){ export default function search(){
@ -27,11 +44,10 @@
placeholder: "Formation", placeholder: "Formation",
items: null, items: null,
allitems: null, allitems: null,
whatToSearch: "fili",
fili: null, fili: null,
sousfili: null sousfili: null
} }
apiLink(this.state.whatToSearch,0).then((response) => { fetchFiliere0().then((response) => {
this.update({ this.update({
items: response, items: response,
allitems: response allitems: response
@ -51,28 +67,60 @@
}, },
filter(fili){ filter(fili){
console.log("filter! "+fili) console.log("filter! "+fili)
let step=0;
if (this.state.placeholder==="Filière de formation"){ if (this.state.placeholder==="Filière de formation"){
this.update({ this.update({
placeholder: "Filière de formation détaillée", placeholder: "Filière de formation détaillée",
sousfili: fili, sousfili: fili,
whatToSearch: "fili&facet=form_lib_voe_acc&facet=fil_lib_voe_acc&refine.form_lib_voe_acc="+this.state.sousfili+"&refine.fili="this.state.fili
}) })
} else { fetchFiliere2(this.state.sousfili).then((response) => {
this.update({
placeholder: "Filière de formation",
fili: fili,
whatToSearch: "fili&facet=form_lib_voe_acc&refine.fili="+this.state.fili
})
}
apiLink(this.state.whatToSearch).then((response) => {
this.update({ this.update({
allitems: response, allitems: response,
item: response items: response
})
})
console.log(this.state.items)
} else if (this.state.placeholder="Formation"){
this.update({
placeholder: "Filière de formation",
fili: fili
})
fetchFiliere1(this.state.fili).then((response) => {
this.update({
allitems: response,
items: response
}) })
console.log(this.state.items) console.log(this.state.items)
}) })
} }
},
back(){
console.log("back")
if (this.state.placeholder==="Filière de formation"){
this.update({
placeholder: "Formation",
fili: null,
})
fetchFiliere0().then((response) => {
this.update({
allitems: response,
items: response
})
})
console.log(this.state.items)
} else if (this.state.placeholder="Filière de formation détaillée"){
this.update({
placeholder: "Filière de formation",
sousfili: null
})
fetchFiliere1(this.state.fili).then((response) => {
this.update({
allitems: response,
items: response
})
console.log(this.state.items)
})
}
}
} }
} }

View File

@ -0,0 +1,139 @@
const searchURL = `https://data.enseignementsup-recherche.gouv.fr/api/records/1.0/search/?dataset=fr-esr-parcoursup&timezone=Europe%2FBerlin`;
async function fetchFiliere0() {
let request = await fetch(`${searchURL}&rows=0&sort=tri&facet=fili`);
let result = await request.json();
return result["facet_groups"][0]["facets"];
}
async function fetchFiliere1(filiere) {
let request = await fetch(`${searchURL}&rows=0&sort=tri&facet=form_lib_voe_acc&refine.fili=${filiere}`);
let result = await request.json();
return result["facet_groups"][0]["facets"];
}
async function fetchFiliere2(sousfiliere) {
let request = await fetch(`${searchURL}&rows=0&sort=tri&facet=fil_lib_voe_acc&refine.form_lib_voe_acc=${sousfiliere}`);
let result = await request.json();
return result["facet_groups"][0]["facets"];
}
var search = {
css: null,
exports: function search() {
return {
onBeforeMount(props, state) {
// initial state
this.state = {
placeholder: "Formation",
items: null,
allitems: null,
fili: null,
button: "disabled"
};
fetchFiliere0().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",
fili: fili
});
fetchFiliere2(this.state.fili).then(response => {
this.update({
allitems: response,
items: response
});
});
console.log(this.state.items);
} else if (this.state.placeholder = "Formation") {
this.update({
placeholder: "Filière de formation",
fili: fili
});
fetchFiliere1(this.state.fili).then(response => {
this.update({
allitems: response,
items: response
});
console.log(this.state.items);
});
}
},
back() {
console.log("back");
}
};
},
template: (template, expressionTypes, bindingTypes, getComponent) => template('<label><input expr0="expr0" type="input"/><button expr1="expr1"><</button><div id="list-formations"><ul><li expr2="expr2"></li></ul></div></label>', [{
redundantAttribute: 'expr0',
selector: '[expr0]',
expressions: [{
type: expressionTypes.EVENT,
name: 'onkeydown',
evaluate: _scope => _scope.searchF
}, {
type: expressionTypes.ATTRIBUTE,
name: 'placeholder',
evaluate: _scope => _scope.state.placeholder
}]
}, {
redundantAttribute: 'expr1',
selector: '[expr1]',
expressions: [{
type: expressionTypes.EVENT,
name: 'onclick',
evaluate: _scope => _scope.back
}, {
type: expressionTypes.ATTRIBUTE,
name: 'this.state.button',
evaluate: _scope => _scope.state.button
}]
}, {
type: bindingTypes.EACH,
getKey: null,
condition: null,
template: template('<span expr3="expr3"> </span><span expr4="expr4"> </span>', [{
redundantAttribute: 'expr3',
selector: '[expr3]',
expressions: [{
type: expressionTypes.TEXT,
childNodeIndex: 0,
evaluate: _scope => _scope.item.name
}, {
type: expressionTypes.EVENT,
name: 'onclick',
evaluate: _scope => () => _scope.filter(_scope.item.name)
}]
}, {
redundantAttribute: 'expr4',
selector: '[expr4]',
expressions: [{
type: expressionTypes.TEXT,
childNodeIndex: 0,
evaluate: _scope => _scope.item.count
}]
}]),
redundantAttribute: 'expr2',
selector: '[expr2]',
itemName: 'item',
indexName: null,
evaluate: _scope => _scope.state.items
}]),
name: 'search'
};
export { search as default };

View File

@ -17,7 +17,7 @@ class PAPI {
} }
static async fetchFiliere(filiere) { static async fetchFiliere(filiere) {
let request = await fetch(`${PAPI.searchURL}&rows=0&sort=tri&facet=lib_for_voe_ins&refine.fili=${filiere}`) let request = await fetch(`${PAPI.searchURL}&rows=0&sort=tri&facet=form_lib_voe_acc&refine.fili=${filiere}`)
let result = await request.json() let result = await request.json()
return result["facet_groups"][0]["facets"] return result["facet_groups"][0]["facets"]

123
javascript/search.js Normal file
View File

@ -0,0 +1,123 @@
const searchURL = `https://data.enseignementsup-recherche.gouv.fr/api/records/1.0/search/?dataset=fr-esr-parcoursup&timezone=Europe%2FBerlin`;
async function fetchFiliere0() {
let request = await fetch(`${searchURL}&rows=0&sort=tri&facet=fili`);
let result = await request.json();
return result["facet_groups"][0]["facets"];
}
async function fetchFiliere1(filiere) {
let request = await fetch(`${searchURL}&rows=0&sort=tri&facet=form_lib_voe_acc&refine.fili=${filiere}`);
let result = await request.json();
return result["facet_groups"][0]["facets"];
}
async function fetchFiliere2(sousfiliere) {
let request = await fetch(`${searchURL}&rows=0&sort=tri&facet=fil_lib_voe_acc&refine.form_lib_voe_acc=${sousfiliere}`);
let result = await request.json();
return result["facet_groups"][0]["facets"];
}
var search = {
css: null,
exports: function search() {
return {
onBeforeMount(props, state) {
// initial state
this.state = {
placeholder: "Formation",
items: null,
allitems: null,
fili: null
};
fetchFiliere0().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",
fili: fili
});
fetchFiliere2(this.state.fili).then(response => {
this.update({
allitems: response,
items: response
});
});
console.log(this.state.items);
} else if (this.state.placeholder = "Formation") {
this.update({
placeholder: "Filière de formation",
fili: fili
});
fetchFiliere1(this.state.fili).then(response => {
this.update({
allitems: response,
items: response
});
console.log(this.state.items);
});
}
}
};
},
template: (template, expressionTypes, bindingTypes, getComponent) => template('<label><input expr36="expr36" type="input"/><div id="list-formations"><ul><li expr37="expr37"></li></ul></div></label>', [{
redundantAttribute: 'expr36',
selector: '[expr36]',
expressions: [{
type: expressionTypes.EVENT,
name: 'onkeydown',
evaluate: _scope => _scope.searchF
}, {
type: expressionTypes.ATTRIBUTE,
name: 'placeholder',
evaluate: _scope => _scope.state.placeholder
}]
}, {
type: bindingTypes.EACH,
getKey: null,
condition: null,
template: template('<span expr38="expr38"> </span><span expr39="expr39"> </span>', [{
redundantAttribute: 'expr38',
selector: '[expr38]',
expressions: [{
type: expressionTypes.TEXT,
childNodeIndex: 0,
evaluate: _scope => _scope.item.name
}, {
type: expressionTypes.EVENT,
name: 'onclick',
evaluate: _scope => () => _scope.filter(_scope.item.name)
}]
}, {
redundantAttribute: 'expr39',
selector: '[expr39]',
expressions: [{
type: expressionTypes.TEXT,
childNodeIndex: 0,
evaluate: _scope => _scope.item.count
}]
}]),
redundantAttribute: 'expr37',
selector: '[expr37]',
itemName: 'item',
indexName: null,
evaluate: _scope => _scope.state.items
}]),
name: 'search'
};
export { search as default };