passage du prototype en composant riot simple
This commit is contained in:
+19
-19
@@ -1,21 +1,21 @@
|
|||||||
export function buildURL(query) {
|
export function buildURL(query) {
|
||||||
let url =
|
let url =
|
||||||
"https://data.enseignementsup-recherche.gouv.fr/api/explore/v2.1/catalog/datasets/fr-esr-parcoursup/records?limit=10"
|
"https://data.enseignementsup-recherche.gouv.fr/api/explore/v2.1/catalog/datasets/fr-esr-parcoursup/records?limit=10"
|
||||||
|
|
||||||
if (query && query.trim() !== "") {
|
if (query && query.trim() !== "") {
|
||||||
url += "&where=search(lib_for_voe_ins, '" + query + "')"
|
url += "&where=search(lib_for_voe_ins, '" + query + "')"
|
||||||
}
|
|
||||||
|
|
||||||
return url
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchFormations(query) {
|
return url
|
||||||
const url = buildURL(query)
|
}
|
||||||
const response = await fetch(url)
|
|
||||||
|
export async function fetchFormations(query) {
|
||||||
if (!response.ok) {
|
const url = buildURL(query)
|
||||||
throw new Error("Erreur HTTP")
|
const response = await fetch(url)
|
||||||
}
|
|
||||||
|
if (!response.ok) {
|
||||||
return await response.json()
|
throw new Error("Erreur HTTP")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return await response.json()
|
||||||
|
}
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
<app>
|
||||||
|
<h1>Mini projet Parcoursup</h1>
|
||||||
|
<p>Recherche de formations Parcoursup avec Riot</p>
|
||||||
|
|
||||||
|
<div if={ !state.selected }>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="Ex : BUT informatique"
|
||||||
|
oninput={ updateQuery }
|
||||||
|
value={ state.query }
|
||||||
|
/>
|
||||||
|
<button onclick={ search }>Rechercher</button>
|
||||||
|
|
||||||
|
<p if={ state.loading }>Chargement...</p>
|
||||||
|
<p if={ !state.loading && state.results.length === 0 && state.hasSearched }>
|
||||||
|
Aucun résultat trouvé
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div each={ f, i in state.results } key={ f.id }
|
||||||
|
style="border:1px solid #ccc; padding:10px; margin:10px;">
|
||||||
|
<h3>{ f.nom }</h3>
|
||||||
|
<p><b>Établissement :</b> { f.etablissement }</p>
|
||||||
|
<p><b>Ville :</b> { f.ville } ({ f.departement })</p>
|
||||||
|
<p><b>Filière :</b> { f.filiere }</p>
|
||||||
|
<p><b>Taux d'accès :</b> { f.tauxAcces }%</p>
|
||||||
|
<button onclick={ () => showDetail(i) }>Voir détail</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div if={ state.selected }>
|
||||||
|
<h2>{ state.selected.nom }</h2>
|
||||||
|
<p><b>Établissement :</b> { state.selected.etablissement }</p>
|
||||||
|
<p><b>Ville :</b> { state.selected.ville }</p>
|
||||||
|
<p><b>Département :</b> { state.selected.departement }</p>
|
||||||
|
<p><b>Filière :</b> { state.selected.filiere }</p>
|
||||||
|
<p><b>Sélectivité :</b> { state.selected.selectivite }</p>
|
||||||
|
<p><b>Capacité :</b> { state.selected.capacite }</p>
|
||||||
|
<p><b>Candidats :</b> { state.selected.candidats }</p>
|
||||||
|
<p><b>Admis :</b> { state.selected.admis }</p>
|
||||||
|
<p><b>Taux d'accès :</b> { state.selected.tauxAcces }%</p>
|
||||||
|
|
||||||
|
<button onclick={ backToList }>Retour</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { fetchFormations } from './api.js'
|
||||||
|
import { createFormation } from './formation.js'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
state: {
|
||||||
|
query: '',
|
||||||
|
loading: false,
|
||||||
|
hasSearched: false,
|
||||||
|
results: [],
|
||||||
|
selected: null
|
||||||
|
},
|
||||||
|
|
||||||
|
updateQuery(e) {
|
||||||
|
this.update({ query: e.target.value })
|
||||||
|
},
|
||||||
|
|
||||||
|
async search() {
|
||||||
|
this.update({
|
||||||
|
loading: true,
|
||||||
|
hasSearched: true,
|
||||||
|
selected: null
|
||||||
|
})
|
||||||
|
|
||||||
|
try {
|
||||||
|
const data = await fetchFormations(this.state.query)
|
||||||
|
const formations = []
|
||||||
|
|
||||||
|
if (data.results) {
|
||||||
|
for (let i = 0; i < data.results.length; i++) {
|
||||||
|
formations.push(createFormation(data.results[i]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.update({
|
||||||
|
results: formations,
|
||||||
|
loading: false
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
this.update({
|
||||||
|
results: [],
|
||||||
|
loading: false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
showDetail(index) {
|
||||||
|
this.update({
|
||||||
|
selected: this.state.results[index]
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
backToList() {
|
||||||
|
this.update({
|
||||||
|
selected: null
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</app>
|
||||||
+22
-22
@@ -1,23 +1,23 @@
|
|||||||
export function createFormation(raw) {
|
export function createFormation(raw) {
|
||||||
let taux = 0
|
let taux = 0
|
||||||
|
|
||||||
if (raw.voe_tot && raw.voe_tot > 0) {
|
if (raw.voe_tot && raw.voe_tot > 0) {
|
||||||
taux = Math.round((raw.acc_tot / raw.voe_tot) * 100)
|
taux = Math.round((raw.acc_tot / raw.voe_tot) * 100)
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: raw.cod_uai + "-" + raw.lib_for_voe_ins,
|
id: raw.cod_uai + "-" + raw.lib_for_voe_ins,
|
||||||
nom: raw.lib_for_voe_ins,
|
nom: raw.lib_for_voe_ins,
|
||||||
etablissement: raw.g_ea_lib_vx,
|
etablissement: raw.g_ea_lib_vx,
|
||||||
ville: raw.ville_etab,
|
ville: raw.ville_etab,
|
||||||
departement: raw.dep,
|
departement: raw.dep,
|
||||||
filiere: raw.fili,
|
filiere: raw.fili,
|
||||||
selectivite: raw.select_form,
|
selectivite: raw.select_form,
|
||||||
capacite: raw.capa_fin,
|
capacite: raw.capa_fin,
|
||||||
candidats: raw.voe_tot,
|
candidats: raw.voe_tot,
|
||||||
admis: raw.acc_tot,
|
admis: raw.acc_tot,
|
||||||
tauxAcces: taux,
|
tauxAcces: taux,
|
||||||
latitude: raw.g_olocalisation_des_formations ? raw.g_olocalisation_des_formations.lat : null,
|
latitude: raw.g_olocalisation_des_formations ? raw.g_olocalisation_des_formations.lat : null,
|
||||||
longitude: raw.g_olocalisation_des_formations ? raw.g_olocalisation_des_formations.lon : null
|
longitude: raw.g_olocalisation_des_formations ? raw.g_olocalisation_des_formations.lon : null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+14
-9
@@ -3,18 +3,23 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Parcoursup - test API</title>
|
<title>Parcoursup Riot</title>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/riot@9/riot+compiler.min.js"></script>
|
||||||
|
<script type="module">
|
||||||
|
import "./api.js"
|
||||||
|
import "./formation.js"
|
||||||
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Mini projet Parcoursup</h1>
|
<app></app>
|
||||||
<p>Recherche de formations Parcoursup</p>
|
|
||||||
|
|
||||||
<input id="search" type="text" placeholder="Ex : BUT informatique" />
|
<script src="./app.riot" type="riot"></script>
|
||||||
<button id="btn-test">Rechercher</button>
|
|
||||||
|
|
||||||
<div id="output">En attente...</div>
|
<script>
|
||||||
|
riot.compile().then(() => {
|
||||||
|
riot.mount('app')
|
||||||
<script type="module" src="./main.js"></script>
|
})
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user