From 0613632b241cbd43be48289328cab1eb014b1453 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=C3=AFssous?= Date: Thu, 30 Mar 2023 17:26:23 +0200 Subject: [PATCH] =?UTF-8?q?d=C3=A9but=20tri=20tableau?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/school.riot | 25 +++++++--- index.html | 1 + javascript/school.js | 103 +++++++++++++++++++++++++++++++---------- javascript/search.js | 48 ++++++++++++------- 4 files changed, 128 insertions(+), 49 deletions(-) diff --git a/components/school.riot b/components/school.riot index c883ea5..7ee2392 100644 --- a/components/school.riot +++ b/components/school.riot @@ -13,11 +13,11 @@ - - - - - + + + + + @@ -44,10 +44,10 @@ onBeforeMount(props, state) { state = { items: null, - breakCycle: false + breakCycle: false, + ascOrder: true } }, - onUpdated(props, state) { if (!props.shouldShowInfos || state.breakCycle) return fetchEtablissement(props.course).then((response) => { @@ -70,6 +70,17 @@ }) state.breakCycle = false }) + }, + sort(e){ + console.log("sort") + console.log(e.target) + if (this.state.ascOrder){ + this.state.items.sort((etablissement1, etablissement2)=>etablissement2.fields[order]-etablissement1.fields[order])) + } else { + this.state.items.sort((etablissement1, etablissement2)=>etablissement1.fields[order]-etablissement2.fields[order])) + } + this.state.ascOrder=!this.state.ascOrder + this.update() } } } diff --git a/index.html b/index.html index de67921..41f24d7 100644 --- a/index.html +++ b/index.html @@ -6,6 +6,7 @@ + diff --git a/javascript/school.js b/javascript/school.js index 2d8436d..07a7e84 100644 --- a/javascript/school.js +++ b/javascript/school.js @@ -8,24 +8,36 @@ class PAPI { 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(); - return result["facet_groups"][0]["facets"]; + 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)); 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"]; + let response = result["facet_groups"][0]["facets"]; + localStorage.setItem("fili." + filiere, JSON.stringify(response)); + return response; } static async fetchSpecialites(specialite) { + if (localStorage.getItem("spe." + specialite)) return JSON.parse(localStorage.getItem("spe." + 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"]; + let response = result["facet_groups"][0]["facets"]; + localStorage.setItem("spe." + 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}`)); 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"]; + let response = result["records"]; + localStorage.setItem(`eta.${filiere}.${sousfiliere}.${soussousfiliere}`, JSON.stringify(response)); + return response; } } @@ -39,7 +51,7 @@ var school = { onBeforeMount(props, state) { }, onUpdated(props, state) { - if (!props.shouldShowInfos) return; + if (!props.shouldShowInfos || state.breakCycle) return; fetchEtablissement(props.course).then(response => { response.forEach(etablissement => { // calcul la moyenne @@ -53,65 +65,108 @@ var school = { // 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; }); + state.breakCycle = true; this.update({ items: response }); + state.breakCycle = false; }); - } + }, + sort(e) {} }; }, - template: (template, expressionTypes, bindingTypes, getComponent) => template('
', [{ + template: (template, expressionTypes, bindingTypes, getComponent) => template('
', [{ type: bindingTypes.IF, evaluate: _scope => _scope.props.shouldShowInfos, - redundantAttribute: 'expr1453', - selector: '[expr1453]', - template: template('
NomVilleDptMoyenneSélectivitéNomVilleDptMoyenneSélectivité
NomVilleDptMoyenneSélectivité
', [{ + redundantAttribute: 'expr693', + selector: '[expr693]', + template: template('
NomVilleDptMoyenneSélectivité
', [{ + redundantAttribute: 'expr694', + selector: '[expr694]', + expressions: [{ + type: expressionTypes.EVENT, + name: 'onclick', + evaluate: _scope => _scope.sort + }] + }, { + redundantAttribute: 'expr695', + selector: '[expr695]', + expressions: [{ + type: expressionTypes.EVENT, + name: 'onclick', + evaluate: _scope => _scope.sort + }] + }, { + redundantAttribute: 'expr696', + selector: '[expr696]', + expressions: [{ + type: expressionTypes.EVENT, + name: 'onclick', + evaluate: _scope => _scope.sort + }] + }, { + redundantAttribute: 'expr697', + selector: '[expr697]', + expressions: [{ + type: expressionTypes.EVENT, + name: 'onclick', + evaluate: _scope => _scope.sort + }] + }, { + redundantAttribute: 'expr698', + selector: '[expr698]', + expressions: [{ + type: expressionTypes.EVENT, + name: 'onclick', + evaluate: _scope => _scope.sort + }] + }, { type: bindingTypes.EACH, getKey: null, - condition: _scope => !_scope.state.loading, - template: template(' ', [{ - redundantAttribute: 'expr1455', - selector: '[expr1455]', + condition: null, + template: template(' ', [{ + redundantAttribute: 'expr700', + selector: '[expr700]', expressions: [{ type: expressionTypes.TEXT, childNodeIndex: 0, evaluate: _scope => _scope.etablissement.fields.g_ea_lib_vx }] }, { - redundantAttribute: 'expr1456', - selector: '[expr1456]', + redundantAttribute: 'expr701', + selector: '[expr701]', expressions: [{ type: expressionTypes.TEXT, childNodeIndex: 0, evaluate: _scope => _scope.etablissement.fields.ville_etab }] }, { - redundantAttribute: 'expr1457', - selector: '[expr1457]', + redundantAttribute: 'expr702', + selector: '[expr702]', expressions: [{ type: expressionTypes.TEXT, childNodeIndex: 0, evaluate: _scope => _scope.etablissement.fields.dep }] }, { - redundantAttribute: 'expr1458', - selector: '[expr1458]', + redundantAttribute: 'expr703', + selector: '[expr703]', expressions: [{ type: expressionTypes.TEXT, childNodeIndex: 0, evaluate: _scope => _scope.etablissement.fields.moyenne }] }, { - redundantAttribute: 'expr1459', - selector: '[expr1459]', + redundantAttribute: 'expr704', + selector: '[expr704]', expressions: [{ type: expressionTypes.TEXT, childNodeIndex: 0, evaluate: _scope => _scope.etablissement.fields.taux_acces_ens }] }]), - redundantAttribute: 'expr1454', - selector: '[expr1454]', + redundantAttribute: 'expr699', + selector: '[expr699]', itemName: 'etablissement', indexName: null, evaluate: _scope => _scope.state.items diff --git a/javascript/search.js b/javascript/search.js index ea0a6d9..5715002 100644 --- a/javascript/search.js +++ b/javascript/search.js @@ -8,24 +8,36 @@ class PAPI { 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(); - return result["facet_groups"][0]["facets"]; + 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)); 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"]; + let response = result["facet_groups"][0]["facets"]; + localStorage.setItem("fili." + filiere, JSON.stringify(response)); + return response; } static async fetchSpecialites(specialite) { + if (localStorage.getItem("spe." + specialite)) return JSON.parse(localStorage.getItem("spe." + 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"]; + let response = result["facet_groups"][0]["facets"]; + localStorage.setItem("spe." + 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}`)); 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"]; + let response = result["records"]; + localStorage.setItem(`eta.${filiere}.${sousfiliere}.${soussousfiliere}`, JSON.stringify(response)); + return response; } } @@ -132,9 +144,9 @@ var search = { this.updateList(); } }, - template: (template, expressionTypes, bindingTypes, getComponent) => template('
', [{ - redundantAttribute: 'expr1400', - selector: '[expr1400]', + template: (template, expressionTypes, bindingTypes, getComponent) => template('
', [{ + redundantAttribute: 'expr626', + selector: '[expr626]', expressions: [{ type: expressionTypes.EVENT, name: 'onkeyup', @@ -145,8 +157,8 @@ var search = { evaluate: _scope => _scope.state.placeholder }] }, { - redundantAttribute: 'expr1401', - selector: '[expr1401]', + redundantAttribute: 'expr627', + selector: '[expr627]', expressions: [{ type: expressionTypes.ATTRIBUTE, name: 'disabled', @@ -160,9 +172,9 @@ var search = { type: bindingTypes.EACH, getKey: null, condition: null, - template: template('', [{ - redundantAttribute: 'expr1403', - selector: '[expr1403]', + template: template('', [{ + redundantAttribute: 'expr629', + selector: '[expr629]', expressions: [{ type: expressionTypes.ATTRIBUTE, name: 'disabled', @@ -173,24 +185,24 @@ var search = { evaluate: _scope => () => _scope.cruiseForward(_scope.item.name) }] }, { - redundantAttribute: 'expr1404', - selector: '[expr1404]', + redundantAttribute: 'expr630', + selector: '[expr630]', expressions: [{ type: expressionTypes.TEXT, childNodeIndex: 0, evaluate: _scope => _scope.item.name }] }, { - redundantAttribute: 'expr1405', - selector: '[expr1405]', + redundantAttribute: 'expr631', + selector: '[expr631]', expressions: [{ type: expressionTypes.TEXT, childNodeIndex: 0, evaluate: _scope => _scope.item.count }] }]), - redundantAttribute: 'expr1402', - selector: '[expr1402]', + redundantAttribute: 'expr628', + selector: '[expr628]', itemName: 'item', indexName: null, evaluate: _scope => _scope.state.items