2023-03-31 00:49:11 +02:00
|
|
|
/*
|
|
|
|
Parcoursup API (PAPI)
|
|
|
|
Comprend un set de wrapper afin d'accéder plus aisément aux informations de l'API parcoursup
|
|
|
|
*/
|
|
|
|
|
|
|
|
class PAPI {
|
|
|
|
static dataset = "fr-esr-parcoursup";
|
|
|
|
static timezone = "Europe%2FBerlin";
|
|
|
|
static searchURL = `https://data.enseignementsup-recherche.gouv.fr/api/records/1.0/search/?dataset=${PAPI.dataset}&timezone=${PAPI.timezone}`;
|
|
|
|
static async fetchFilieres() {
|
|
|
|
if (localStorage.getItem("filis")) return JSON.parse(localStorage.getItem("filis"));
|
|
|
|
let request = await fetch(`${PAPI.searchURL}&rows=0&sort=tri&facet=fili`);
|
|
|
|
let result = await request.json();
|
|
|
|
let response = result["facet_groups"][0]["facets"];
|
|
|
|
localStorage.setItem("filis", JSON.stringify(response));
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
static async fetchFiliere(filiere) {
|
|
|
|
if (localStorage.getItem("fili." + filiere)) return JSON.parse(localStorage.getItem("fili." + filiere));
|
2023-03-31 11:37:06 +02:00
|
|
|
let url = `${PAPI.searchURL}&rows=0&sort=tri&facet=form_lib_voe_acc&refine.fili=${filiere}`;
|
|
|
|
url = url.replace("+", "%2B");
|
|
|
|
let request = await fetch(url);
|
2023-03-31 00:49:11 +02:00
|
|
|
let result = await request.json();
|
|
|
|
let response = result["facet_groups"][0]["facets"];
|
|
|
|
localStorage.setItem("fili." + filiere, JSON.stringify(response));
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
static async fetchSpecialites(filiere, specialite) {
|
|
|
|
if (localStorage.getItem(`spe.${filiere}.${specialite}`)) return JSON.parse(localStorage.getItem(`spe.${filiere}.${specialite}`));
|
2023-03-31 11:37:06 +02:00
|
|
|
let url = `${PAPI.searchURL}&rows=0&sort=tri&facet=fil_lib_voe_acc&refine.form_lib_voe_acc=${specialite}&refine.fili=${filiere}`;
|
|
|
|
url = url.replace("+", "%2B");
|
|
|
|
let request = await fetch(url);
|
2023-03-31 00:49:11 +02:00
|
|
|
let result = await request.json();
|
|
|
|
let response = result["facet_groups"][0]["facets"];
|
|
|
|
localStorage.setItem(`spe.${filiere}.${specialite}`, JSON.stringify(response));
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
static async fetchEtablissement(filiere, sousfiliere, soussousfiliere) {
|
|
|
|
if (localStorage.getItem(`eta.${filiere}.${sousfiliere}.${soussousfiliere}`)) return JSON.parse(localStorage.getItem(`eta.${filiere}.${sousfiliere}.${soussousfiliere}`));
|
2023-03-31 11:37:06 +02:00
|
|
|
let url = `${PAPI.searchURL}&rows=10000&refine.fil_lib_voe_acc=${soussousfiliere}&refine.form_lib_voe_acc=${sousfiliere}&refine.fili=${filiere}`;
|
|
|
|
url = url.replace("+", "%2B");
|
|
|
|
let request = await fetch(url);
|
2023-03-31 00:49:11 +02:00
|
|
|
let result = await request.json();
|
|
|
|
let response = result["records"];
|
|
|
|
localStorage.setItem(`eta.${filiere}.${sousfiliere}.${soussousfiliere}`, JSON.stringify(response));
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const SORT_TABLE = [{
|
|
|
|
name: "Nom",
|
|
|
|
id: "g_ea_lib_vx"
|
|
|
|
}, {
|
|
|
|
name: "Ville",
|
|
|
|
id: "ville_etab"
|
|
|
|
}, {
|
|
|
|
name: "Département",
|
|
|
|
id: "dep"
|
|
|
|
}, {
|
|
|
|
name: "Moyenne",
|
|
|
|
id: "moyenne"
|
|
|
|
}, {
|
|
|
|
name: "Sélectivité",
|
|
|
|
id: "taux_acces_ens"
|
|
|
|
}];
|
2023-03-28 13:42:53 +02:00
|
|
|
var mainController = {
|
|
|
|
css: null,
|
2023-03-29 22:56:14 +02:00
|
|
|
exports: {
|
2023-03-31 00:49:11 +02:00
|
|
|
sortList(sortBy) {
|
|
|
|
//Si la liste est déjà triée par la bonne catégorie, on l'inverse
|
|
|
|
if (sortBy == this.state.sortBy) {
|
2023-03-31 11:34:14 +02:00
|
|
|
this.state.filteredSchoolList.reverse();
|
2023-03-31 00:49:11 +02:00
|
|
|
}
|
|
|
|
//Sinon on l'ordonne par la nouvelle catégorie (ascendant par défaut)
|
|
|
|
else {
|
|
|
|
this.state.sortBy = sortBy;
|
|
|
|
switch (sortBy) {
|
|
|
|
case SORT_TABLE[3].id:
|
|
|
|
case SORT_TABLE[4].id:
|
|
|
|
{
|
2023-03-31 11:34:14 +02:00
|
|
|
this.state.filteredSchoolList.sort((a, b) => {
|
2023-03-31 00:49:11 +02:00
|
|
|
if (a.fields[sortBy] > b.fields[sortBy]) return 1;else return -1;
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
2023-03-31 11:34:14 +02:00
|
|
|
this.state.filteredSchoolList.sort((a, b) => {
|
2023-03-31 00:49:11 +02:00
|
|
|
return a.fields[sortBy].localeCompare(b.fields[sortBy]);
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-31 11:34:14 +02:00
|
|
|
this.update();
|
2023-03-31 00:49:11 +02:00
|
|
|
},
|
|
|
|
updateList(course) {
|
|
|
|
course = course || this.state.course;
|
|
|
|
PAPI.fetchEtablissement(course.fili, course.sousfili, course.soussousfili).then(response => {
|
|
|
|
response.forEach(etablissement => {
|
|
|
|
// calcul la moyenne
|
|
|
|
let pct_sansmention = etablissement.fields.pct_sansmention;
|
|
|
|
let pct_AB = etablissement.fields.pct_ab;
|
|
|
|
let pct_B = etablissement.fields.pct_b;
|
|
|
|
let pct_TB = etablissement.fields.pct_tb;
|
|
|
|
let pct_TBF = etablissement.fields.pct_tbf;
|
|
|
|
|
|
|
|
// On prend la moyenne des moyennes comprises dans la mention
|
|
|
|
// Exemple : Assez bien est entre 12 et 14 donc 13.
|
|
|
|
etablissement.fields.moyenne = (pct_TBF * 19 + pct_TB * 17 + pct_B * 15 + pct_AB * 13 + pct_sansmention * 11) / 100;
|
|
|
|
});
|
|
|
|
this.update({
|
|
|
|
schoolList: response
|
|
|
|
});
|
2023-03-31 11:34:14 +02:00
|
|
|
this.filterSearch();
|
2023-03-31 00:49:11 +02:00
|
|
|
});
|
2023-03-29 22:01:50 +02:00
|
|
|
},
|
2023-03-30 00:54:13 +02:00
|
|
|
updateCourse(course) {
|
2023-03-31 00:49:11 +02:00
|
|
|
this.updateList(course);
|
2023-03-29 22:01:50 +02:00
|
|
|
this.update({
|
2023-03-30 00:54:13 +02:00
|
|
|
course: course,
|
2023-03-31 00:49:11 +02:00
|
|
|
sortFields: SORT_TABLE,
|
|
|
|
shouldShowInfos: course != null
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onMounted(props, state) {
|
|
|
|
this.update({
|
|
|
|
course: null,
|
|
|
|
sortBy: null,
|
|
|
|
schoolList: null,
|
|
|
|
sortFields: SORT_TABLE,
|
2023-03-31 11:34:14 +02:00
|
|
|
filteredSchoolList: null,
|
2023-03-31 00:49:11 +02:00
|
|
|
shouldShowInfos: false
|
2023-03-29 22:01:50 +02:00
|
|
|
});
|
2023-03-31 11:34:14 +02:00
|
|
|
},
|
|
|
|
filterSearch() {
|
|
|
|
let input = this.$("input");
|
|
|
|
if (!input) return;
|
|
|
|
let finalArray = [];
|
|
|
|
|
|
|
|
//On évite de trier avant d'avoir plus de 1 lettres.
|
|
|
|
if (input.value.length > 1) {
|
|
|
|
finalArray = this.state.schoolList.filter(item => {
|
|
|
|
return item.name.toLowerCase().includes(input.value.toLowerCase());
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
finalArray = this.state.schoolList;
|
|
|
|
}
|
|
|
|
this.update({
|
|
|
|
filteredSchoolList: finalArray
|
|
|
|
});
|
2023-03-29 22:56:14 +02:00
|
|
|
}
|
|
|
|
},
|
2023-03-31 11:37:06 +02:00
|
|
|
template: (template, expressionTypes, bindingTypes, getComponent) => template('<div class="columns"><div class="column is-one-third"><div class="box p-3 m-2" style="display: flex"><img class="m-auto" src="./resources/logo-parcoursup.svg"/></div><search expr59="expr59"></search></div><div class="column"><fili-info expr60="expr60"></fili-info><school expr61="expr61"></school></div></div><school-info expr62="expr62"></school-info>', [{
|
2023-03-28 13:42:53 +02:00
|
|
|
type: bindingTypes.TAG,
|
|
|
|
getComponent: getComponent,
|
|
|
|
evaluate: _scope => 'search',
|
|
|
|
slots: [],
|
2023-03-29 22:56:14 +02:00
|
|
|
attributes: [{
|
|
|
|
type: expressionTypes.ATTRIBUTE,
|
2023-03-29 22:01:50 +02:00
|
|
|
name: 'updateCourse',
|
|
|
|
evaluate: _scope => _scope.updateCourse
|
2023-03-29 22:56:14 +02:00
|
|
|
}],
|
2023-03-31 11:37:06 +02:00
|
|
|
redundantAttribute: 'expr59',
|
|
|
|
selector: '[expr59]'
|
2023-03-28 13:42:53 +02:00
|
|
|
}, {
|
|
|
|
type: bindingTypes.TAG,
|
|
|
|
getComponent: getComponent,
|
|
|
|
evaluate: _scope => 'fili-info',
|
|
|
|
slots: [],
|
2023-03-30 00:54:13 +02:00
|
|
|
attributes: [{
|
2023-03-31 00:49:11 +02:00
|
|
|
type: expressionTypes.ATTRIBUTE,
|
|
|
|
name: 'schoolList',
|
|
|
|
evaluate: _scope => _scope.state.schoolList
|
|
|
|
}, {
|
2023-03-30 00:54:13 +02:00
|
|
|
type: expressionTypes.ATTRIBUTE,
|
|
|
|
name: 'course',
|
|
|
|
evaluate: _scope => _scope.state.course
|
|
|
|
}, {
|
|
|
|
type: expressionTypes.ATTRIBUTE,
|
|
|
|
name: 'shouldShowInfos',
|
|
|
|
evaluate: _scope => _scope.state.shouldShowInfos
|
|
|
|
}],
|
2023-03-31 11:37:06 +02:00
|
|
|
redundantAttribute: 'expr60',
|
|
|
|
selector: '[expr60]'
|
2023-03-28 13:42:53 +02:00
|
|
|
}, {
|
|
|
|
type: bindingTypes.TAG,
|
|
|
|
getComponent: getComponent,
|
|
|
|
evaluate: _scope => 'school',
|
|
|
|
slots: [],
|
2023-03-30 00:54:13 +02:00
|
|
|
attributes: [{
|
2023-03-30 19:28:40 +02:00
|
|
|
type: expressionTypes.ATTRIBUTE,
|
2023-03-31 00:49:11 +02:00
|
|
|
name: 'sortList',
|
|
|
|
evaluate: _scope => _scope.sortList
|
|
|
|
}, {
|
|
|
|
type: expressionTypes.ATTRIBUTE,
|
|
|
|
name: 'schoolList',
|
2023-03-31 11:34:14 +02:00
|
|
|
evaluate: _scope => _scope.state.filteredSchoolList
|
2023-03-31 00:49:11 +02:00
|
|
|
}, {
|
|
|
|
type: expressionTypes.ATTRIBUTE,
|
|
|
|
name: 'sortFields',
|
|
|
|
evaluate: _scope => _scope.state.sortFields
|
2023-03-30 19:28:40 +02:00
|
|
|
}, {
|
2023-03-30 00:54:13 +02:00
|
|
|
type: expressionTypes.ATTRIBUTE,
|
|
|
|
name: 'course',
|
|
|
|
evaluate: _scope => _scope.state.course
|
|
|
|
}, {
|
|
|
|
type: expressionTypes.ATTRIBUTE,
|
|
|
|
name: 'shouldShowInfos',
|
|
|
|
evaluate: _scope => _scope.state.shouldShowInfos
|
|
|
|
}],
|
2023-03-31 11:37:06 +02:00
|
|
|
redundantAttribute: 'expr61',
|
|
|
|
selector: '[expr61]'
|
2023-03-28 13:42:53 +02:00
|
|
|
}, {
|
|
|
|
type: bindingTypes.TAG,
|
|
|
|
getComponent: getComponent,
|
|
|
|
evaluate: _scope => 'school-info',
|
|
|
|
slots: [],
|
|
|
|
attributes: [],
|
2023-03-31 11:37:06 +02:00
|
|
|
redundantAttribute: 'expr62',
|
|
|
|
selector: '[expr62]'
|
2023-03-28 13:42:53 +02:00
|
|
|
}]),
|
|
|
|
name: 'main-controller'
|
|
|
|
};
|
|
|
|
|
|
|
|
export { mainController as default };
|