This commit is contained in:
lalBi94 2023-03-05 15:00:07 +01:00
parent 7bc56c09b5
commit c98509523e

View File

@ -2,7 +2,7 @@
<style>
#selector {
width: 300px;
min-height: 700px;
min-height: 625px;
padding: 15px;
box-shadow: 0px 0px 3px 1px black;
}
@ -53,6 +53,8 @@
#selector-list-container
#selector-list
.selector-list-names {
text-decoration: none;
color: black;
padding-left: 18px;
}
@ -70,54 +72,74 @@
</style>
<script>
const api = "https://data.enseignementsup-recherche.gouv.fr/api/records/1.0/search/?dataset=fr-esr-parcoursup&q=&sort=tri&facet=fili&timezone=Europe%2FBerlin"
let data = []
export default {
async getData() {
let data = []
await fetch(api)
.then((res) => res.json())
.then((d) => {
data = d.facet_groups[0].facets
})
this.state = {
page: {
curIndex: 0,
"name": [
"formation",
"filère de formation",
"filière de formation détaillée"
]
},
data: data
}
console.log(this.state)
state: {
page: {
curIndex: 0,
cat: null,
name: [
"formation",
"filière de formation",
"filière de formation détaillée"
],
},
data: null
},
previousPage(){
try {
if(this.state.page.curIndex-1 >= 0) {
this.update({ curIndex: this.state.page.curIndex-- });
}
console.log(this.state.page.curIndex)
} catch(e) {
console.error(e)
}
},
nextPage() {
try {
if(this.state.page.curIndex+1 <= 2 ) {
this.update({ curIndex: this.state.page.curIndex++ });
}
console.log(this.state.page.curIndex)
} catch(e) {
console.error(e)
}
},
async getData() {
try {
const api = "https://data.enseignementsup-recherche.gouv.fr/api/records/1.0/search/?dataset=fr-esr-parcoursup&q=&sort=tri&facet=fili&timezone=Europe%2FBerlin";
const response = await fetch(api);
const data = await response.json();
this.update({ data: data.facet_groups[0].facets });
} catch (e) {
console.error(e);
}
},
onBeforeMount() {
this.getData()
this.getData();
}
}
};
</script>
<div id="selector">
<span if={ !this.state.data }>Chargement...</span>
<div if={ this.state.data } id="selector">
<div id="selector-top-container">
<span id="selector-top-title">
{ state.pages.name[state.pages.curIndex] }
</span>
<button id="selector-top-btn">
<
</button>
<span id="selector-top-title">
{ this.state.page.name[this.state.page.curIndex] }
</span>
<button onclick={ previousPage } id="selector-top-btn">&lt;</button>
</div>
<div id="selector-list-container">
<ul id="selector-list">
<li each={ item in state.data } class="selector-list-inner">
<span class="selector-list-names">{state.data.name}</span>
<span class="selector-list-counts">{state.data.count}</span>
<li each={ item in this.state.data } class="selector-list-inner">
<a onclick={ nextPage } class="selector-list-names">{ item.name }</a>
<span class="selector-list-counts">{ item.count }</span>
</li>
</ul>
</div>