$
This commit is contained in:
@@ -4,7 +4,7 @@ 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",
|
||||
link: "https://data.enseignementsup-recherche.gouv.fr/api/records/1.0/search/?dataset=fr-esr-parcoursup&q=&lang=fr&sort=tri",
|
||||
facet: {
|
||||
filiaire: "fili",
|
||||
formation: "form_lib_voe_acc",
|
||||
@@ -15,6 +15,7 @@ export default class Model {
|
||||
curIndex: 0, /* section n.0 -> n.2. */
|
||||
cat: null,
|
||||
scat: null,
|
||||
tcat: null,
|
||||
path: ["", "", ""],
|
||||
name: [
|
||||
"formation",
|
||||
@@ -75,6 +76,21 @@ export default class Model {
|
||||
this.state.page.scat = val
|
||||
}
|
||||
|
||||
/**
|
||||
* Recuperer la valeur de TCat
|
||||
* @return { string | null }
|
||||
* */
|
||||
getTCat() {
|
||||
return this.state.page.tcat
|
||||
}
|
||||
|
||||
/**
|
||||
* @param { string } val la valeur du refine "fil_lib_voe_acc"
|
||||
* */
|
||||
setTCat(val) {
|
||||
this.state.page.tcat = val
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne le chemin filiaires - formations - formations detaillees
|
||||
* @return { array[] } Le chemin.
|
||||
@@ -98,7 +114,7 @@ export default class Model {
|
||||
* */
|
||||
getModelData0() {
|
||||
if(!localStorage.getItem(`sec0`)) {
|
||||
const link = `${ this.state.api.link }` +
|
||||
const link = `${ this.state.api.link }&rows=0` +
|
||||
`&facet=${this.state.api.facet.filiaire}`
|
||||
|
||||
return fetch(link)
|
||||
@@ -124,7 +140,7 @@ export default class Model {
|
||||
* */
|
||||
getModelData1() {
|
||||
if(!localStorage.getItem(`sec1-${this.state.page.cat}`)) {
|
||||
const link = `${this.state.api.link}` +
|
||||
const link = `${this.state.api.link}&rows=0` +
|
||||
`&facet=${this.state.api.facet.filiaire}` +
|
||||
`&facet=${this.state.api.facet.formation}` +
|
||||
`&facet=${this.state.api.facet.spec}` +
|
||||
@@ -154,13 +170,12 @@ export default class Model {
|
||||
* */
|
||||
getModelData2() {
|
||||
if(!localStorage.getItem(`sec2-${this.state.page.cat}-${this.state.page.scat}`)) {
|
||||
const link = `${this.state.api.link}` +
|
||||
const link = `${this.state.api.link}&rows=0` +
|
||||
`&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}` +
|
||||
`&refine.${this.state.api.facet.formation}=${this.state.page.scat}`
|
||||
console.log(link)
|
||||
|
||||
return fetch(link)
|
||||
.then((res) => res.json())
|
||||
@@ -178,4 +193,41 @@ export default class Model {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne la liste d'etablissement
|
||||
* @return { json } les donnees demandees en JSON
|
||||
* */
|
||||
getModelData3() {
|
||||
if(!localStorage.getItem(`sec-etab-${this.state.page.cat}-${this.state.page.scat}-${this.state.page.tcat}`)) {
|
||||
const link = `${this.state.api.link}&rows=100` +
|
||||
`&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}` +
|
||||
`&refine.${this.state.api.facet.formation}=${this.state.page.scat}` +
|
||||
`&refine.${this.state.api.facet.spec}=${this.state.page.tcat}`
|
||||
|
||||
console.log(link)
|
||||
|
||||
return fetch(link)
|
||||
.then((res) => {
|
||||
|
||||
console.log(res)
|
||||
return res.json()
|
||||
})
|
||||
.then((data) => {
|
||||
try {
|
||||
if(data) {
|
||||
localStorage.setItem(`sec-etab-${this.state.page.cat}-${this.state.page.scat}-${this.state.page.tcat}`, JSON.stringify(data.records))
|
||||
return data.records
|
||||
}
|
||||
} catch(donothing) {}
|
||||
})
|
||||
} else {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(JSON.parse(localStorage.getItem(`sec-etab-${this.state.page.cat}-${this.state.page.scat}-${this.state.page.tcat}`)))
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user