diff --git a/src/components/global/generalytics/generalytics.riot b/src/components/global/generalytics/generalytics.riot index 5dc56f7..b47d4f6 100644 --- a/src/components/global/generalytics/generalytics.riot +++ b/src/components/global/generalytics/generalytics.riot @@ -322,7 +322,7 @@ 20% (Gen.) 30% (Tech.) 25% (Pro.) - 25% (Aut.) + 0% (Aut.)
diff --git a/src/components/global/selector/api/Controller.js b/src/components/global/selector/api/Controller.js new file mode 100644 index 0000000..d831dda --- /dev/null +++ b/src/components/global/selector/api/Controller.js @@ -0,0 +1,46 @@ +import log from "./log"; + +export default class Controller { + constructor(model, view) { + this.model = model + this.view = view + window.updateModel = (selection, action) => { + if(this.model.getCurIndex() === 0) { + log("Selector->Controller", "Ajout d'une section pour refine") + this.model.setCat(selection) + } + + if(action === "next") { + this.model.nextPage() + } else if(action === "previous") { + this.model.previousPage() + } else { + log("Selector->Controller", "Action inconnue au bataillon (updateModel)") + } + + this.getData(this.model.getCurIndex()).then() + } + + log("Selector", "Controller 3/3") + this.getData(0).then() + } + + async getData(n) { + if(n === 0) { + log("Selector->Controller", "Requete Section 0") + this.model.getModelData0().then((res) => { + this.view.renderMenu(res) + }) + } else if(n === 1) { + log("Selector->Controller", "Requete Section 1") + this.model.getModelData1().then((res) => { + this.view.renderMenu(res) + }) + } else if(n === 2) { + log("Selector->Controller", "Requete Section 2") + this.model.getModelData2().then((res) => { + this.view.renderMenu(res) + }) + } + } +} \ No newline at end of file diff --git a/src/components/global/selector/api/Model.js b/src/components/global/selector/api/Model.js new file mode 100644 index 0000000..8d0082b --- /dev/null +++ b/src/components/global/selector/api/Model.js @@ -0,0 +1,120 @@ +import log from "./log" + +export default class Model { + constructor() { + this.state = { + api: { + link: "https://data.enseignementsup-recherche.gouv.fr/api/records/1.0/search/?dataset=fr-esr-parcoursup&q=&lang=fr&rows=0&sort=tri", + facet: { + filiaire: "fili", + formation: "form_lib_voe_acc", + spec: "fil_lib_voe_acc" + } + }, + page: { + curIndex: 0, /* section n.0 -> n.2. */ + cat: null, + path: ["", "", ""], + name: [ + "formation", + "filière de formation", + "filière de formation détaillée" + ], + } + } + + log("Selector", "Model 2/3") + } + + getCurIndex() { + return this.state.page.curIndex + } + + nextPage() { + if(this.state.page.curIndex+1 <= 2) { + this.state.page.curIndex++ + } + } + + previousPage() { + if(this.state.page.curIndex-1 >= 0) { + this.state.page.curIndex-- + } + } + + setCat(v) { + this.state.page.cat = v + } + + getModelData0() { + if(!localStorage.getItem(`sec0`)) { + const link = `${ this.state.api.link }` + + `&facet=${this.state.api.facet.filiaire}` + + return fetch(link) + .then((res) => res.json()) + .then((data) => { + if(data) { + localStorage.setItem(`sec0`, JSON.stringify(data.facet_groups[0].facets)) + return data.facet_groups[0].facets + } else { + return null + } + }) + } else { + return new Promise((resolve, reject) => { + resolve(JSON.parse(localStorage.getItem(`sec0`))) + }) + } + } + + getModelData1() { + if(!localStorage.getItem(`sec1-${this.state.page.cat}`)) { + const link = `${this.state.api.link}` + + `&facet=${this.state.api.facet.filiaire}` + + `&facet=${this.state.api.facet.formation}` + + `&facet=${this.state.api.facet.spec}` + + `&refine.${this.state.api.facet.filiaire}=${this.state.page.cat}` + + return fetch(link) + .then((res) => res.json()) + .then((data) => { + if(data) { + localStorage.setItem(`sec1-${this.state.page.cat}`, JSON.stringify(data.facet_groups[1].facets)) + return data.facet_groups[1].facets + } else { + return null + } + }) + } else { + return new Promise((resolve, reject) => { + resolve(JSON.parse(localStorage.getItem(`sec1-${this.state.page.cat}`))) + }) + } + } + + getModelData2() { + if(!localStorage.getItem(`sec2-${this.state.page.cat}`)) { + const link = `${this.state.api.link}` + + `&facet=${this.state.api.facet.filiaire}` + + `&facet=${this.state.api.facet.formation}` + + `&facet=${this.state.api.facet.spec}` + + `&refine.${this.state.api.facet.filiaire}=${this.state.page.cat}` + + return fetch(link) + .then((res) => res.json()) + .then((data) => { + if(data) { + localStorage.setItem(`sec2-${this.state.page.cat}`, JSON.stringify(data.facet_groups[2].facets)) + return data.facet_groups[2].facets + } else { + return null + } + }) + } else { + return new Promise((resolve, reject) => { + resolve(JSON.parse(localStorage.getItem(`sec2-${this.state.page.cat}`))) + }) + } + } +} \ No newline at end of file diff --git a/src/components/global/selector/api/View.js b/src/components/global/selector/api/View.js new file mode 100644 index 0000000..47256f7 --- /dev/null +++ b/src/components/global/selector/api/View.js @@ -0,0 +1,48 @@ +import log from "./log"; + +export default class View { + constructor() { + this.zone = document.getElementById("selector-list-zone") + this.btn = document.getElementById("selector-top-btn") + this.btn.onclick = () => { + this.updateMenu("", "previous") + } + + log("Selector", "View 1/3") + } + + renderMenu(data) { + this.zone.innerHTML = "" + + data.forEach((e) => { + let li = document.createElement("li") + li.className = "selector-list-inner" + li.onclick = () => { + this.updateMenu(document.getElementById(`menu0-${e.name}`).innerText, "next") + } + + let name = document.createElement("a") + name.innerText = e.name + name.id = `menu0-${e.name}` + name.className = "selector-list-names" + + let count = document.createElement("span") + count.innerText = e.count + count.className = "selector-list-counts" + + li.appendChild(name) + li.appendChild(count) + this.zone.appendChild(li) + }) + + log("Selector->View", "Donnees recuperer OK !") + } + + updateMenu(selection, direction) { + if(direction) { + window.updateModel(selection, direction) + } else { + log("Selector->View", "Mince, le menu ne veut pas s'ouvrir :(") + } + } +} \ No newline at end of file diff --git a/src/components/global/selector/api/log.js b/src/components/global/selector/api/log.js new file mode 100644 index 0000000..451ce42 --- /dev/null +++ b/src/components/global/selector/api/log.js @@ -0,0 +1,3 @@ +export default function log(mvc, msg) { + console.log(`${ mvc }:: ${ msg }`) +} \ No newline at end of file diff --git a/src/components/global/selector/api/selector.spec.js b/src/components/global/selector/api/selector.spec.js new file mode 100644 index 0000000..67d6652 --- /dev/null +++ b/src/components/global/selector/api/selector.spec.js @@ -0,0 +1,9 @@ +import Controller from "./Controller.js" +import View from "./View.js" +import Model from "./Model.js" + +export default function start() { + const view = new View() + const model = new Model() + new Controller(model, view) +} \ No newline at end of file diff --git a/src/components/global/selector/selector.riot b/src/components/global/selector/selector.riot index f4b00a7..f7af0cd 100644 --- a/src/components/global/selector/selector.riot +++ b/src/components/global/selector/selector.riot @@ -56,7 +56,7 @@ #selector #selector-list-container - .selector-list + #selector-list-zone .selector-list-inner { display: flex; flex-direction: row; @@ -67,7 +67,8 @@ #selector #selector-list-container - .selector-list + #selector-list-zone + .selector-list-inner .selector-list-names { text-decoration: none; color: white; @@ -77,7 +78,8 @@ #selector #selector-list-container - .selector-list + #selector-list-zone + .selector-list-inner .selector-list-names:hover { background: #344D59; cursor: pointer; @@ -87,7 +89,8 @@ #selector #selector-list-container - .selector-list + #selector-list-zone + .selector-list-inner .selector-list-counts { color: white; background: green; @@ -98,218 +101,31 @@ } - - - - Chargement des données...
-
- -
+
- { this.state.page.name[this.state.page.curIndex] } + blabal
- - - - -
+ + \ No newline at end of file