2023-03-28 00:48:55 +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() {
|
|
|
|
let request = await fetch(`${PAPI.searchURL}&rows=0&sort=tri&facet=fili`);
|
|
|
|
let result = await request.json();
|
|
|
|
return result["facet_groups"][0]["facets"];
|
|
|
|
}
|
|
|
|
static async fetchFiliere(filiere) {
|
|
|
|
let request = await fetch(`${PAPI.searchURL}&rows=0&sort=tri&facet=form_lib_voe_acc&refine.fili=${filiere}`);
|
|
|
|
let result = await request.json();
|
|
|
|
return result["facet_groups"][0]["facets"];
|
|
|
|
}
|
|
|
|
static async fetchSpecialites(specialite) {
|
|
|
|
let request = await fetch(`${PAPI.searchURL}&rows=0&sort=tri&facet=fil_lib_voe_acc&refine.form_lib_voe_acc=${specialite}`);
|
|
|
|
let result = await request.json();
|
|
|
|
return result["facet_groups"][0]["facets"];
|
|
|
|
}
|
2023-03-28 16:51:44 +02:00
|
|
|
static async fetchEtablissement(filiere, sousfiliere, soussousfiliere) {
|
|
|
|
let request = await fetch(`${PAPI.searchURL}&refine.fil_lib_voe_acc=${soussousfiliere}&refine.form_lib_voe_acc=${sousfiliere}&refine.fili=${filiere}`);
|
|
|
|
let result = await request.json();
|
|
|
|
return result["records"];
|
|
|
|
}
|
2023-03-27 20:19:59 +02:00
|
|
|
}
|
2023-03-28 00:48:55 +02:00
|
|
|
|
2023-03-29 17:42:04 +02:00
|
|
|
const PLACEHOLDERS = ["Formation", "Filière", "Spécialité"];
|
2023-03-27 20:19:59 +02:00
|
|
|
var search = {
|
|
|
|
css: null,
|
2023-03-29 16:50:48 +02:00
|
|
|
exports: {
|
2023-03-29 17:42:04 +02:00
|
|
|
updateList() {
|
|
|
|
let promise;
|
|
|
|
switch (this.state.currentStep) {
|
|
|
|
case 0:
|
|
|
|
promise = PAPI.fetchFilieres();
|
|
|
|
break;
|
|
|
|
case 1:
|
2023-03-29 22:01:50 +02:00
|
|
|
promise = PAPI.fetchFiliere(this.state.course.fili);
|
2023-03-29 17:42:04 +02:00
|
|
|
break;
|
|
|
|
case 2:
|
2023-03-29 22:01:50 +02:00
|
|
|
promise = PAPI.fetchSpecialites(this.state.course.sousfili);
|
2023-03-29 17:42:04 +02:00
|
|
|
break;
|
2023-03-30 00:54:13 +02:00
|
|
|
default:
|
|
|
|
return;
|
2023-03-29 17:42:04 +02:00
|
|
|
}
|
2023-03-30 00:54:13 +02:00
|
|
|
this.update({
|
|
|
|
updating: true
|
|
|
|
});
|
2023-03-29 17:42:04 +02:00
|
|
|
promise.then(response => {
|
|
|
|
this.state.allItems = response;
|
|
|
|
this.filterSearch();
|
|
|
|
this.update({
|
|
|
|
updating: false
|
|
|
|
});
|
2023-03-29 22:56:14 +02:00
|
|
|
}, () => {
|
|
|
|
if (!this.state.currentStep) {
|
|
|
|
this.cruiseBack();
|
|
|
|
}
|
|
|
|
this.update({
|
|
|
|
updating: false
|
|
|
|
});
|
2023-03-29 17:42:04 +02:00
|
|
|
});
|
|
|
|
},
|
2023-03-29 22:56:14 +02:00
|
|
|
clearSearch() {
|
|
|
|
this.$("input").value = "";
|
|
|
|
},
|
2023-03-29 17:42:04 +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.allItems.filter(item => {
|
|
|
|
return item.name.toLowerCase().includes(input.value.toLowerCase());
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
finalArray = this.state.allItems;
|
|
|
|
}
|
|
|
|
this.update({
|
|
|
|
items: finalArray
|
|
|
|
});
|
|
|
|
},
|
|
|
|
cruiseForward(selection) {
|
|
|
|
switch (this.state.currentStep) {
|
|
|
|
case 0:
|
2023-03-29 22:01:50 +02:00
|
|
|
this.state.course.fili = selection;
|
2023-03-29 17:42:04 +02:00
|
|
|
break;
|
|
|
|
case 1:
|
2023-03-29 22:01:50 +02:00
|
|
|
this.state.course.sousfili = selection;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
this.state.course.soussousfili = selection;
|
2023-03-30 00:54:13 +02:00
|
|
|
this.props.updateCourse(this.state.course);
|
2023-03-29 22:56:14 +02:00
|
|
|
return;
|
|
|
|
default:
|
|
|
|
return;
|
2023-03-29 17:42:04 +02:00
|
|
|
}
|
|
|
|
this.state.currentStep++;
|
|
|
|
this.updateList();
|
2023-03-29 22:56:14 +02:00
|
|
|
this.clearSearch();
|
2023-03-29 17:42:04 +02:00
|
|
|
this.update({
|
|
|
|
placeholder: PLACEHOLDERS[this.state.currentStep]
|
|
|
|
});
|
|
|
|
},
|
|
|
|
cruiseBack() {
|
|
|
|
if (!this.state.currentStep) return;
|
|
|
|
this.state.currentStep--;
|
|
|
|
this.updateList();
|
2023-03-29 22:56:14 +02:00
|
|
|
this.clearSearch();
|
2023-03-29 17:42:04 +02:00
|
|
|
this.update({
|
|
|
|
placeholder: PLACEHOLDERS[this.state.currentStep]
|
|
|
|
});
|
|
|
|
},
|
2023-03-29 16:50:48 +02:00
|
|
|
onBeforeMount(props, state) {
|
|
|
|
//Initial state
|
|
|
|
this.state = {
|
2023-03-29 17:42:04 +02:00
|
|
|
placeholder: PLACEHOLDERS[0],
|
2023-03-29 16:50:48 +02:00
|
|
|
currentStep: 0,
|
|
|
|
allItems: null,
|
2023-03-29 17:42:04 +02:00
|
|
|
items: null,
|
2023-03-30 00:54:13 +02:00
|
|
|
course: {},
|
|
|
|
updating: false
|
2023-03-29 16:50:48 +02:00
|
|
|
};
|
2023-03-29 17:42:04 +02:00
|
|
|
},
|
2023-03-29 22:56:14 +02:00
|
|
|
onMounted(props, state) {
|
2023-03-29 17:42:04 +02:00
|
|
|
this.updateList();
|
2023-03-29 16:50:48 +02:00
|
|
|
}
|
2023-03-27 20:19:59 +02:00
|
|
|
},
|
2023-03-30 00:54:13 +02:00
|
|
|
template: (template, expressionTypes, bindingTypes, getComponent) => template('<div class="box p-1 m-2"><div class="columns m-1"><input expr1400="expr1400" class="input" type="input"/><button expr1401="expr1401" class="button ml-1"><</button></div><div id="list-formations"><ul><li expr1402="expr1402" class="m-1"></li></ul></div></div>', [{
|
|
|
|
redundantAttribute: 'expr1400',
|
|
|
|
selector: '[expr1400]',
|
2023-03-27 20:19:59 +02:00
|
|
|
expressions: [{
|
|
|
|
type: expressionTypes.EVENT,
|
2023-03-29 17:42:04 +02:00
|
|
|
name: 'onkeyup',
|
2023-03-29 16:50:48 +02:00
|
|
|
evaluate: _scope => _scope.filterSearch
|
2023-03-27 20:19:59 +02:00
|
|
|
}, {
|
|
|
|
type: expressionTypes.ATTRIBUTE,
|
|
|
|
name: 'placeholder',
|
|
|
|
evaluate: _scope => _scope.state.placeholder
|
|
|
|
}]
|
2023-03-28 00:48:55 +02:00
|
|
|
}, {
|
2023-03-30 00:54:13 +02:00
|
|
|
redundantAttribute: 'expr1401',
|
|
|
|
selector: '[expr1401]',
|
2023-03-28 00:48:55 +02:00
|
|
|
expressions: [{
|
2023-03-29 16:50:48 +02:00
|
|
|
type: expressionTypes.ATTRIBUTE,
|
|
|
|
name: 'disabled',
|
2023-03-29 17:42:04 +02:00
|
|
|
evaluate: _scope => !_scope.state.currentStep || _scope.state.updating
|
2023-03-29 16:50:48 +02:00
|
|
|
}, {
|
2023-03-28 00:48:55 +02:00
|
|
|
type: expressionTypes.EVENT,
|
|
|
|
name: 'onclick',
|
2023-03-29 16:50:48 +02:00
|
|
|
evaluate: _scope => _scope.cruiseBack
|
2023-03-28 00:48:55 +02:00
|
|
|
}]
|
2023-03-27 20:19:59 +02:00
|
|
|
}, {
|
|
|
|
type: bindingTypes.EACH,
|
|
|
|
getKey: null,
|
|
|
|
condition: null,
|
2023-03-30 00:54:13 +02:00
|
|
|
template: template('<button expr1403="expr1403" class="button is-fullwidth p-2"><span style="font-size: .75em; max-size: 90%"><strong expr1404="expr1404"> </strong></span><div style="margin-left: auto;"></div><span expr1405="expr1405" class="tag is-primary"> </span></button>', [{
|
|
|
|
redundantAttribute: 'expr1403',
|
|
|
|
selector: '[expr1403]',
|
2023-03-27 20:19:59 +02:00
|
|
|
expressions: [{
|
2023-03-29 17:42:04 +02:00
|
|
|
type: expressionTypes.ATTRIBUTE,
|
|
|
|
name: 'disabled',
|
|
|
|
evaluate: _scope => _scope.state.updating
|
|
|
|
}, {
|
2023-03-27 20:19:59 +02:00
|
|
|
type: expressionTypes.EVENT,
|
|
|
|
name: 'onclick',
|
2023-03-29 16:50:48 +02:00
|
|
|
evaluate: _scope => () => _scope.cruiseForward(_scope.item.name)
|
2023-03-27 20:19:59 +02:00
|
|
|
}]
|
|
|
|
}, {
|
2023-03-30 00:54:13 +02:00
|
|
|
redundantAttribute: 'expr1404',
|
|
|
|
selector: '[expr1404]',
|
2023-03-28 13:06:28 +02:00
|
|
|
expressions: [{
|
|
|
|
type: expressionTypes.TEXT,
|
|
|
|
childNodeIndex: 0,
|
|
|
|
evaluate: _scope => _scope.item.name
|
|
|
|
}]
|
|
|
|
}, {
|
2023-03-30 00:54:13 +02:00
|
|
|
redundantAttribute: 'expr1405',
|
|
|
|
selector: '[expr1405]',
|
2023-03-27 20:19:59 +02:00
|
|
|
expressions: [{
|
|
|
|
type: expressionTypes.TEXT,
|
|
|
|
childNodeIndex: 0,
|
|
|
|
evaluate: _scope => _scope.item.count
|
|
|
|
}]
|
|
|
|
}]),
|
2023-03-30 00:54:13 +02:00
|
|
|
redundantAttribute: 'expr1402',
|
|
|
|
selector: '[expr1402]',
|
2023-03-27 20:19:59 +02:00
|
|
|
itemName: 'item',
|
|
|
|
indexName: null,
|
|
|
|
evaluate: _scope => _scope.state.items
|
|
|
|
}]),
|
|
|
|
name: 'search'
|
|
|
|
};
|
|
|
|
|
|
|
|
export { search as default };
|