337 lines
8.9 KiB
Plaintext
337 lines
8.9 KiB
Plaintext
<app>
|
|
<header class="site-header">
|
|
<div class="header-inner">
|
|
<div class="logo">
|
|
<span class="logo-icon"></span>
|
|
<span class="logo-text">Parcoursup <span class="logo-light">Explorer</span></span>
|
|
</div>
|
|
<div class="header-badge" if={ state.selectedFormations.length > 0 }>
|
|
{ state.selectedFormations.length } sélection(s)
|
|
</div>
|
|
</div>
|
|
</header>
|
|
|
|
<div class="page">
|
|
|
|
<div if={ !state.selected }>
|
|
<search-bar onsearch={ launchSearch }></search-bar>
|
|
|
|
<div class="detail-card comparateur-card" if={ state.selectedFormations.length > 0 }>
|
|
<h3>Comparateur</h3>
|
|
|
|
<p>Choisis ton profil pour comparer les formations sélectionnées.</p>
|
|
|
|
<div class="compare-controls">
|
|
<div>
|
|
<label><b>Note moyenne :</b></label><br />
|
|
<input
|
|
type="number"
|
|
min="0"
|
|
max="20"
|
|
step="0.1"
|
|
value={ state.note }
|
|
oninput={ updateNote }
|
|
/>
|
|
</div>
|
|
|
|
<div>
|
|
<label><b>Série :</b></label><br />
|
|
<select onchange={ updateSerie }>
|
|
<option value="general" selected={ state.serie === 'general' }>Général</option>
|
|
<option value="techno" selected={ state.serie === 'techno' }>Technologique</option>
|
|
<option value="pro" selected={ state.serie === 'pro' }>Professionnel</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div>
|
|
<label><b>Trier par :</b></label><br />
|
|
<select onchange={ updateSort }>
|
|
<option value="nom" selected={ state.sortBy === 'nom' }>Nom</option>
|
|
<option value="ville" selected={ state.sortBy === 'ville' }>Ville</option>
|
|
<option value="taux" selected={ state.sortBy === 'taux' }>Taux d'accès</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<button class="btn btn-danger" onclick={ clearSelection }>Vider la sélection</button>
|
|
|
|
<hr />
|
|
|
|
<h3>Formations sélectionnées</h3>
|
|
|
|
<div each={ f in getSortedSelection() } key={ f.id } class="card">
|
|
<h4>{ f.nom }</h4>
|
|
|
|
<p><b>Ville :</b> { f.ville }</p>
|
|
<p><b>Filière :</b> { f.filiere }</p>
|
|
<p><b>Taux d'accès :</b> { f.tauxAcces }%</p>
|
|
|
|
<p>
|
|
<b>Profil admis :</b>
|
|
Général { f.pctGeneral }% /
|
|
Techno { f.pctTechno }% /
|
|
Pro { f.pctPro }%
|
|
</p>
|
|
|
|
<p>
|
|
<b>Estimation :</b>
|
|
<span class={ getEstimateClass(f) }>
|
|
{ estimateFormation(f) }
|
|
</span>
|
|
</p>
|
|
|
|
<button class="btn btn-small btn-outline" onclick={ () => removeFromSelection(f.id) }>
|
|
Retirer
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<p class="result-count" if={ state.hasSearched && !state.loading }>
|
|
<b>{ state.query }</b> — { state.total } résultat(s)
|
|
</p>
|
|
|
|
<map-view results={ state.results }></map-view>
|
|
|
|
<div class="layout">
|
|
<div>
|
|
<result-list
|
|
results={ state.results }
|
|
hasSearched={ state.hasSearched }
|
|
loading={ state.loading }
|
|
ondetail={ showDetail }
|
|
onselect={ addToSelection }>
|
|
</result-list>
|
|
|
|
<div class="pagination" if={ state.total > state.limit }>
|
|
<button class="btn btn-outline" onclick={ previousPage } disabled={ state.page === 1 }>
|
|
← Précédent
|
|
</button>
|
|
|
|
<span class="page-info">Page { state.page } / { getTotalPages() }</span>
|
|
|
|
<button class="btn btn-outline" onclick={ nextPage } disabled={ state.page === getTotalPages() }>
|
|
Suivant →
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div if={ state.selected }>
|
|
<detail-view
|
|
formation={ state.selected }
|
|
onback={ backToList }>
|
|
</detail-view>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
export default {
|
|
state: {
|
|
loading: false,
|
|
hasSearched: false,
|
|
results: [],
|
|
selected: null,
|
|
selectedFormations: [],
|
|
note: 12,
|
|
serie: 'general',
|
|
sortBy: 'nom',
|
|
query: '',
|
|
page: 1,
|
|
limit: 20,
|
|
total: 0
|
|
},
|
|
|
|
onMounted() {
|
|
const saved = localStorage.getItem('selectionFormations')
|
|
|
|
if (saved) {
|
|
try {
|
|
this.update({
|
|
selectedFormations: JSON.parse(saved)
|
|
})
|
|
} catch (e) {
|
|
console.error(e)
|
|
}
|
|
}
|
|
},
|
|
|
|
async launchSearch(query) {
|
|
this.update({
|
|
loading: true,
|
|
hasSearched: true,
|
|
selected: null,
|
|
query: query,
|
|
page: 1
|
|
})
|
|
|
|
await this.loadPage(1)
|
|
},
|
|
|
|
async loadPage(page) {
|
|
this.update({
|
|
loading: true
|
|
})
|
|
|
|
try {
|
|
const offset = (page - 1) * this.state.limit
|
|
|
|
const data = await window.fetchFormations(
|
|
this.state.query,
|
|
this.state.limit,
|
|
offset
|
|
)
|
|
|
|
const formations = []
|
|
|
|
if (data.results) {
|
|
for (let i = 0; i < data.results.length; i++) {
|
|
const raw = data.results[i]
|
|
formations.push(window.createFormation(raw))
|
|
}
|
|
}
|
|
|
|
this.update({
|
|
results: formations,
|
|
total: data.total_count ? data.total_count : 0,
|
|
page: page,
|
|
loading: false
|
|
})
|
|
} catch (error) {
|
|
console.error(error)
|
|
this.update({
|
|
results: [],
|
|
total: 0,
|
|
loading: false
|
|
})
|
|
}
|
|
},
|
|
|
|
getTotalPages() {
|
|
return Math.ceil(this.state.total / this.state.limit)
|
|
},
|
|
|
|
async nextPage() {
|
|
if (this.state.page < this.getTotalPages()) {
|
|
await this.loadPage(this.state.page + 1)
|
|
}
|
|
},
|
|
|
|
async previousPage() {
|
|
if (this.state.page > 1) {
|
|
await this.loadPage(this.state.page - 1)
|
|
}
|
|
},
|
|
|
|
showDetail(index) {
|
|
this.update({
|
|
selected: this.state.results[index]
|
|
})
|
|
},
|
|
|
|
backToList() {
|
|
this.update({
|
|
selected: null
|
|
})
|
|
},
|
|
|
|
addToSelection(index) {
|
|
const formation = this.state.results[index]
|
|
const selection = [...this.state.selectedFormations]
|
|
|
|
let exists = false
|
|
|
|
for (let i = 0; i < selection.length; i++) {
|
|
if (selection[i].id === formation.id) {
|
|
exists = true
|
|
}
|
|
}
|
|
|
|
if (!exists) {
|
|
selection.push(formation)
|
|
this.update({ selectedFormations: selection })
|
|
localStorage.setItem('selectionFormations', JSON.stringify(selection))
|
|
}
|
|
},
|
|
|
|
removeFromSelection(id) {
|
|
const newSelection = []
|
|
|
|
for (let i = 0; i < this.state.selectedFormations.length; i++) {
|
|
const f = this.state.selectedFormations[i]
|
|
|
|
if (f.id !== id) {
|
|
newSelection.push(f)
|
|
}
|
|
}
|
|
|
|
this.update({
|
|
selectedFormations: newSelection
|
|
})
|
|
|
|
localStorage.setItem('selectionFormations', JSON.stringify(newSelection))
|
|
},
|
|
|
|
clearSelection() {
|
|
this.update({
|
|
selectedFormations: []
|
|
})
|
|
|
|
localStorage.setItem('selectionFormations', JSON.stringify([]))
|
|
},
|
|
|
|
updateNote(e) {
|
|
this.update({ note: Number(e.target.value) })
|
|
},
|
|
|
|
updateSerie(e) {
|
|
this.update({ serie: e.target.value })
|
|
},
|
|
|
|
updateSort(e) {
|
|
this.update({ sortBy: e.target.value })
|
|
},
|
|
|
|
getSortedSelection() {
|
|
const selection = [...this.state.selectedFormations]
|
|
|
|
if (this.state.sortBy === 'taux') {
|
|
selection.sort((a, b) => b.tauxAcces - a.tauxAcces)
|
|
} else if (this.state.sortBy === 'ville') {
|
|
selection.sort((a, b) => a.ville.localeCompare(b.ville))
|
|
} else {
|
|
selection.sort((a, b) => a.nom.localeCompare(b.nom))
|
|
}
|
|
|
|
return selection
|
|
},
|
|
|
|
estimateFormation(f) {
|
|
let score = 0
|
|
|
|
if (f.tauxAcces >= 50) score += 2
|
|
else if (f.tauxAcces >= 20) score += 1
|
|
|
|
if (this.state.note >= 15) score += 2
|
|
else if (this.state.note >= 12) score += 1
|
|
|
|
if (this.state.serie === 'general' && f.pctGeneral >= 50) score += 2
|
|
if (this.state.serie === 'techno' && f.pctTechno >= 20) score += 2
|
|
if (this.state.serie === 'pro' && f.pctPro >= 15) score += 2
|
|
|
|
if (score >= 5) return 'Favorable'
|
|
if (score >= 3) return 'Possible'
|
|
return 'Difficile'
|
|
},
|
|
|
|
getEstimateClass(f) {
|
|
const result = this.estimateFormation(f)
|
|
|
|
if (result === 'Favorable') return 'estimate favorable'
|
|
if (result === 'Possible') return 'estimate possible'
|
|
return 'estimate difficile'
|
|
}
|
|
}
|
|
</script>
|
|
</app>
|