This commit is contained in:
2026-03-20 03:06:30 +01:00
parent 864f5c1940
commit bd20abb745
6 changed files with 167 additions and 72 deletions
+31 -14
View File
@@ -167,32 +167,36 @@
onMounted() { onMounted() {
var saved = localStorage.getItem('selectionFormations') var saved = localStorage.getItem('selectionFormations')
var self = this
// Charger la sélection locale si elle existe
if (saved) { if (saved) {
try { try {
this.state.selectedFormations = JSON.parse(saved) this.state.selectedFormations = JSON.parse(saved)
} catch (e) { } catch (e) {
console.error(e) console.error('Erreur lecture localStorage :', e)
} }
} }
var self = this // Écouter les changements de connexion Firebase
// Écouter les changements d'authentification Firebase
window.firebaseServices.onUserChanged(function(user) { window.firebaseServices.onUserChanged(function(user) {
self.update({ user: user }) self.update({ user: user })
// Si un utilisateur vient de se connecter, charger sa sélection depuis Firestore
if (user) { if (user) {
// Charger la sélection depuis Firestore window.firebaseServices.loadUserData(user.uid)
window.firebaseServices.loadUserData(user.uid).then(function(data) { .then(function(data) {
if (data && data.selection) { if (data && data.selection) {
self.update({ selectedFormations: data.selection }) self.update({ selectedFormations: data.selection })
localStorage.setItem('selectionFormations', JSON.stringify(data.selection)) localStorage.setItem('selectionFormations', JSON.stringify(data.selection))
} }
}).catch(function(err) { })
console.error('Erreur chargement Firestore:', err) .catch(function(err) {
console.error('Erreur chargement Firestore :', err)
}) })
} }
}) })
window.addEventListener('hashchange', function() { window.addEventListener('hashchange', function() {
@@ -202,26 +206,31 @@
this.handleRoute() this.handleRoute()
}, },
// Appelée après une connexion ou inscription réussie
onUserAuth() { onUserAuth() {
// Appelé après connexion/inscription réussie — l'écouteur onUserChanged gère le reste // L'écouteur onUserChanged dans onMounted gère automatiquement le reste
}, },
// Appelée après une déconnexion
onUserLogout() { onUserLogout() {
// Vider la sélection locale à la déconnexion → obligé de se reconnecter pour retrouver ses formations // On vide la sélection : l'utilisateur doit se reconnecter pour retrouver ses formations
this.update({ selectedFormations: [] }) this.update({ selectedFormations: [] })
localStorage.removeItem('selectionFormations') localStorage.removeItem('selectionFormations')
}, },
// Sauvegarder la sélection en local ET dans Firestore si connecté
async saveSelection(selection) { async saveSelection(selection) {
localStorage.setItem('selectionFormations', JSON.stringify(selection)) localStorage.setItem('selectionFormations', JSON.stringify(selection))
if (this.state.user) { if (this.state.user) {
try { try {
await window.firebaseServices.saveUserData(this.state.user.uid, { selection: selection }) await window.firebaseServices.saveUserData(this.state.user.uid, { selection: selection })
} catch (err) { } catch (err) {
console.error('Erreur sauvegarde Firestore:', err) console.error('Erreur sauvegarde Firestore :', err)
} }
} }
}, },
handleRoute() { handleRoute() {
@@ -397,9 +406,17 @@
this.saveSelection([]) this.saveSelection([])
}, },
updateNote(e) { this.update({ note: Number(e.target.value) }) }, updateNote(e) {
updateSerie(e) { this.update({ serie: e.target.value }) }, this.update({ note: Number(e.target.value) })
updateSort(e) { this.update({ sortBy: e.target.value }) }, },
updateSerie(e) {
this.update({ serie: e.target.value })
},
updateSort(e) {
this.update({ sortBy: e.target.value })
},
getSortedSelection() { getSortedSelection() {
var selection = this.state.selectedFormations.slice() var selection = this.state.selectedFormations.slice()
+55 -23
View File
@@ -1,38 +1,39 @@
<auth-panel> <auth-panel>
<!-- Bouton compact dans le header quand pas connecté -->
<!-- Bouton connexion dans le header (utilisateur non connecté) -->
<div class="auth-header-btn" if={ !props.user }> <div class="auth-header-btn" if={ !props.user }>
<button class="btn btn-auth" onclick={ openModal }> <button class="btn btn-auth" onclick={ openModal }>
<span class="auth-icon">👤</span> Connexion <span class="auth-icon">👤</span> Connexion
</button> </button>
</div> </div>
<!-- Info utilisateur connecté dans le header --> <!-- Email + bouton déconnexion dans le header (utilisateur connecté) -->
<div class="auth-user-info" if={ props.user }> <div class="auth-user-info" if={ props.user }>
<span class="auth-email">{ props.user.email }</span> <span class="auth-email">{ props.user.email }</span>
<button class="btn btn-auth-logout" onclick={ handleLogout }>Déconnexion</button> <button class="btn btn-auth-logout" onclick={ handleLogout }>Déconnexion</button>
</div> </div>
<!-- Modale --> <!-- Modale d'authentification -->
<div class="auth-modal-overlay" if={ state.open } onclick={ closeOnOverlay }> <div class="auth-modal-overlay" if={ state.open } onclick={ closeOnOverlay }>
<div class="auth-modal"> <div class="auth-modal">
<button class="auth-modal-close" onclick={ closeModal }>✕</button> <button class="auth-modal-close" onclick={ closeModal }>✕</button>
<h2 class="auth-modal-title">{ state.mode === 'login' ? 'Connexion' : 'Créer un compte' }</h2> <h2 class="auth-modal-title">{ state.titre }</h2>
<!-- Onglets Connexion / Inscription -->
<div class="auth-tabs"> <div class="auth-tabs">
<button <button class={ state.classBtnLogin } onclick={ switchToLogin }>
class={ state.mode === 'login' ? 'auth-tab active' : 'auth-tab' }
onclick={ () => switchMode('login') }>
Connexion Connexion
</button> </button>
<button <button class={ state.classBtnRegister } onclick={ switchToRegister }>
class={ state.mode === 'register' ? 'auth-tab active' : 'auth-tab' }
onclick={ () => switchMode('register') }>
Inscription Inscription
</button> </button>
</div> </div>
<!-- Formulaire -->
<form onsubmit={ handleSubmit } class="auth-form"> <form onsubmit={ handleSubmit } class="auth-form">
<div class="auth-field"> <div class="auth-field">
<label>Adresse e-mail</label> <label>Adresse e-mail</label>
<input <input
@@ -42,6 +43,7 @@
required required
/> />
</div> </div>
<div class="auth-field"> <div class="auth-field">
<label>Mot de passe</label> <label>Mot de passe</label>
<input <input
@@ -53,24 +55,31 @@
/> />
</div> </div>
<!-- Message d'erreur -->
<div class="auth-error" if={ state.error }> <div class="auth-error" if={ state.error }>
{ state.error } { state.error }
</div> </div>
<button type="submit" class="btn btn-primary auth-submit" disabled={ state.loading }> <button type="submit" class="btn btn-primary auth-submit" disabled={ state.loading }>
{ state.loading ? 'Chargement...' : (state.mode === 'login' ? 'Se connecter' : 'Créer le compte') } { state.labelBouton }
</button> </button>
</form> </form>
</div> </div>
</div> </div>
<script> <script>
export default { export default {
state: { state: {
open: false, open: false,
mode: 'login', mode: 'login',
loading: false, loading: false,
error: null error: null,
titre: 'Connexion',
labelBouton: 'Se connecter',
classBtnLogin: 'auth-tab active',
classBtnRegister: 'auth-tab'
}, },
openModal() { openModal() {
@@ -87,19 +96,38 @@
} }
}, },
switchMode(mode) { switchToLogin() {
this.update({ mode: mode, error: null }) this.update({
mode: 'login',
error: null,
titre: 'Connexion',
labelBouton: 'Se connecter',
classBtnLogin: 'auth-tab active',
classBtnRegister: 'auth-tab'
})
},
switchToRegister() {
this.update({
mode: 'register',
error: null,
titre: 'Créer un compte',
labelBouton: 'Créer le compte',
classBtnLogin: 'auth-tab',
classBtnRegister: 'auth-tab active'
})
}, },
async handleSubmit(e) { async handleSubmit(e) {
e.preventDefault() e.preventDefault()
var email = e.target.email.value.trim() var email = e.target.email.value.trim()
var password = e.target.password.value var password = e.target.password.value
var services = window.firebaseServices
this.update({ loading: true, error: null }) this.update({ loading: true, error: null })
try { try {
var services = window.firebaseServices
if (this.state.mode === 'register') { if (this.state.mode === 'register') {
await services.createAccount(email, password) await services.createAccount(email, password)
@@ -109,22 +137,24 @@
this.update({ open: false, loading: false }) this.update({ open: false, loading: false })
this.props.onauth && this.props.onauth() this.props.onauth && this.props.onauth()
} catch (err) { } catch (err) {
var msg = 'Une erreur est survenue.'
var message = 'Une erreur est survenue.'
if (err.code === 'auth/email-already-in-use') { if (err.code === 'auth/email-already-in-use') {
msg = 'Cet e-mail est déjà utilisé.' message = 'Cet e-mail est déjà utilisé.'
} else if (err.code === 'auth/invalid-email') { } else if (err.code === 'auth/invalid-email') {
msg = 'Adresse e-mail invalide.' message = 'Adresse e-mail invalide.'
} else if (err.code === 'auth/wrong-password' || err.code === 'auth/invalid-credential') { } else if (err.code === 'auth/wrong-password' || err.code === 'auth/invalid-credential') {
msg = 'E-mail ou mot de passe incorrect.' message = 'E-mail ou mot de passe incorrect.'
} else if (err.code === 'auth/weak-password') { } else if (err.code === 'auth/weak-password') {
msg = 'Le mot de passe doit faire au moins 6 caractères.' message = 'Le mot de passe doit faire au moins 6 caractères.'
} else if (err.code === 'auth/user-not-found') { } else if (err.code === 'auth/user-not-found') {
msg = 'Aucun compte trouvé avec cet e-mail.' message = 'Aucun compte trouvé avec cet e-mail.'
} }
this.update({ loading: false, error: msg }) this.update({ loading: false, error: message })
} }
}, },
@@ -133,9 +163,11 @@
await window.firebaseServices.logout() await window.firebaseServices.logout()
this.props.onlogout && this.props.onlogout() this.props.onlogout && this.props.onlogout()
} catch (err) { } catch (err) {
console.error('Erreur déconnexion:', err) console.error('Erreur déconnexion :', err)
} }
} }
} }
</script> </script>
</auth-panel> </auth-panel>
+13 -3
View File
@@ -191,7 +191,7 @@
</div> </div>
</div> </div>
<button onclick={ () => props.onback() } class="btn-retour">Retour à la liste</button> <button onclick={ goBack } class="btn-retour">Retour à la liste</button>
</div> </div>
<script> <script>
@@ -221,6 +221,11 @@
} }
}, },
// Retour à la liste des résultats
goBack() {
this.props.onback()
},
renderCharts() { renderCharts() {
var f = this.props.formation var f = this.props.formation
if (!f) return if (!f) return
@@ -307,8 +312,13 @@
var rows = '' var rows = ''
for (var i = 0; i < hist.length; i++) { for (var i = 0; i < hist.length; i++) {
var h = hist[i] var h = hist[i]
var sizeCand = maxCandidats > 0 ? Math.round((h.candidats / maxCandidats) * 100) / 100 : 0 var sizeCand = 0
var sizeAdmis = maxCandidats > 0 ? Math.round((h.admis / maxCandidats) * 100) / 100 : 0 var sizeAdmis = 0
if (maxCandidats > 0) {
sizeCand = Math.round((h.candidats / maxCandidats) * 100) / 100
sizeAdmis = Math.round((h.admis / maxCandidats) * 100) / 100
}
rows += '<tr>' rows += '<tr>'
rows += '<th scope="row">' + h.annee + '</th>' rows += '<th scope="row">' + h.annee + '</th>'
+24 -7
View File
@@ -12,7 +12,7 @@
<div class="filters-toggle"> <div class="filters-toggle">
<button class="btn btn-small btn-outline" onclick={ toggleFilters }> <button class="btn btn-small btn-outline" onclick={ toggleFilters }>
{ state.showFilters ? 'Masquer les filtres' : 'Filtres avancés' } { state.labelFiltres }
</button> </button>
</div> </div>
@@ -91,6 +91,7 @@
state: { state: {
query: '', query: '',
showFilters: false, showFilters: false,
labelFiltres: 'Filtres avancés',
filiere: '', filiere: '',
selectivite: '', selectivite: '',
region: '', region: '',
@@ -109,14 +110,30 @@
}, },
toggleFilters() { toggleFilters() {
this.update({ showFilters: !this.state.showFilters }) var visible = !this.state.showFilters
var label = visible ? 'Masquer les filtres' : 'Filtres avancés'
this.update({ showFilters: visible, labelFiltres: label })
}, },
updateFiliere(e) { this.update({ filiere: e.target.value }) }, updateFiliere(e) {
updateSelectivite(e) { this.update({ selectivite: e.target.value }) }, this.update({ filiere: e.target.value })
updateRegion(e) { this.update({ region: e.target.value }) }, },
updateTauxMin(e) { this.update({ tauxMin: Number(e.target.value) }) },
updateTauxMax(e) { this.update({ tauxMax: Number(e.target.value) }) }, updateSelectivite(e) {
this.update({ selectivite: e.target.value })
},
updateRegion(e) {
this.update({ region: e.target.value })
},
updateTauxMin(e) {
this.update({ tauxMin: Number(e.target.value) })
},
updateTauxMax(e) {
this.update({ tauxMax: Number(e.target.value) })
},
submitSearch() { submitSearch() {
var filters = { var filters = {
+20 -3
View File
@@ -1,4 +1,5 @@
import { initializeApp } from "https://www.gstatic.com/firebasejs/11.6.1/firebase-app.js"; import { initializeApp } from "https://www.gstatic.com/firebasejs/11.6.1/firebase-app.js";
import { import {
getAuth, getAuth,
createUserWithEmailAndPassword, createUserWithEmailAndPassword,
@@ -6,6 +7,7 @@ import {
signOut, signOut,
onAuthStateChanged onAuthStateChanged
} from "https://www.gstatic.com/firebasejs/11.6.1/firebase-auth.js"; } from "https://www.gstatic.com/firebasejs/11.6.1/firebase-auth.js";
import { import {
getFirestore, getFirestore,
doc, doc,
@@ -13,6 +15,7 @@ import {
getDoc getDoc
} from "https://www.gstatic.com/firebasejs/11.6.1/firebase-firestore.js"; } from "https://www.gstatic.com/firebasejs/11.6.1/firebase-firestore.js";
const firebaseConfig = { const firebaseConfig = {
apiKey: "AIzaSyDr1jMgGm0Oj_bOiWY-8Gy27IlzkmAzlOM", apiKey: "AIzaSyDr1jMgGm0Oj_bOiWY-8Gy27IlzkmAzlOM",
authDomain: "parcoursupp-expl.firebaseapp.com", authDomain: "parcoursupp-expl.firebaseapp.com",
@@ -20,37 +23,51 @@ const firebaseConfig = {
storageBucket: "parcoursupp-expl.firebasestorage.app", storageBucket: "parcoursupp-expl.firebasestorage.app",
messagingSenderId: "973054617217", messagingSenderId: "973054617217",
appId: "1:973054617217:web:4d52af4280396976228f80" appId: "1:973054617217:web:4d52af4280396976228f80"
}; };
const app = initializeApp(firebaseConfig); const app = initializeApp(firebaseConfig);
const auth = getAuth(app); const auth = getAuth(app);
const db = getFirestore(app); const db = getFirestore(app);
// Créer un compte avec email et mot de passe
async function createAccount(email, password) { async function createAccount(email, password) {
return createUserWithEmailAndPassword(auth, email, password); return createUserWithEmailAndPassword(auth, email, password);
} }
// Se connecter avec email et mot de passe
async function login(email, password) { async function login(email, password) {
return signInWithEmailAndPassword(auth, email, password); return signInWithEmailAndPassword(auth, email, password);
} }
// Se déconnecter
async function logout() { async function logout() {
return signOut(auth); return signOut(auth);
} }
// Écouter les changements d'état de connexion
function onUserChanged(callback) { function onUserChanged(callback) {
return onAuthStateChanged(auth, callback); return onAuthStateChanged(auth, callback);
} }
// Sauvegarder les données d'un utilisateur dans Firestore
async function saveUserData(uid, data) { async function saveUserData(uid, data) {
await setDoc(doc(db, "users", uid), data, { merge: true }); await setDoc(doc(db, "users", uid), data, { merge: true });
} }
// Charger les données d'un utilisateur depuis Firestore
async function loadUserData(uid) { async function loadUserData(uid) {
const snap = await getDoc(doc(db, "users", uid)); var snap = await getDoc(doc(db, "users", uid));
return snap.exists() ? snap.data() : null;
if (snap.exists()) {
return snap.data();
} else {
return null;
}
} }
export { export {
auth, auth,
db, db,
+10 -8
View File
@@ -1,10 +1,17 @@
export function createFormation(raw) { export function createFormation(raw) {
let taux = 0 var taux = 0
var latitude = null
var longitude = null
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)
} }
if (raw.g_olocalisation_des_formations) {
latitude = raw.g_olocalisation_des_formations.lat
longitude = raw.g_olocalisation_des_formations.lon
}
return { return {
id: raw.cod_uai + "-" + raw.lib_for_voe_ins, id: raw.cod_uai + "-" + raw.lib_for_voe_ins,
@@ -25,13 +32,8 @@ export function createFormation(raw) {
admis: raw.acc_tot, admis: raw.acc_tot,
tauxAcces: taux, tauxAcces: taux,
latitude: raw.g_olocalisation_des_formations latitude: latitude,
? raw.g_olocalisation_des_formations.lat longitude: longitude,
: null,
longitude: raw.g_olocalisation_des_formations
? raw.g_olocalisation_des_formations.lon
: null,
pctFemmes: raw.pct_f, pctFemmes: raw.pct_f,
pctBoursiers: raw.pct_bours, pctBoursiers: raw.pct_bours,