This commit is contained in:
pro.boooooo 2023-03-08 23:57:59 +01:00
parent 4cbf6418ce
commit 607729c848
2 changed files with 18 additions and 6 deletions

View File

@ -16,8 +16,11 @@ export default class Controller {
* */ * */
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") log("Selector->Controller", "Ajout d'une section pour refine fili")
this.model.setCat(selection) this.model.setCat(selection)
} else if(this.model.getCurIndex() === 1) {
log("Selector->Controller", "Ajout d'une section pour refine form_lib_voe_acc")
this.model.setSCat(selection)
} }
if(action === "next") { if(action === "next") {

View File

@ -14,6 +14,7 @@ export default class Model {
page: { page: {
curIndex: 0, /* section n.0 -> n.2. */ curIndex: 0, /* section n.0 -> n.2. */
cat: null, cat: null,
scat: null,
path: ["", "", ""], path: ["", "", ""],
name: [ name: [
"formation", "formation",
@ -53,12 +54,19 @@ export default class Model {
} }
/** /**
* @param v La valeur du refine * @param v La valeur du refine "fili"
* */ * */
setCat(v) { setCat(v) {
this.state.page.cat = v this.state.page.cat = v
} }
/**
* @param v la valeur du refine "form_lib_voe_acc"
* */
setSCat(v) {
this.state.page.scat = v
}
/** /**
* Retourne la section 0 + l'enregistre dans le local storage * Retourne la section 0 + l'enregistre dans le local storage
* @return les donnees demandees en JSON * @return les donnees demandees en JSON
@ -119,18 +127,19 @@ export default class Model {
* @return les donnees demandees en JSON * @return les donnees demandees en JSON
* */ * */
getModelData2() { getModelData2() {
if(!localStorage.getItem(`sec2-${this.state.page.cat}`)) { if(!localStorage.getItem(`sec2-${this.state.page.cat}-${this.state.page.scat}`)) {
const link = `${this.state.api.link}` + const link = `${this.state.api.link}` +
`&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}` +
`&refine.${this.state.api.facet.filiaire}=${this.state.page.cat}` `&refine.${this.state.api.facet.filiaire}=${this.state.page.cat}` +
`&refine.${this.state.api.facet.formation}=${this.state.page.scat}`
return fetch(link) return fetch(link)
.then((res) => res.json()) .then((res) => res.json())
.then((data) => { .then((data) => {
if(data) { if(data) {
localStorage.setItem(`sec2-${this.state.page.cat}`, JSON.stringify(data.facet_groups[2].facets)) localStorage.setItem(`sec2-${this.state.page.cat}-${this.state.page.scat}`, JSON.stringify(data.facet_groups[2].facets))
return data.facet_groups[2].facets return data.facet_groups[2].facets
} else { } else {
return null return null
@ -138,7 +147,7 @@ export default class Model {
}) })
} else { } else {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
resolve(JSON.parse(localStorage.getItem(`sec2-${this.state.page.cat}`))) resolve(JSON.parse(localStorage.getItem(`sec2-${this.state.page.cat}-${this.state.page.scat}`)))
}) })
} }
} }