From ea62bb9d3fe0a7b375596835778be9b20a8468c2 Mon Sep 17 00:00:00 2001 From: horville Date: Wed, 29 Mar 2023 16:50:48 +0200 Subject: [PATCH] search.riot refactor WIP --- components/school.riot | 25 +++--- components/search.riot | 59 ++++++++++---- javascript/fili-info.js | 14 ++-- javascript/main-controller.js | 18 ++--- javascript/school-info.js | 16 ++-- javascript/school.js | 33 ++++---- javascript/search.js | 143 ++++++++++------------------------ style/parcoursup.css | 5 +- 8 files changed, 144 insertions(+), 169 deletions(-) diff --git a/components/school.riot b/components/school.riot index 7e0a58f..7c4207b 100644 --- a/components/school.riot +++ b/components/school.riot @@ -1,11 +1,13 @@ -
-
- - - - -
+
+ +
+
+ + + + +
@@ -29,6 +31,7 @@ +
\ No newline at end of file diff --git a/javascript/fili-info.js b/javascript/fili-info.js index e7293de..c9408ee 100644 --- a/javascript/fili-info.js +++ b/javascript/fili-info.js @@ -1,30 +1,30 @@ var filiInfo = { css: null, exports: null, - template: (template, expressionTypes, bindingTypes, getComponent) => template('

BUT / BUT - Production / Informatique

Moyenne des admis19.3

Nombre de formations5

Capacité90

Sélectivité

', [{ + template: (template, expressionTypes, bindingTypes, getComponent) => template('

BUT / BUT - Production / Informatique

Moyenne des admis19.3

Nombre de formations5

Capacité90

Sélectivité

', [{ type: bindingTypes.TAG, getComponent: getComponent, evaluate: _scope => 'line-graph', slots: [], attributes: [], - redundantAttribute: 'expr9', - selector: '[expr9]' + redundantAttribute: 'expr4', + selector: '[expr4]' }, { type: bindingTypes.TAG, getComponent: getComponent, evaluate: _scope => 'line-graph', slots: [], attributes: [], - redundantAttribute: 'expr10', - selector: '[expr10]' + redundantAttribute: 'expr5', + selector: '[expr5]' }, { type: bindingTypes.TAG, getComponent: getComponent, evaluate: _scope => 'line-graph', slots: [], attributes: [], - redundantAttribute: 'expr11', - selector: '[expr11]' + redundantAttribute: 'expr6', + selector: '[expr6]' }]), name: 'fili-info' }; diff --git a/javascript/main-controller.js b/javascript/main-controller.js index 38ac6db..ee01884 100644 --- a/javascript/main-controller.js +++ b/javascript/main-controller.js @@ -1,38 +1,38 @@ var mainController = { css: null, exports: {}, - template: (template, expressionTypes, bindingTypes, getComponent) => template('
', [{ + template: (template, expressionTypes, bindingTypes, getComponent) => template('
', [{ type: bindingTypes.TAG, getComponent: getComponent, evaluate: _scope => 'search', slots: [], attributes: [], - redundantAttribute: 'expr12', - selector: '[expr12]' + redundantAttribute: 'expr0', + selector: '[expr0]' }, { type: bindingTypes.TAG, getComponent: getComponent, evaluate: _scope => 'fili-info', slots: [], attributes: [], - redundantAttribute: 'expr13', - selector: '[expr13]' + redundantAttribute: 'expr1', + selector: '[expr1]' }, { type: bindingTypes.TAG, getComponent: getComponent, evaluate: _scope => 'school', slots: [], attributes: [], - redundantAttribute: 'expr14', - selector: '[expr14]' + redundantAttribute: 'expr2', + selector: '[expr2]' }, { type: bindingTypes.TAG, getComponent: getComponent, evaluate: _scope => 'school-info', slots: [], attributes: [], - redundantAttribute: 'expr15', - selector: '[expr15]' + redundantAttribute: 'expr3', + selector: '[expr3]' }]), name: 'main-controller' }; diff --git a/javascript/school-info.js b/javascript/school-info.js index 8673e4e..1bdb901 100644 --- a/javascript/school-info.js +++ b/javascript/school-info.js @@ -10,14 +10,14 @@ var schoolInfo = { this.update(); } }, - template: (template, expressionTypes, bindingTypes, getComponent) => template('
', [{ + template: (template, expressionTypes, bindingTypes, getComponent) => template('
', [{ type: bindingTypes.IF, evaluate: _scope => _scope.state.enabled, - redundantAttribute: 'expr0', - selector: '[expr0]', - template: template('

', [{ - redundantAttribute: 'expr1', - selector: '[expr1]', + redundantAttribute: 'expr7', + selector: '[expr7]', + template: template('

', [{ + redundantAttribute: 'expr8', + selector: '[expr8]', expressions: [{ type: expressionTypes.EVENT, name: 'onclick', @@ -29,8 +29,8 @@ var schoolInfo = { evaluate: _scope => 'line-graph', slots: [], attributes: [], - redundantAttribute: 'expr2', - selector: '[expr2]' + redundantAttribute: 'expr9', + selector: '[expr9]' }]) }]), name: 'school-info' diff --git a/javascript/school.js b/javascript/school.js index 54018b8..04c19b0 100644 --- a/javascript/school.js +++ b/javascript/school.js @@ -55,7 +55,10 @@ var school = { let pct_B = etablissement.fields.pct_b; let pct_TB = etablissement.fields.pct_tb; let pct_TBF = etablissement.fields.pct_tbf; - let moyenne = (pct_TBF * 18 + pct_TB * 16 + pct_B * 14 + pct_AB * 12 + pct_sansmention * 10) / 100; + + // On prend la moyenne des moyennes comprises dans la mention + // Exemple : Assez bien est entre 12 et 14 donc 13. + let moyenne = (pct_TBF * 19 + pct_TB * 17 + pct_B * 15 + pct_AB * 13 + pct_sansmention * 11) / 100; etablissement.fields.moyenne = moyenne; console.log(etablissement.fields); }); @@ -64,53 +67,53 @@ var school = { } }; }, - template: (template, expressionTypes, bindingTypes, getComponent) => template('
NomVilleDptMoyenneSélectivité
', [{ + template: (template, expressionTypes, bindingTypes, getComponent) => template('

NomVilleDptMoyenneSélectivité
', [{ type: bindingTypes.EACH, getKey: null, condition: null, - template: template(' ', [{ - redundantAttribute: 'expr59', - selector: '[expr59]', + template: template(' ', [{ + redundantAttribute: 'expr35', + selector: '[expr35]', expressions: [{ type: expressionTypes.TEXT, childNodeIndex: 0, evaluate: _scope => _scope.etablissement.fields.g_ea_lib_vx }] }, { - redundantAttribute: 'expr60', - selector: '[expr60]', + redundantAttribute: 'expr36', + selector: '[expr36]', expressions: [{ type: expressionTypes.TEXT, childNodeIndex: 0, evaluate: _scope => _scope.etablissement.fields.ville_etab }] }, { - redundantAttribute: 'expr61', - selector: '[expr61]', + redundantAttribute: 'expr37', + selector: '[expr37]', expressions: [{ type: expressionTypes.TEXT, childNodeIndex: 0, evaluate: _scope => _scope.etablissement.fields.dep }] }, { - redundantAttribute: 'expr62', - selector: '[expr62]', + redundantAttribute: 'expr38', + selector: '[expr38]', expressions: [{ type: expressionTypes.TEXT, childNodeIndex: 0, evaluate: _scope => _scope.etablissement.fields.moyenne }] }, { - redundantAttribute: 'expr63', - selector: '[expr63]', + redundantAttribute: 'expr39', + selector: '[expr39]', expressions: [{ type: expressionTypes.TEXT, childNodeIndex: 0, evaluate: _scope => _scope.etablissement.fields.taux_acces_ens }] }]), - redundantAttribute: 'expr58', - selector: '[expr58]', + redundantAttribute: 'expr34', + selector: '[expr34]', itemName: 'etablissement', indexName: null, evaluate: _scope => _scope.state.items diff --git a/javascript/search.js b/javascript/search.js index ce6e5e1..15efa6f 100644 --- a/javascript/search.js +++ b/javascript/search.js @@ -29,147 +29,86 @@ class PAPI { } } -async function fetchFiliere(state) { - if (state.sousfili) { - return PAPI.fetchSpecialites(state.sousfili); - //var request = await fetch(`${searchURL}&rows=0&sort=tri&facet=fil_lib_voe_acc&refine.form_lib_voe_acc=${state.sousfili}`) - } else if (state.fili && !state.sousfili) { - return PAPI.fetchFiliere(state.fili); - //var request = await fetch(`${searchURL}&rows=0&sort=tri&facet=form_lib_voe_acc&refine.fili=${state.fili}`) - } else if (!state.fili && !state.sousfili) { - return PAPI.fetchFilieres(); - //var request = await fetch(`${searchURL}&rows=0&sort=tri&facet=fili`) - } - - //let result = await request.json() - //return result["facet_groups"][0]["facets"] -} - +function filterSearch() {} var search = { css: null, - exports: function search() { - return { - onBeforeMount(props, state) { - // initial state - this.state = { - placeholder: "Formation", - items: null, - allitems: null, - fili: null, - sousfili: null - }; - fetchFiliere(this.state).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); - } - }); + exports: { + onBeforeMount(props, state) { + //Initial state + this.state = { + placeholder: "Formation", + currentStep: 0, + allItems: null, + filter: null, + items: null + }; + PAPI.fetchFilieres().then(response => { + this.state.allItems = response; this.update({ - items: responseFiltered + items: filterSearch(this.state.allItems) }); - }, - filter(fili) { - console.log("filter! " + fili); - if (this.state.placeholder === "Filière de formation") { - this.update({ - placeholder: "Filière de formation détaillée", - sousfili: fili - }); - } else if (this.state.placeholder = "Formation") { - this.update({ - placeholder: "Filière de formation", - fili: fili - }); - } - fetchFiliere(this.state).then(response => { - this.update({ - allitems: response, - items: response - }); - console.log(this.state.items); - }); - }, - back() { - console.log("back"); - if (this.state.placeholder === "Filière de formation") { - this.update({ - placeholder: "Formation", - fili: null - }); - } 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 - }); - }); - } - }; + }); + } }, - template: (template, expressionTypes, bindingTypes, getComponent) => template('
', [{ - redundantAttribute: 'expr16', - selector: '[expr16]', + template: (template, expressionTypes, bindingTypes, getComponent) => template('
', [{ + redundantAttribute: 'expr10', + selector: '[expr10]', expressions: [{ type: expressionTypes.EVENT, name: 'onkeydown', - evaluate: _scope => _scope.searchF + evaluate: _scope => _scope.filterSearch + }, { + type: expressionTypes.EVENT, + name: 'onfocusout', + evaluate: _scope => _scope.filterSearch }, { type: expressionTypes.ATTRIBUTE, name: 'placeholder', evaluate: _scope => _scope.state.placeholder }] }, { - redundantAttribute: 'expr17', - selector: '[expr17]', + redundantAttribute: 'expr11', + selector: '[expr11]', expressions: [{ + type: expressionTypes.ATTRIBUTE, + name: 'disabled', + evaluate: _scope => !_scope.state.currentStep + }, { type: expressionTypes.EVENT, name: 'onclick', - evaluate: _scope => _scope.back + evaluate: _scope => _scope.cruiseBack }] }, { type: bindingTypes.EACH, getKey: null, condition: null, - template: template('', [{ - redundantAttribute: 'expr19', - selector: '[expr19]', + template: template('', [{ + redundantAttribute: 'expr13', + selector: '[expr13]', expressions: [{ type: expressionTypes.EVENT, name: 'onclick', - evaluate: _scope => () => _scope.filter(_scope.item.name) + evaluate: _scope => () => _scope.cruiseForward(_scope.item.name) }] }, { - redundantAttribute: 'expr20', - selector: '[expr20]', + redundantAttribute: 'expr14', + selector: '[expr14]', expressions: [{ type: expressionTypes.TEXT, childNodeIndex: 0, evaluate: _scope => _scope.item.name }] }, { - redundantAttribute: 'expr21', - selector: '[expr21]', + redundantAttribute: 'expr15', + selector: '[expr15]', expressions: [{ type: expressionTypes.TEXT, childNodeIndex: 0, evaluate: _scope => _scope.item.count }] }]), - redundantAttribute: 'expr18', - selector: '[expr18]', + redundantAttribute: 'expr12', + selector: '[expr12]', itemName: 'item', indexName: null, evaluate: _scope => _scope.state.items diff --git a/style/parcoursup.css b/style/parcoursup.css index 1bdae61..9047354 100644 --- a/style/parcoursup.css +++ b/style/parcoursup.css @@ -1,6 +1,7 @@ body, html { - width: 100%; - height: 100%; + width: 100vw; + height: 100vh; + min-height: 100vh; top: 0px; left: 0px; background-color: #EFEFEF;