opti code search

This commit is contained in:
2023-03-27 21:22:11 +02:00
parent d4112402c1
commit 2a60706e63
2 changed files with 62 additions and 67 deletions

View File

@@ -1,16 +1,14 @@
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}`);
async function fetchFiliere(state) {
if (state.sousfili) {
await fetch(`${searchURL}&rows=0&sort=tri&facet=fil_lib_voe_acc&refine.form_lib_voe_acc=${sousfiliere}`);
} else if (state.fili & !state.sousfili) {
await fetch(`${searchURL}&rows=0&sort=tri&facet=form_lib_voe_acc&refine.fili=${filiere}`);
} else if (!state.fili & !state.sousfili) {
await fetch(`${searchURL}&rows=0&sort=tri&facet=fili`);
} else {
console.log("ta verif elle pue");
}
let result = await request.json();
return result["facet_groups"][0]["facets"];
}
@@ -25,9 +23,9 @@ var search = {
items: null,
allitems: null,
fili: null,
button: "disabled"
sousfili: null
};
fetchFiliere0().then(response => {
fetchFiliere(this.state).then(response => {
this.update({
items: response,
allitems: response
@@ -50,9 +48,9 @@ var search = {
if (this.state.placeholder === "Filière de formation") {
this.update({
placeholder: "Filière de formation détaillée",
fili: fili
sousfili: fili
});
fetchFiliere2(this.state.fili).then(response => {
fetchFiliere(this.state).then(response => {
this.update({
allitems: response,
items: response
@@ -64,7 +62,7 @@ var search = {
placeholder: "Filière de formation",
fili: fili
});
fetchFiliere1(this.state.fili).then(response => {
fetchFiliere(this.state).then(response => {
this.update({
allitems: response,
items: response
@@ -75,6 +73,31 @@ var search = {
},
back() {
console.log("back");
if (this.state.placeholder === "Filière de formation") {
this.update({
placeholder: "Formation",
fili: null
});
fetchFiliere(state).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
});
fetchFiliere(this.state).then(response => {
this.update({
allitems: response,
items: response
});
console.log(this.state.items);
});
}
}
};
},
@@ -97,10 +120,6 @@ var search = {
type: expressionTypes.EVENT,
name: 'onclick',
evaluate: _scope => _scope.back
}, {
type: expressionTypes.ATTRIBUTE,
name: 'this.state.button',
evaluate: _scope => _scope.state.button
}]
}, {
type: bindingTypes.EACH,