This commit is contained in:
pro.boooooo 2023-03-09 14:41:05 +01:00
parent 563864e461
commit 2b1132fdf9
4 changed files with 40 additions and 59 deletions

View File

@ -8,27 +8,26 @@ export default class Controller {
constructor(model, view) { constructor(model, view) {
this.model = model this.model = model
this.view = view this.view = view
this.toload = 0
this.getData(0).then() this.getData(0).then()
/** /**
* Envoyer dans le controlleur tous les events fait. * Envoyer dans le controlleur tous les events fait.
* @param { {name: string, count: int} } selection Ce qu'on va utiliser pour le &refine. * @param { string } selection Ce qu'on va utiliser pour le &refine.
* @param { string } action Retour en arriere ou aller en avant. { "previous", "next" }. * @param { string } action Retour en arriere ou aller en avant. { "previous", "next" }.
* */ * */
window.updateModel = (selection, action) => { window.updateModel = (selection, action) => {
if(this.model.getCurIndex() === 0) { if(this.model.getCurIndex() === 0) {
log("Selector->Controller", "Ajout d'une section pour refine fili") log("Selector->Controller", "Ajout d'une section pour refine fili")
this.model.setCat(selection.name) this.model.setCat(selection)
} else if(this.model.getCurIndex() === 1) { } else if(this.model.getCurIndex() === 1) {
log("Selector->Controller", "Ajout d'une section pour refine form_lib_voe_acc") log("Selector->Controller", "Ajout d'une section pour refine form_lib_voe_acc")
this.model.setSCat(selection.name) this.model.setSCat(selection)
} else if(this.model.getCurIndex() === 2) { } else if(this.model.getCurIndex() === 2) {
log("Selector->Controller", "Ajout d'une section pour refine fil_lib_voe_acc") log("Selector->Controller", "Ajout d'une section pour refine fil_lib_voe_acc")
this.model.setTCat(selection.name) this.model.setTCat(selection)
} }
this.model.setPath(this.model.getCurIndex(), selection.name) this.model.setPath(this.model.getCurIndex(), selection)
if(action === "next") { if(action === "next") {
this.model.nextPage() this.model.nextPage()
@ -38,8 +37,7 @@ export default class Controller {
log("Selector->Controller", "Action inconnue au bataillon (updateModel)") log("Selector->Controller", "Action inconnue au bataillon (updateModel)")
} }
if(this.model.getTCat()) { if(this.model.getTCat() != null) {
this.toload = selection.count
this.getData(3).then() this.getData(3).then()
} else { } else {
this.getData(this.model.getCurIndex()).then() this.getData(this.model.getCurIndex()).then()
@ -71,7 +69,7 @@ export default class Controller {
}) })
} else if(n === 3) { } else if(n === 3) {
log("Selector->Controller", "Requete de la liste des etablissements") log("Selector->Controller", "Requete de la liste des etablissements")
this.model.getModelData3(this.toload).then((res) => { this.model.getModelData3().then((res) => {
this.view.renderEtab(res) this.view.renderEtab(res)
}) })
} else { } else {

View File

@ -195,13 +195,12 @@ export default class Model {
} }
/** /**
* Retourne la liste d'etablissement. * Retourne la liste d'etablissement
* @param { int } howMany Combien d'etablissement il y a * @return { json } les donnees demandees en JSON
* @return { json } Les donnees demandees en JSON.
* */ * */
getModelData3(howMany) { getModelData3() {
if(!localStorage.getItem(`sec-etab-${this.state.page.cat}-${this.state.page.scat}-${this.state.page.tcat}`)) { if(!localStorage.getItem(`sec-etab-${this.state.page.cat}-${this.state.page.scat}-${this.state.page.tcat}`)) {
const link = `${this.state.api.link}&rows=${howMany}` + const link = `${this.state.api.link}&rows=10000` +
`&facet=${this.state.api.facet.filiaire}` + `&facet=${this.state.api.facet.filiaire}` +
`&facet=${this.state.api.facet.formation}` + `&facet=${this.state.api.facet.formation}` +
`&facet=${this.state.api.facet.spec}` + `&facet=${this.state.api.facet.spec}` +
@ -209,6 +208,8 @@ export default class Model {
`&refine.${this.state.api.facet.formation}=${this.state.page.scat}` + `&refine.${this.state.api.facet.formation}=${this.state.page.scat}` +
`&refine.${this.state.api.facet.spec}=${this.state.page.tcat}` `&refine.${this.state.api.facet.spec}=${this.state.page.tcat}`
console.log(link)
return fetch(link) return fetch(link)
.then((res) => { .then((res) => {
return res.json() return res.json()
@ -217,6 +218,7 @@ export default class Model {
try { try {
if(data) { if(data) {
localStorage.setItem(`sec-etab-${this.state.page.cat}-${this.state.page.scat}-${this.state.page.tcat}`, JSON.stringify(data.records)) localStorage.setItem(`sec-etab-${this.state.page.cat}-${this.state.page.scat}-${this.state.page.tcat}`, JSON.stringify(data.records))
this.state.page.tcat = null
return data.records return data.records
} }
} catch(donothing) {} } catch(donothing) {}
@ -224,6 +226,7 @@ export default class Model {
} else { } else {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
resolve(JSON.parse(localStorage.getItem(`sec-etab-${this.state.page.cat}-${this.state.page.scat}-${this.state.page.tcat}`))) resolve(JSON.parse(localStorage.getItem(`sec-etab-${this.state.page.cat}-${this.state.page.scat}-${this.state.page.tcat}`)))
this.state.page.tcat = null
}) })
} }
} }

View File

@ -8,7 +8,7 @@ export default class View {
this.etab = document.getElementById("etab") this.etab = document.getElementById("etab")
this.btn = document.getElementById("selector-top-btn") this.btn = document.getElementById("selector-top-btn")
this.btn.onclick = () => { this.btn.onclick = () => {
this.updateMenu({name: " ", count: 0}, "previous") this.updateMenu(" ", "previous")
} }
log("Selector", "View 1/3") log("Selector", "View 1/3")
@ -32,13 +32,7 @@ export default class View {
let li = document.createElement("li") let li = document.createElement("li")
li.className = "selector-list-inner" li.className = "selector-list-inner"
li.onclick = () => { li.onclick = () => {
this.updateMenu( this.updateMenu(document.getElementById(`menu0-${e.name}`).innerText, "next")
{
name: document.getElementById(`menu0-${e.name}`).innerText,
count: parseInt(document.getElementById(`menu0-${e.name}-count`).innerText)
},
"next"
)
} }
let name = document.createElement("a") let name = document.createElement("a")
@ -48,7 +42,6 @@ export default class View {
let count = document.createElement("span") let count = document.createElement("span")
count.innerText = e.count count.innerText = e.count
count.id = `menu0-${e.name}-count`
count.className = "selector-list-counts" count.className = "selector-list-counts"
li.appendChild(name) li.appendChild(name)
@ -63,7 +56,7 @@ export default class View {
/** /**
* Pour afficher en haut a gauche le chemin courant. * Pour afficher en haut a gauche le chemin courant.
* @param { array[] } path Chemin courant. * @param { string[] } path Chemin courant.
* */ * */
renderPath(path) { renderPath(path) {
this.path.innerText = `${path[0]} / ${path[1]} / ${path[2]}` this.path.innerText = `${path[0]} / ${path[1]} / ${path[2]}`
@ -75,32 +68,14 @@ export default class View {
* @param { json } data La liste des etablissements. * @param { json } data La liste des etablissements.
* */ * */
renderEtab(data) { renderEtab(data) {
this.etab.innerHTML = "" this.etab.innerHTML =
let table = document.createElement("table") "<tr>" +
let trow = document.createElement("tr") " <th>Nom</th>" +
" <th>Ville</th>" +
let th1 = document.createElement("th") " <th>Dept</th>" +
th1.innerText = "Nom" " <th>Moyenne</th>" +
" <th>Selectivite</th>" +
let th2 = document.createElement("th") "</tr>"
th2.innerText = "Ville"
let th3 = document.createElement("th")
th3.innerText = "Dpt"
let th4 = document.createElement("th")
th4.innerText = "Moyenne"
let th5 = document.createElement("th")
th5.innerText = "Selectivite"
trow.appendChild(th1)
trow.appendChild(th2)
trow.appendChild(th3)
trow.appendChild(th4)
trow.appendChild(th5)
table.appendChild(trow)
data.forEach((e) => { data.forEach((e) => {
let etab = e.fields.g_ea_lib_vx let etab = e.fields.g_ea_lib_vx
@ -132,15 +107,13 @@ export default class View {
tr.appendChild(td4) tr.appendChild(td4)
tr.appendChild(td5) tr.appendChild(td5)
table.appendChild(tr) this.etab.appendChild(tr)
}) })
this.etab.appendChild(table)
} }
/** /**
* Envoyer dans le controlleur tous les events fait. * Envoyer dans le controlleur tous les events fait.
* @param { {name: string, count: int} } selection Ce qu'on va utiliser pour le &refine. * @param { string } selection Ce qu'on va utiliser pour le &refine.
* @param { string } direction Retour en arriere ou aller en avant. { "previous", "next" } * @param { string } direction Retour en arriere ou aller en avant. { "previous", "next" }
* */ * */
updateMenu(selection, direction) { updateMenu(selection, direction) {

View File

@ -9,8 +9,7 @@
} }
etablanalytics etablanalytics
#etab #etab {
table {
font-size: 17px; font-size: 17px;
color: white; color: white;
font-weight: bold; font-weight: bold;
@ -20,7 +19,6 @@
etablanalytics etablanalytics
#etab #etab
table
tr tr
th { th {
background: #344D59; background: #344D59;
@ -32,7 +30,6 @@
etablanalytics etablanalytics
#etab #etab
table
tr tr
td { td {
text-align: center; text-align: center;
@ -41,5 +38,15 @@
} }
</style> </style>
<div id="etab"></div> <div>
<table id="etab">
<tr>
<th>Nom</th>
<th>Ville</th>
<th>Dept</th>
<th>Moyenne</th>
<th>Selectivite</th>
</tr>
</table>
</div>
</etablanalytics> </etablanalytics>