Spaces:
Running
Running
<html lang="fr"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<!-- Titre mis à jour --> | |
<title>Cocktail Fitness - Suivi</title> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/confetti.browser.min.js"></script> | |
<!-- SDK Firebase (v8) - Inchangé --> | |
<script src="https://www.gstatic.com/firebasejs/8.10.1/firebase-app.js"></script> | |
<script src="https://www.gstatic.com/firebasejs/8.10.1/firebase-auth.js"></script> | |
<script src="https://www.gstatic.com/firebasejs/8.10.1/firebase-firestore.js"></script> | |
<!-- Importation de Google Fonts (Oswald) --> | |
<link rel="preconnect" href="https://fonts.googleapis.com"> | |
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> | |
<link href="https://fonts.googleapis.com/css2?family=Oswald:wght@700&family=Roboto:wght@400;700&display=swap" rel="stylesheet"> | |
<style> | |
/* ===== NOUVELLES VARIABLES DE COULEUR & POLICES ===== */ | |
:root { | |
--bg-dark: #101010; /* Fond très sombre, proche du noir */ | |
--bg-card: #1e1e1e; /* Fond des cartes légèrement plus clair */ | |
--text-light: #f0f0f0; /* Texte principal légèrement off-white */ | |
--text-secondary: #aaaaaa; /* Texte secondaire (labels, etc.) */ | |
--accent: #FFC107; /* Jaune/Or du logo Cocktail */ | |
--accent-dark: #E0A800; /* Jaune plus sombre pour hover */ | |
--text-on-accent: #101010; /* Texte sur fond jaune (assez foncé pour contraste) */ | |
--neutral-white: #FFFFFF; /* Blanc pur du logo Fitness */ | |
--danger: #f44336; /* Rouge pour danger (inchangé) */ | |
--info: #6c757d; /* Couleur neutre/grise pour info (ancien bleu) */ | |
--border-color: #333333; /* Couleur des bordures */ | |
--font-primary: 'Roboto', sans-serif; /* Police par défaut */ | |
--font-headings: 'Oswald', sans-serif; /* Police pour titres/boutons (style COCKTAIL) */ | |
} | |
/* ===== FIN NOUVELLES VARIABLES ===== */ | |
* { | |
margin: 0; | |
padding: 0; | |
box-sizing: border-box; | |
/* Police par défaut appliquée */ | |
font-family: var(--font-primary); | |
} | |
body { | |
background-color: var(--bg-dark); | |
color: var(--text-light); | |
min-height: 100vh; | |
padding-bottom: 80px; /* Espace pour nav bottom */ | |
} | |
.container { | |
width: 100%; | |
max-width: 800px; | |
margin: 0 auto; | |
padding: 1rem; | |
} | |
/* Header modifié pour intégrer le logo */ | |
header { | |
padding: 1rem 0; | |
text-align: center; | |
border-bottom: 1px solid var(--border-color); | |
margin-bottom: 1rem; | |
display: flex; /* Utilisation de flex pour centrer le logo */ | |
flex-direction: column; /* Logo au-dessus du slogan */ | |
align-items: center; /* Centrage horizontal */ | |
} | |
header img#app-logo { | |
max-width: 250px; /* Ajustez la taille selon vos besoins */ | |
height: auto; | |
margin-bottom: 0.5rem; /* Espace entre logo et slogan */ | |
} | |
header p { | |
color: var(--text-secondary); | |
font-size: 0.9rem; | |
} | |
/* Fin modif header */ | |
h1, h2, h3, h4 { | |
/* Application de la police titre + couleur accent */ | |
font-family: var(--font-headings); | |
font-weight: 700; /* Assurez-vous que le poids est chargé */ | |
color: var(--accent); | |
text-transform: uppercase; /* Style COCKTAIL */ | |
letter-spacing: 0.5px; /* Léger espacement */ | |
} | |
.btn { | |
background-color: var(--accent); | |
/* Texte sur bouton doit contraster avec le jaune */ | |
color: var(--text-on-accent); | |
border: none; | |
padding: 0.6rem 1.2rem; | |
border-radius: 4px; | |
cursor: pointer; | |
font-weight: bold; /* Utilise le poids de Roboto Bold par défaut */ | |
font-family: var(--font-headings); /* Police titre sur boutons */ | |
text-transform: uppercase; /* Style COCKTAIL */ | |
transition: background-color 0.2s, color 0.2s; | |
} | |
.btn:hover { | |
background-color: var(--accent-dark); | |
color: var(--text-on-accent); | |
} | |
.btn:disabled { | |
background-color: #555; | |
color: #999; | |
cursor: not-allowed; | |
} | |
.btn-outline { | |
background-color: transparent; | |
color: var(--accent); | |
border: 1px solid var(--accent); | |
} | |
.btn-outline:hover { | |
background-color: rgba(255, 193, 7, 0.1); /* Léger fond jaune au survol */ | |
color: var(--accent); | |
} | |
.btn-outline:disabled { | |
color: #555; | |
border-color: #555; | |
background-color: transparent; | |
} | |
.btn-danger { | |
background-color: var(--danger); | |
color: white; /* Texte blanc sur rouge */ | |
border-color: var(--danger); | |
} | |
.btn-danger:hover { | |
background-color: #d32f2f; /* Rouge plus foncé */ | |
color: white; | |
} | |
.btn-info { | |
background-color: var(--info); | |
color: var(--text-light); /* Texte clair sur fond gris */ | |
border-color: var(--info); | |
} | |
.btn-info:hover { | |
background-color: #5a6268; /* Gris plus foncé */ | |
color: var(--text-light); | |
} | |
input, select, textarea { | |
width: 100%; | |
padding: 0.7rem; /* Légèrement plus de padding */ | |
margin-bottom: 1rem; | |
background-color: #2a2a2a; | |
border: 1px solid #444; | |
border-radius: 4px; | |
color: var(--text-light); | |
font-size: 1rem; /* Taille de police standard */ | |
} | |
input:focus, select:focus, textarea:focus { | |
outline: none; | |
border-color: var(--accent); | |
box-shadow: 0 0 0 2px rgba(255, 193, 7, 0.3); /* Ombre focus jaune */ | |
} | |
input[type="checkbox"] { | |
width: auto; | |
margin-right: 0.5rem; | |
vertical-align: middle; | |
accent-color: var(--accent); /* Couleur de la coche */ | |
} | |
.card { | |
background-color: var(--bg-card); | |
border-radius: 8px; | |
padding: 1.2rem; /* Padding un peu plus grand */ | |
margin-bottom: 1rem; | |
box-shadow: 0 4px 8px rgba(0,0,0,0.3); /* Ombre un peu plus prononcée */ | |
} | |
.form-group { margin-bottom: 1rem; } | |
.form-row { display: flex; gap: 1rem; margin-bottom: 0.5rem; flex-wrap: wrap; } /* Espace augmenté */ | |
.form-row > * { flex: 1; margin-bottom: 0; min-width: 100px; } | |
label { | |
display: block; | |
margin-bottom: 0.4rem; /* Espace label/input */ | |
color: var(--text-secondary); | |
font-size: 0.9rem; | |
font-weight: bold; /* Labels en gras */ | |
} | |
/* Exercise styling */ | |
.exercise { | |
border-left: 4px solid var(--accent); /* Bordure accentuée */ | |
padding-left: 1rem; | |
margin-bottom: 1.5rem; | |
display: none; | |
background-color: rgba(0,0,0,0.1); /* Léger fond pour démarquer */ | |
padding: 1rem; /* Padding interne */ | |
border-radius: 0 4px 4px 0; | |
} | |
.exercise.active-exercise { display: block; animation: fadeIn 0.3s ease-in-out; } | |
.exercise-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; gap: 0.5rem;} | |
.exercise-header input { margin-bottom: 0; } | |
.series-container { margin-left: 0rem; margin-top: 1rem; } /* Pas de marge gauche superflue */ | |
.series { background-color: #282828; padding: 0.8rem; border-radius: 4px; margin-bottom: 0.8rem; border: 1px solid #333; } /* Style série amélioré */ | |
/* Nav Bottom */ | |
.nav-bottom { | |
position: fixed; bottom: 0; left: 0; width: 100%; | |
background-color: #1a1a1a; | |
display: flex; justify-content: space-around; | |
padding: 0.7rem 0; | |
box-shadow: 0 -3px 10px rgba(0,0,0,0.4); | |
z-index: 10; | |
} | |
.nav-item { | |
text-align: center; color: var(--text-secondary); | |
text-decoration: none; font-size: 0.85rem; | |
transition: color 0.2s; padding: 0 0.5rem; | |
} | |
.nav-item.active { color: var(--accent); font-weight: bold; } | |
.nav-icon { font-size: 1.5rem; margin-bottom: 0.2rem; } /* Icônes plus grandes */ | |
/* Workout Card */ | |
.workout-card { | |
border-left: 4px solid var(--accent); | |
cursor: pointer; | |
transition: transform 0.2s ease-out, box-shadow 0.2s ease-out; | |
position: relative; /* Pour positionner le badge date */ | |
} | |
.workout-card:hover { | |
transform: translateY(-3px); /* Légère lévitation */ | |
box-shadow: 0 6px 12px rgba(0,0,0,0.4); | |
} | |
.workout-header { display: flex; justify-content: space-between; align-items: flex-start; } | |
.workout-header h3 { color: var(--text-light); margin-bottom: 0.3rem; font-family: var(--font-primary); text-transform: none; letter-spacing: normal; font-weight: bold; } /* Nom séance normal */ | |
.workout-header .badge { position: absolute; top: 1rem; right: 1rem; background-color: var(--info); color: var(--text-light); } /* Badge date repositionné */ | |
.workout-details { font-size: 0.9rem; color: var(--text-secondary); margin-top: 0.8rem; } | |
.workout-details span { margin-right: 0.8rem; } | |
/* Stats */ | |
.stat-card { text-align: center; padding: 1rem; } | |
.stat-value { | |
font-size: 2rem; /* Taille augmentée */ | |
color: var(--accent); | |
font-weight: bold; | |
font-family: var(--font-headings); /* Police titre */ | |
margin-bottom: 0.3rem; | |
} | |
.stat-card div:last-child { color: var(--text-secondary); font-size: 0.9rem; } /* Label stat */ | |
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 1rem; } /* Min width augmentée */ | |
.hidden { display: none ; } /* Utilise !important pour forcer */ | |
#login-page { display: block; } | |
#main-app-content { display: none; } | |
#app-container > div:not(.active) { display: none ; } | |
.flex-between { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 1rem; } /* Espace augmenté */ | |
/* Badges */ | |
.badge { | |
background-color: var(--accent); | |
color: var(--text-on-accent); | |
padding: 0.3rem 0.6rem; /* Padding ajusté */ | |
border-radius: 12px; /* Plus arrondi */ | |
font-size: 0.8rem; | |
font-weight: bold; | |
white-space: nowrap; | |
margin-left: 5px; | |
} | |
.badge.type-badge { background-color: var(--neutral-white); color: var(--bg-dark); } /* Badge type en blanc (logo Fitness) */ | |
/* Spinner */ | |
.spinner { | |
border: 4px solid rgba(255, 255, 255, 0.1); | |
width: 36px; height: 36px; | |
border-radius: 50%; | |
border-left-color: var(--accent); /* Couleur accent pour spinner */ | |
animation: spin 1s linear infinite; | |
margin: 2rem auto; display: none; | |
} | |
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } | |
/* Exercise Summary in Details */ | |
.exercise-summary { | |
margin: 0.3rem 0; padding: 0.5rem 0; | |
border-bottom: 1px solid var(--border-color); | |
font-size: 0.9rem; | |
} | |
.exercise-summary:last-child { border-bottom: none; } | |
.series-summary-container .badge { font-size: 0.7rem; padding: 0.2rem 0.4rem; } /* Badges plus petits dans résumé */ | |
/* Satisfaction Slider */ | |
.satisfaction { display: flex; align-items: center; justify-content: center; flex-direction: column; margin-top: 1rem; } | |
input[type="range"] { accent-color: var(--accent); cursor: pointer;} | |
.satisfaction-value { font-size: 2.2rem; color: var(--accent); margin-top: 0.5rem; font-weight: bold; font-family: var(--font-headings); } | |
/* Exercise Navigation */ | |
.exercise-navigation { display: flex; justify-content: space-between; margin-top: 1.5rem; margin-bottom: 1.5rem; align-items: center;} | |
.exercise-navigation span { color: var(--text-secondary); font-style: italic; } | |
/* Login Page */ | |
#login-page .card { max-width: 400px; margin: 3rem auto; } | |
#login-page h2 { text-align: center; margin-bottom: 1.5rem; color: var(--accent); } | |
#login-error { color: var(--danger); text-align: center; margin-top: 1rem; font-size: 0.9rem; display: none; min-height: 1.2em; font-weight: bold; } | |
#login-form button { margin-top: 1rem; } | |
.auth-switch { text-align: center; margin-top: 1.5rem; font-size: 0.9rem; color: var(--text-secondary); } | |
.auth-switch a { color: var(--accent); cursor: pointer; text-decoration: underline; font-weight: bold; } | |
/* User Info */ | |
.user-info { text-align: right; margin-bottom: 1rem; font-size: 0.9rem; color: var(--text-secondary);} | |
.user-info strong { color: var(--text-light); margin: 0 5px; } | |
.user-info button { margin-left: 0.8rem; padding: 0.3rem 0.7rem; font-size: 0.8rem; } | |
/* Manage Types Page */ | |
#workout-types-list li { | |
display: flex; justify-content: space-between; align-items: center; | |
background-color: #2a2a2a; padding: 0.7rem 1rem; /* Padding augmenté */ | |
margin-bottom: 0.5rem; border-radius: 4px; | |
border-left: 4px solid var(--neutral-white); /* Bordure blanche */ | |
color: var(--text-light); font-weight: bold; | |
} | |
#add-type-form { display: flex; gap: 0.5rem; align-items: flex-end;} | |
#add-type-form input { margin-bottom: 0; flex-grow: 1;} | |
#add-type-form button { flex-shrink: 0; } | |
#add-type-error { color: var(--danger); font-size: 0.9rem; margin-top: 0.5rem; font-weight: bold; } | |
/* Select Workout Type Page */ | |
#select-workout-type-page .card { text-align: center; } | |
#select-workout-type-page .btn { margin-top: 1rem; width: 80%; } /* Boutons plus larges */ | |
#select-workout-type { margin-bottom: 1rem;} | |
/* Type Trend Card */ | |
.type-trend-card { margin-bottom: 1.5rem; } | |
.type-trend-card h4 { | |
/* Style titre appliqué par défaut */ | |
color: var(--neutral-white); /* Titre Tendance en Blanc */ | |
border-bottom: 1px solid var(--border-color); | |
padding-bottom: 0.5rem; margin-bottom: 1rem; | |
text-transform: uppercase; /* Garde uppercase pour section */ | |
} | |
.type-trend-card ul { list-style: none; padding: 0; font-size: 0.95rem; } | |
.type-trend-card li { margin-bottom: 0.6rem; color: var(--text-light); display: flex; justify-content: space-between; border-bottom: 1px dashed #333; padding-bottom: 0.4rem;} | |
.type-trend-card li:last-child { border-bottom: none; } | |
.type-trend-card li span:first-child { color: var(--text-secondary); font-size: 0.85rem; margin-right: 1rem; } /* Date */ | |
.type-trend-card li strong { color: var(--accent); } /* Tonnage en accent */ | |
/* Media Queries (inchangées pour la structure, mais les styles héritent) */ | |
@media (max-width: 600px) { | |
.container { padding: 0.8rem; } /* Plus de padding sur mobile */ | |
h1,h2 { font-size: 1.6rem; } | |
.form-row { flex-direction: column; gap: 0.8rem; } /* Plus d'espace en colonne */ | |
/* Ajustements spécifiques mobile si nécessaire */ | |
.flex-between { flex-direction: column; align-items: stretch; gap: 0.8rem; } | |
.flex-between > div { width: 100%; display: flex; justify-content: center; margin-top: 0.5rem;} /* Boutons centrés */ | |
.user-info { text-align: center; margin-bottom: 0.8rem;} | |
.user-info button { display: block; margin: 0.5rem auto 0;} | |
.exercise-navigation button { padding: 0.6rem; font-size: 0.9rem;} | |
#add-type-form { flex-direction: column; align-items: stretch;} | |
header img#app-logo { max-width: 200px; } /* Logo plus petit sur mobile */ | |
} | |
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } } | |
</style> | |
</head> | |
<body> | |
<div class="container"> | |
<!-- Header modifié avec le logo --> | |
<header> | |
<img src="input_file_0.png" alt="Cocktail Fitness Logo" id="app-logo"> | |
<p>Votre suivi de séances personnalisé</p> <!-- Slogan mis à jour --> | |
</header> | |
<!-- Login Page (structure inchangée, styles appliqués) --> | |
<div id="login-page"> | |
<div class="card"> | |
<h2 id="auth-title">Connexion</h2> | |
<form id="login-form"> | |
<div class="form-group"> <label for="auth-email">Email</label> <input type="email" id="auth-email" placeholder="[email protected]" required> </div> | |
<div class="form-group"> <label for="auth-password">Mot de passe</label> <input type="password" id="auth-password" placeholder="********" required> </div> | |
<p id="login-error"></p> | |
<button type="submit" id="auth-action-btn" class="btn" style="width: 100%;">Se Connecter</button> | |
</form> | |
<div class="auth-switch"> <span id="auth-switch-text">Pas encore de compte ?</span> <a id="auth-switch-link">Inscrivez-vous ici</a> </div> | |
</div> | |
</div> | |
<!-- Main App Content (structure inchangée) --> | |
<div id="main-app-content"> | |
<div class="user-info"> | |
Connecté: <strong id="current-user-display"></strong> | |
<button id="logout-btn" class="btn btn-outline">Déconnexion</button> | |
</div> | |
<div id="app-container"> | |
<!-- Home Page --> | |
<div id="home-page" class="active"> | |
<div class="flex-between"> | |
<h2>Mes séances</h2> | |
<div> | |
<button id="manage-types-btn" class="btn btn-outline" style="margin-right: 0.5rem;">Gérer Types</button> | |
<button id="new-workout-btn" class="btn">Nouvelle séance</button> | |
</div> | |
</div> | |
<div id="workouts-list" class="workout-list" style="margin-top: 1.5rem;"> | |
<div class="spinner hidden"></div> | |
<p id="empty-workout-message" class="hidden" style="text-align: center; margin-top: 2rem; color: var(--text-secondary);"> Aucune séance enregistrée. </p> | |
</div> | |
</div> | |
<!-- Manage Types Page --> | |
<div id="manage-types-page"> | |
<div class="flex-between"> | |
<h2>Gérer les Types</h2> | |
<button class="btn btn-outline back-to-home-btn">Retour</button> | |
</div> | |
<div class="card"> | |
<h3>Types Existants</h3> | |
<ul id="workout-types-list" style="list-style: none; padding: 0; margin-top: 1rem;"> | |
<li class="hidden" id="empty-types-message" style="color: var(--text-secondary); background: none; border: none; padding-left: 0;">Aucun type défini.</li> | |
</ul> | |
<div class="spinner hidden" id="types-spinner"></div> | |
</div> | |
<div class="card"> | |
<h3>Ajouter un Type</h3> | |
<form id="add-type-form"> | |
<input type="text" id="new-type-name" placeholder="Nom (ex: Push, Pull, Legs)" required> | |
<button type="submit" class="btn">Ajouter</button> | |
</form> | |
<p id="add-type-error"></p> | |
</div> | |
</div> | |
<!-- Select Workout Type Page --> | |
<div id="select-workout-type-page"> | |
<div class="flex-between"> | |
<h2>Démarrer Séance</h2> | |
<button class="btn btn-outline back-to-home-btn">Annuler</button> | |
</div> | |
<div class="card"> | |
<h3>Séance Structurée</h3> | |
<select id="select-workout-type"> | |
<option value="">-- Sélectionner Type --</option> | |
</select> | |
<button id="start-structured-workout-btn" class="btn" disabled>Démarrer</button> | |
</div> | |
<div class="card"> | |
<h3>Séance Libre</h3> | |
<button id="start-free-workout-btn" class="btn btn-info">Démarrer Libre</button> | |
</div> | |
</div> | |
<!-- New Workout Page --> | |
<div id="new-workout-page"> | |
<div class="flex-between"> | |
<h2>Nouvelle séance <span id="workout-type-indicator" class="badge type-badge hidden"></span> <span id="current-exercise-indicator" style="font-size: 0.9rem; color: var(--text-secondary); text-transform: none; font-family: var(--font-primary);"></span></h2> | |
<div> | |
<button id="cancel-new-workout-btn" class="btn btn-outline" style="margin-right: 0.5rem;">Annuler</button> | |
<button id="save-workout-btn" class="btn">Enregistrer</button> | |
</div> | |
</div> | |
<div class="card"> | |
<div class="form-group"> <label for="workout-name">Nom Séance (optionnel)</label> <input type="text" id="workout-name" placeholder="Ex: Séance Haut du Corps..."> </div> | |
<div class="form-row"> | |
<div class="form-group"> <label for="workout-date">Date</label> <input type="date" id="workout-date"> </div> | |
<div class="form-group"> <label for="workout-duration">Durée (min)</label> <input type="number" id="workout-duration" min="1" placeholder="60"> </div> | |
</div> | |
</div> | |
<h3 style="margin: 1.5rem 0;">Exercices</h3> | |
<div class="exercise-navigation card"> | |
<button id="prev-exercise-btn" class="btn btn-outline">< Précédent</button> | |
<span style="align-self: center; color: var(--text-secondary);">Exercice Actif</span> | |
<button id="next-exercise-btn" class="btn btn-outline">Suivant ></button> | |
</div> | |
<div id="exercises-container"> <!-- Exercices injected here --> </div> | |
<button id="add-exercise-btn" class="btn btn-outline" style="width: 100%; margin-top: 1rem;">+ Ajouter Exercice</button> | |
<div class="card" style="margin-top: 2rem;"> | |
<div class="form-group"> | |
<label for="satisfaction">Satisfaction (1-100%)</label> | |
<input type="range" id="satisfaction" min="1" max="100" value="75"> | |
<div class="satisfaction"> <div class="satisfaction-value">75%</div> </div> | |
</div> | |
</div> | |
</div> | |
<!-- Workout Details Page --> | |
<div id="workout-details-page"> | |
<div class="flex-between"> | |
<h2>Détail Séance <span id="detail-workout-type" class="badge type-badge hidden"></span></h2> | |
<button class="btn btn-outline back-to-home-btn">Retour</button> | |
</div> | |
<div class="card"> | |
<div class="workout-details-info"> | |
<p><strong>Nom:</strong> <span id="detail-workout-name" style="color: var(--text-light); font-weight: normal;"></span></p> | |
<div class="form-row" style="margin-top: 0.5rem;"> | |
<p><strong>Date:</strong> <span id="detail-date" style="color: var(--text-light); font-weight: normal;"></span></p> | |
<p><strong>Durée:</strong> <span id="detail-duration" style="color: var(--text-light); font-weight: normal;"></span> min</p> | |
</div> | |
</div> | |
</div> | |
<div class="stats-grid" style="margin-top: 1.5rem;"> | |
<div class="card stat-card"> <div class="stat-value" id="detail-tonnage">0</div> <div>Tonnage (kg)</div> </div> | |
<div class="card stat-card"> <div class="stat-value" id="detail-satisfaction">0%</div> <div>Satisfaction</div> </div> | |
<div class="card stat-card"> <div class="stat-value" id="detail-exercises-count">0</div> <div>Exercices</div> </div> | |
</div> | |
<h3 style="margin: 1.5rem 0 1rem;">Exercices Réalisés</h3> | |
<div id="detail-exercises-container"> <!-- Details injected here --> </div> | |
<button id="delete-workout-btn" class="btn btn-danger" style="width: 100%; margin-top: 2rem;">Supprimer Séance</button> | |
</div> | |
<!-- Stats Page --> | |
<div id="stats-page"> | |
<h2>Statistiques Générales</h2> | |
<div class="stats-grid"> | |
<div class="card stat-card"> <div class="stat-value" id="stats-workout-count">0</div> <div>Séances Totales</div> </div> | |
<div class="card stat-card"> <div class="stat-value" id="stats-avg-tonnage">0</div> <div>Tonnage Moyen / Séance</div> </div> | |
<div class="card stat-card"> <div class="stat-value" id="stats-avg-satisfaction">0%</div> <div>Satisfaction Moyenne</div> </div> | |
</div> | |
<h3 style="margin: 2rem 0 1rem;">Tendances par Type</h3> | |
<div id="type-trends-container"> | |
<p id="no-trends-message" style="text-align: center; color: var(--text-secondary);" class="hidden"> Pas assez de données pour afficher les tendances par type. </p> | |
<div class="spinner hidden" id="trends-spinner"></div> | |
<!-- Trends injected here --> | |
</div> | |
</div> | |
</div> <!-- Fin #app-container --> | |
<!-- Bottom Navigation --> | |
<nav class="nav-bottom"> | |
<a href="#" class="nav-item active" data-page="home-page"> <div class="nav-icon">📋</div> <div>Séances</div> </a> | |
<a href="#" class="nav-item" data-page="stats-page"> <div class="nav-icon">📊</div> <div>Stats</div> </a> | |
</nav> | |
</div> <!-- Fin #main-app-content --> | |
</div> <!-- Fin .container --> | |
<!-- JavaScript (Identique à l'original, sauf mentions textuelles si besoin) --> | |
<script> | |
// Firebase Init (Identique) | |
const firebaseConfig = { apiKey: "AIzaSyAkWvrRyXgrC7zbTtoh_GppsHMrz2rF7WM", authDomain: "lifttrackapp.firebaseapp.com", projectId: "lifttrackapp", storageBucket: "lifttrackapp.appspot.com", messagingSenderId: "594426771796", appId: "1:594426771796:web:789bef037ca0016c54b0c1", measurementId: "G-MXLFK0H160" }; | |
let app, auth, db; try { app = firebase.initializeApp(firebaseConfig); auth = firebase.auth(); db = firebase.firestore(); console.log("Firebase Initialisé !"); } catch (e) { console.error("Erreur Init Firebase:", e); alert("Erreur connexion DB."); } | |
// --- Variables d'État --- (Inchangé) | |
let workouts = []; let currentWorkoutId = null; let currentExerciseIndex = 0; let workoutExercisesForm = []; let currentFirebaseUser = null; let userWorkoutTypes = []; let selectedWorkoutTypeName = null; | |
// --- Éléments DOM --- (Inchangé, les variables pointeront toujours vers les bons ID) | |
const loginPage = document.getElementById('login-page'); const mainAppContent = document.getElementById('main-app-content'); const authEmailInput = document.getElementById('auth-email'); const authPasswordInput = document.getElementById('auth-password'); const loginForm = document.getElementById('login-form'); const authActionButton = document.getElementById('auth-action-btn'); const authSwitchLink = document.getElementById('auth-switch-link'); const authTitle = document.getElementById('auth-title'); const authSwitchText = document.getElementById('auth-switch-text'); const loginError = document.getElementById('login-error'); const currentUserDisplay = document.getElementById('current-user-display'); const logoutBtn = document.getElementById('logout-btn'); const spinner = document.querySelector('#workouts-list .spinner'); const appContainer = document.getElementById('app-container'); const navItems = document.querySelectorAll('.nav-item'); const newWorkoutBtn = document.getElementById('new-workout-btn'); const saveWorkoutBtn = document.getElementById('save-workout-btn'); const cancelNewWorkoutBtn = document.getElementById('cancel-new-workout-btn'); const addExerciseBtn = document.getElementById('add-exercise-btn'); const exercisesContainer = document.getElementById('exercises-container'); const workoutsList = document.getElementById('workouts-list'); const backToHomeBtns = document.querySelectorAll('.back-to-home-btn'); const deleteWorkoutBtn = document.getElementById('delete-workout-btn'); const satisfactionRange = document.getElementById('satisfaction'); const satisfactionValue = document.querySelector('.satisfaction-value'); const emptyWorkoutMessage = document.getElementById('empty-workout-message'); const workoutDateInput = document.getElementById('workout-date'); const prevExerciseBtn = document.getElementById('prev-exercise-btn'); const nextExerciseBtn = document.getElementById('next-exercise-btn'); const currentExerciseIndicator = document.getElementById('current-exercise-indicator'); const workoutTypeIndicator = document.getElementById('workout-type-indicator'); const detailWorkoutType = document.getElementById('detail-workout-type'); const manageTypesBtn = document.getElementById('manage-types-btn'); const manageTypesPage = document.getElementById('manage-types-page'); const workoutTypesList = document.getElementById('workout-types-list'); const emptyTypesMessage = document.getElementById('empty-types-message'); const typesSpinner = document.getElementById('types-spinner'); const addTypeForm = document.getElementById('add-type-form'); const newTypeNameInput = document.getElementById('new-type-name'); const addTypeError = document.getElementById('add-type-error'); const selectWorkoutTypePage = document.getElementById('select-workout-type-page'); const selectWorkoutTypeDropdown = document.getElementById('select-workout-type'); const startStructuredWorkoutBtn = document.getElementById('start-structured-workout-btn'); const startFreeWorkoutBtn = document.getElementById('start-free-workout-btn'); | |
const statsWorkoutCountEl = document.getElementById('stats-workout-count'); const statsAvgTonnageEl = document.getElementById('stats-avg-tonnage'); const statsAvgSatisfactionEl = document.getElementById('stats-avg-satisfaction'); | |
const typeTrendsContainer = document.getElementById('type-trends-container'); | |
const noTrendsMessage = document.getElementById('no-trends-message'); | |
const trendsSpinner = document.getElementById('trends-spinner'); | |
let isLoginMode = true; | |
// =========================================== | |
// --- DÉFINITION DES FONCTIONS --- (JavaScript Inchangé) | |
// =========================================== | |
function initAuthListener() { /* ... */ if (!auth) return; auth.onAuthStateChanged(user => { console.log("Auth state:", user ? user.uid : 'null'); if (user) { currentFirebaseUser = user; showApp(); } else { currentFirebaseUser = null; workouts = []; userWorkoutTypes = []; renderWorkoutsList(); renderWorkoutTypesList(); showLoginPage(); } }); } | |
function showLoginPage() { /* ... */ if(loginPage) loginPage.style.display = 'block'; if(mainAppContent) mainAppContent.style.display = 'none'; } | |
function showApp() { /* ... */ if (!currentFirebaseUser || !mainAppContent) return; console.log("Affichage App"); if(loginPage) loginPage.style.display = 'none'; mainAppContent.style.display = 'block'; if(currentUserDisplay) currentUserDisplay.textContent = currentFirebaseUser.email; setTodayDate(); loadWorkouts(); loadWorkoutTypes(); showPage('home-page'); } | |
function handleAuthAction(event) { /* ... */ if(!auth) return; event.preventDefault(); const email = authEmailInput.value; const password = authPasswordInput.value; loginError.textContent = ''; if (!email || !password) { loginError.textContent = 'Email et Mot de passe requis.'; return; } authActionButton.disabled = true; authActionButton.textContent = 'Chargement...'; if (isLoginMode) { auth.signInWithEmailAndPassword(email, password).catch(handleAuthError).finally(() => { authActionButton.disabled = false; authActionButton.textContent = 'Se Connecter'; }); } else { auth.createUserWithEmailAndPassword(email, password).catch(handleAuthError).finally(() => { authActionButton.disabled = false; authSwitchMode(); authActionButton.textContent = 'S\'inscrire'; }); } } | |
function handleLogout() { /* ... */ if(!auth) return; console.log("Déconnexion..."); auth.signOut().catch(handleAuthError); } | |
function authSwitchMode() { /* ... */ isLoginMode = !isLoginMode; loginError.textContent = ''; authTitle.textContent=isLoginMode?'Connexion':'Inscription'; authActionButton.textContent=isLoginMode?'Se Connecter':'S\'inscrire'; authSwitchText.textContent=isLoginMode?'Pas de compte ?':'Déjà un compte ?'; authSwitchLink.textContent=isLoginMode?'Inscrivez-vous':'Connectez-vous'; } | |
function handleAuthError(error) { /* ... */ console.error("Erreur Auth:", error); loginError.textContent = getAuthErrorMessage(error); } | |
function getAuthErrorMessage(error) { /* ... */ switch (error.code) { case 'auth/invalid-email': return 'Format d\'email invalide.'; case 'auth/user-disabled': return 'Ce compte utilisateur a été désactivé.'; case 'auth/user-not-found': return 'Aucun utilisateur trouvé avec cet email.'; case 'auth/wrong-password': return 'Mot de passe incorrect.'; case 'auth/email-already-in-use': return 'Cet email est déjà utilisé par un autre compte.'; case 'auth/weak-password': return 'Le mot de passe est trop faible (minimum 6 caractères).'; case 'auth/operation-not-allowed': return 'Connexion par email/mot de passe non activée.'; default: return 'Erreur d\'authentification. Veuillez réessayer.'; } } | |
function loadWorkoutTypes() { /* ... */ if (!currentFirebaseUser || !db) return; const userId = currentFirebaseUser.uid; console.log("Chargement types..."); userWorkoutTypes = []; if (typesSpinner) typesSpinner.classList.remove('hidden'); db.collection('workoutTypes').where('userId', '==', userId).orderBy('name').get().then(snapshot => { snapshot.forEach(doc => userWorkoutTypes.push({ id: doc.id, ...doc.data() })); console.log("Types chargés:", userWorkoutTypes); renderWorkoutTypesList(); populateWorkoutTypeSelector(); }).catch(handleFirestoreError).finally(() => { if (typesSpinner) typesSpinner.classList.add('hidden'); }); } | |
function renderWorkoutTypesList() { /* ... */ if (!workoutTypesList) return; workoutTypesList.innerHTML = ''; if (userWorkoutTypes.length === 0) { if(emptyTypesMessage) emptyTypesMessage.classList.remove('hidden'); } else { if(emptyTypesMessage) emptyTypesMessage.classList.add('hidden'); userWorkoutTypes.forEach(type => { const li = document.createElement('li'); li.textContent = type.name; /* Bouton Supprimer peut être ajouté ici si besoin */ workoutTypesList.appendChild(li); }); } } | |
function handleAddWorkoutType(event) { /* ... */ event.preventDefault(); if (!currentFirebaseUser || !newTypeNameInput || !db) return; const typeName = newTypeNameInput.value.trim(); addTypeError.textContent = ''; if (!typeName) { addTypeError.textContent = "Le nom du type ne peut pas être vide."; return; } if (userWorkoutTypes.some(t => t.name.toLowerCase() === typeName.toLowerCase())) { addTypeError.textContent = "Ce type de séance existe déjà."; return; } console.log("Ajout type:", typeName); const typeData = { userId: currentFirebaseUser.uid, name: typeName }; db.collection('workoutTypes').add(typeData).then(() => { console.log("Type ajouté avec succès"); newTypeNameInput.value = ''; loadWorkoutTypes(); }).catch(handleFirestoreError); } | |
function populateWorkoutTypeSelector() { /* ... */ if (!selectWorkoutTypeDropdown) return; selectWorkoutTypeDropdown.innerHTML = '<option value="">-- Sélectionner Type --</option>'; userWorkoutTypes.forEach(type => { const option = document.createElement('option'); option.value = type.name; option.textContent = type.name; selectWorkoutTypeDropdown.appendChild(option); }); updateStartStructuredBtnState(); } | |
function updateStartStructuredBtnState() { /* ... */ if (!selectWorkoutTypeDropdown || !startStructuredWorkoutBtn) return; startStructuredWorkoutBtn.disabled = !selectWorkoutTypeDropdown.value; } | |
function loadWorkouts() { /* ... */ if (!currentFirebaseUser || !db) { console.log("Chargement séances annulé (non connecté)."); workouts = []; renderWorkoutsList(); /* Pas besoin de showPage ici, géré par auth listener */ return; } const userId = currentFirebaseUser.uid; console.log(`Chargement séances pour ${userId}...`); if (spinner) spinner.classList.remove('hidden'); if(emptyWorkoutMessage) emptyWorkoutMessage.classList.add('hidden'); if(workoutsList) workoutsList.innerHTML = ''; workouts = []; db.collection('workouts').where('userId', '==', userId).orderBy('date', 'desc').get().then((querySnapshot) => { console.log(`${querySnapshot.size} séances trouvées.`); querySnapshot.forEach((doc) => { const workoutData = doc.data(); workoutData.firestoreId = doc.id; workouts.push(workoutData); }); renderWorkoutsList(); updateStats(); /* MAJ stats après chargement */ }).catch(handleFirestoreError).finally(() => { if (spinner) spinner.classList.add('hidden'); }); } | |
function saveWorkout() { /* ... */ if (!currentFirebaseUser || !db) { alert("Vous devez être connecté pour enregistrer."); return; } const userId = currentFirebaseUser.uid; workoutExercisesForm = Array.from(exercisesContainer.querySelectorAll('.exercise')); const workoutNameInput = document.getElementById('workout-name'); const workoutName = workoutNameInput ? workoutNameInput.value.trim() : ''; const workoutDate = workoutDateInput.value; const workoutDurationInput = document.getElementById('workout-duration'); const workoutDuration = workoutDurationInput ? parseInt(workoutDurationInput.value) || 0 : 0; const satisfaction = satisfactionRange ? parseInt(satisfactionRange.value) : 75; if (!selectedWorkoutTypeName) { alert("Erreur : Type de séance non défini. Veuillez recommencer."); showPage('home-page'); return; } if (!workoutDate) { alert("Veuillez sélectionner une date pour la séance."); if(workoutDateInput) workoutDateInput.focus(); return; } if (workoutDuration <= 0) { alert("Veuillez entrer une durée valide pour la séance."); if(workoutDurationInput) workoutDurationInput.focus(); return; } const exerciseElements = workoutExercisesForm; const exercises = []; if (exerciseElements.length === 0) { alert("Veuillez ajouter au moins un exercice à votre séance."); return; } let validationError = null; exerciseElements.forEach((exerciseEl, index) => { if (validationError) return; const nameInput = exerciseEl.querySelector('.exercise-name'); const exerciseName = nameInput ? nameInput.value.trim() : ''; const unilateralCheckbox = exerciseEl.querySelector('.unilateral-checkbox'); const isUnilateral = unilateralCheckbox ? unilateralCheckbox.checked : false; if (!exerciseName) { validationError = `Veuillez nommer l'exercice #${index + 1}.`; if(nameInput) nameInput.focus(); return; } const series = []; const seriesElements = exerciseEl.querySelectorAll('.series'); if (seriesElements.length === 0) { validationError = `L'exercice "${exerciseName}" doit contenir au moins une série.`; return; } seriesElements.forEach((seriesEl, sIndex) => { if (validationError) return; const repsInput = seriesEl.querySelector('.reps'); const weightInput = seriesEl.querySelector('.weight'); const degressiveCheckbox = seriesEl.querySelector('.degressive-checkbox'); const reps = repsInput ? parseInt(repsInput.value) || 0 : 0; const weight = weightInput ? parseFloat(weightInput.value) || 0 : 0; const isDegressive = degressiveCheckbox ? degressiveCheckbox.checked : false; if (reps <= 0) { validationError = `Nombre de répétitions invalide pour la série ${sIndex + 1} de l'exercice "${exerciseName}".`; if(repsInput) repsInput.focus(); return; } if (weight < 0) { validationError = `La charge ne peut pas être négative pour la série ${sIndex + 1} de l'exercice "${exerciseName}".`; if(weightInput) weightInput.focus(); return; } series.push({ reps, weight, isDegressive }); }); if (!validationError) { exercises.push({ name: exerciseName, isUnilateral, series }); } }); if (validationError) { alert(validationError); return; } let totalTonnage = 0; exercises.forEach(ex => ex.series.forEach(s => totalTonnage += s.reps * s.weight * (ex.isUnilateral ? 2 : 1))); const finalWorkoutName = workoutName || selectedWorkoutTypeName; const workout = { id: currentWorkoutId || db.collection('workouts').doc().id, /* Génère ID Firestore */ userId: userId, workoutTypeName: selectedWorkoutTypeName, name: finalWorkoutName, date: workoutDate, duration: workoutDuration, exercises: exercises, totalTonnage: totalTonnage, satisfaction: satisfaction }; console.log("Sauvegarde de la séance:", workout); saveWorkoutBtn.disabled = true; saveWorkoutBtn.textContent = 'Sauvegarde...'; db.collection('workouts').doc(workout.id).set(workout).then(() => { console.log("Séance sauvegardée avec succès:", workout.id); const existingIndex = workouts.findIndex(w => w.id === workout.id); if (existingIndex > -1) workouts[existingIndex] = workout; else workouts.push(workout); try { confetti({ particleCount: 150, spread: 90, origin: { y: 0.6 } }); } catch(e) { console.warn("Confetti error:", e)} showPage('home-page'); loadWorkouts(); // Recharger pour être sûr et màj stats }).catch(handleFirestoreError).finally(() => { saveWorkoutBtn.disabled = false; saveWorkoutBtn.textContent = 'Enregistrer Séance'; }); } | |
function deleteWorkout() { /* ... */ if (!currentFirebaseUser || !currentWorkoutId || !db) return; const workoutToDelete = workouts.find(w => w.id === currentWorkoutId); if (!workoutToDelete) { console.error("Séance à supprimer non trouvée localement."); return; } const confirmDelete = confirm(`Êtes-vous sûr de vouloir supprimer la séance "${workoutToDelete.name}" du ${new Date(workoutToDelete.date).toLocaleDateString('fr-FR')} ? Cette action est irréversible.`); if (!confirmDelete) return; console.log("Suppression de la séance:", currentWorkoutId); deleteWorkoutBtn.disabled = true; deleteWorkoutBtn.textContent = 'Suppression...'; db.collection('workouts').doc(currentWorkoutId).delete().then(() => { console.log("Séance supprimée avec succès:", currentWorkoutId); workouts = workouts.filter(w => w.id !== currentWorkoutId); currentWorkoutId = null; showPage('home-page'); renderWorkoutsList(); updateStats(); }).catch(handleFirestoreError).finally(() => { deleteWorkoutBtn.disabled = false; deleteWorkoutBtn.textContent = 'Supprimer Séance'; }); } | |
function setTodayDate() { /* ... */ if(workoutDateInput) try { workoutDateInput.value = new Date().toISOString().split('T')[0]; } catch(e){ console.error("Erreur lors de la définition de la date:", e); }} | |
function showPage(pageId) { /* ... */ console.log(`Affichage page: ${pageId}`); if (!currentFirebaseUser && pageId !== 'login-page') { console.log("Non connecté, redirection vers login."); showLoginPage(); return; } document.querySelectorAll('#app-container > div').forEach(page => page.classList.remove('active')); const pageToShow = document.getElementById(pageId); if (pageToShow) { pageToShow.classList.add('active'); window.scrollTo(0, 0); // Scroll en haut de page if (pageId === 'new-workout-page') { if (!selectedWorkoutTypeName) { console.warn("Entrée sur new-workout-page sans type sélectionné, retour home."); showPage('home-page'); return; } /* triggerFlameAnimation(); // Optionnel */ renderActiveExerciseForm(); updateWorkoutTypeIndicator(); } if (pageId === 'manage-types-page') { loadWorkoutTypes(); } if (pageId === 'select-workout-type-page') { populateWorkoutTypeSelector(); } if (pageId === 'stats-page') { updateStats(); } if (pageId === 'workout-details-page' && !currentWorkoutId) { console.warn("Tentative d'accès détails sans ID, retour home."); showPage('home-page'); return; } } else { console.error(`Page ID "${pageId}" non trouvée. Retour à l'accueil.`); document.getElementById('home-page').classList.add('active'); pageId = 'home-page'; } navItems.forEach(item => { item.classList.remove('active'); }); /* Correction: Ne pas se baser que sur stats-page pour la nav */ const currentPageForNav = ['home-page', 'manage-types-page', 'select-workout-type-page', 'new-workout-page', 'workout-details-page'].includes(pageId) ? 'home-page' : pageId; const activeNavItem = document.querySelector(`.nav-item[data-page="${currentPageForNav}"]`); if(activeNavItem) activeNavItem.classList.add('active'); } | |
function triggerFlameAnimation() { /* ... */ const duration = 1 * 1000; const animationEnd = Date.now() + duration; const defaults = { startVelocity: 30, spread: 360, ticks: 60, zIndex: 0 }; function randomInRange(min, max) { return Math.random() * (max - min) + min; } const interval = setInterval(function() { const timeLeft = animationEnd - Date.now(); if (timeLeft <= 0) return clearInterval(interval); const particleCount = 50 * (timeLeft / duration); try{ confetti(Object.assign({}, defaults, { particleCount, origin: { x: randomInRange(0.3, 0.7), y: Math.random() - 0.2 }, angle: randomInRange(240, 300), spread: randomInRange(50, 90), gravity: 0.5, drift: randomInRange(-1, 1), colors: ['#ff6f00', '#ff8f00', '#ffa000', '#ffcc00'] })); } catch(e){console.warn("Confetti error:", e); clearInterval(interval);} }, 250); } | |
function handleAddNewExercise() { /* ... */ addExercise(true); } | |
function addExercise(navigateToNew = false) { /* ... */ if (!currentFirebaseUser) return; const exerciseId = `exercise-${Date.now()}`; const exerciseDiv = document.createElement('div'); exerciseDiv.className = 'card exercise'; // Ajout classe card pour style cohérent exerciseDiv.setAttribute('data-exercise-id', exerciseId); exerciseDiv.innerHTML = `<div class="exercise-header"> <input type="text" placeholder="Nom Exercice (ex: Développé Couché)" class="exercise-name"> <button class="btn btn-danger remove-exercise" style="padding: 0.3rem 0.6rem; flex-shrink: 0;">×</button> </div> <div class="form-group" style="margin-top: 0.5rem; margin-bottom: 0.5rem;"> <label style="display: inline-flex; align-items: center; color: var(--text-secondary); font-size: 0.9rem; font-weight: normal;"> <input type="checkbox" class="unilateral-checkbox"> Unilatéral ? </label> </div> <div class="series-container"></div> <button class="btn btn-outline add-series" style="width: 100%; margin-top: 1rem; padding: 0.4rem;">+ Ajouter Série</button>`; // Bouton série style cohérent exercisesContainer.appendChild(exerciseDiv); workoutExercisesForm = Array.from(exercisesContainer.querySelectorAll('.exercise')); const removeBtn = exerciseDiv.querySelector('.remove-exercise'); removeBtn.addEventListener('click', () => { const indexToRemove = workoutExercisesForm.findIndex(el => el === exerciseDiv); if (indexToRemove > -1) { exerciseDiv.remove(); workoutExercisesForm.splice(indexToRemove, 1); // Mettre à jour le tableau interne if (currentExerciseIndex >= indexToRemove && currentExerciseIndex > 0) { currentExerciseIndex--; // Décrémenter si on supprime avant ou l'actuel (sauf si c'est le premier) } if (currentExerciseIndex >= workoutExercisesForm.length) { // Si on a supprimé le dernier currentExerciseIndex = Math.max(0, workoutExercisesForm.length - 1); } renderActiveExerciseForm(); // Rafraîchir la vue } }); const addSeriesBtn = exerciseDiv.querySelector('.add-series'); const seriesContainer = exerciseDiv.querySelector('.series-container'); addSeriesBtn.addEventListener('click', () => addSeries(seriesContainer)); addSeries(seriesContainer); // Ajoute une série par défaut if (navigateToNew) { currentExerciseIndex = workoutExercisesForm.length - 1; renderActiveExerciseForm(); // Focus sur le nouvel exercice ajouté } else { updateExerciseNavButtons(); // Met à jour juste les boutons si on n'a pas navigué } } | |
function addSeries(container) { /* ... */ if (!currentFirebaseUser || !container) return; const seriesId = `series-${Date.now()}`; const seriesDiv = document.createElement('div'); seriesDiv.className = 'series'; seriesDiv.setAttribute('data-series-id', seriesId); seriesDiv.innerHTML = `<div class="form-row" style="align-items: flex-end; gap: 0.8rem;"> <div class="form-group" style="flex: 1.2;"> <label style="font-weight: normal; font-size: 0.8rem;">Reps</label> <input type="number" class="reps" min="1" placeholder="10" style="padding: 0.5rem;"> </div> <div class="form-group" style="flex: 1.2;"> <label style="font-weight: normal; font-size: 0.8rem;">Charge (kg)</label> <input type="number" class="weight" min="0" step="0.1" placeholder="20" style="padding: 0.5rem;"> </div> <div class="form-group" style="flex: 1; display: flex; align-items: center; padding-bottom: 0.8rem; min-width: 100px;"> <label style="display: inline-flex; align-items: center; color: var(--text-secondary); font-size: 0.8rem; margin-bottom: 0; white-space: nowrap; font-weight: normal;"> <input type="checkbox" class="degressive-checkbox" style="margin-right: 0.3rem;"> Dégressive </label> </div> <button class="btn btn-danger remove-series" style="padding: 0.3rem 0.6rem; margin-bottom: 0.8rem; flex-basis: 30px; flex-grow: 0; align-self: center;" aria-label="Supprimer série">×</button> </div>`; container.appendChild(seriesDiv); const removeBtn = seriesDiv.querySelector('.remove-series'); removeBtn.addEventListener('click', () => seriesDiv.remove()); } | |
function navigateExerciseForm(direction) { /* ... */ workoutExercisesForm = Array.from(exercisesContainer.querySelectorAll('.exercise')); const newIndex = currentExerciseIndex + direction; if (newIndex >= 0 && newIndex < workoutExercisesForm.length) { currentExerciseIndex = newIndex; renderActiveExerciseForm(); } } | |
function renderActiveExerciseForm() { /* ... */ workoutExercisesForm = Array.from(exercisesContainer.querySelectorAll('.exercise')); workoutExercisesForm.forEach((ex, index) => { if (index === currentExerciseIndex) { ex.classList.add('active-exercise'); ex.style.display = 'block'; // Assure la visibilité } else { ex.classList.remove('active-exercise'); ex.style.display = 'none'; // Cache les inactifs } }); updateExerciseNavButtons(); } | |
function updateExerciseNavButtons() { /* ... */ const totalExercises = workoutExercisesForm.length; if (!currentExerciseIndicator || !prevExerciseBtn || !nextExerciseBtn) return; if (totalExercises === 0) { currentExerciseIndicator.textContent = "(Aucun exercice)"; prevExerciseBtn.disabled = true; nextExerciseBtn.disabled = true; } else { currentExerciseIndicator.textContent = `(${currentExerciseIndex + 1} / ${totalExercises})`; prevExerciseBtn.disabled = currentExerciseIndex === 0; nextExerciseBtn.disabled = currentExerciseIndex === totalExercises - 1; } } | |
function clearNewWorkoutForm(typeName = "Libre") { /* ... */ console.log("Nettoyage formulaire pour type:", typeName); if (!currentFirebaseUser) return; selectedWorkoutTypeName = typeName; const workoutNameInput = document.getElementById('workout-name'); if(workoutNameInput) workoutNameInput.value = (typeName === "Libre" ? "" : typeName); if(workoutDateInput) setTodayDate(); const durationInput = document.getElementById('workout-duration'); if(durationInput) durationInput.value = '60'; // Default 60 min if(exercisesContainer) exercisesContainer.innerHTML = ''; workoutExercisesForm = []; if(satisfactionRange) satisfactionRange.value = 75; if(satisfactionValue) satisfactionValue.textContent = '75%'; currentWorkoutId = null; // Assure qu'on crée un nouveau workout currentExerciseIndex = 0; addExercise(false); // Ajoute le premier exercice sans naviguer updateWorkoutTypeIndicator(); renderActiveExerciseForm(); } | |
function updateWorkoutTypeIndicator() { /* ... */ if (!workoutTypeIndicator) return; if (selectedWorkoutTypeName && selectedWorkoutTypeName !== "Libre") { workoutTypeIndicator.textContent = selectedWorkoutTypeName; workoutTypeIndicator.classList.remove('hidden'); } else { workoutTypeIndicator.classList.add('hidden'); } } | |
function renderWorkoutsList() { /* ... */ if (!currentFirebaseUser || !workoutsList || !emptyWorkoutMessage) { if(workoutsList) workoutsList.innerHTML = ''; if(emptyWorkoutMessage) emptyWorkoutMessage.classList.remove('hidden'); console.warn("Impossible de rendre la liste: user non connecté ou éléments DOM manquants."); updateStats(); // Mettre à jour les stats même si la liste est vide return; } workoutsList.innerHTML = ''; if (workouts.length === 0) { emptyWorkoutMessage.classList.remove('hidden'); } else { emptyWorkoutMessage.classList.add('hidden'); const sortedWorkouts = [...workouts].sort((a, b) => new Date(b.date) - new Date(a.date)); sortedWorkouts.forEach(workout => { const workoutDate = new Date(workout.date).toLocaleDateString('fr-FR', { year: 'numeric', month: 'short', day: 'numeric' }); const workoutDiv = document.createElement('div'); workoutDiv.className = 'card workout-card'; workoutDiv.setAttribute('data-workout-id', workout.id); const typeBadge = workout.workoutTypeName && workout.workoutTypeName !== "Libre" ? `<span class="badge type-badge" style="margin-left: 8px;">${workout.workoutTypeName}</span>` : ''; workoutDiv.innerHTML = `<div class="workout-header"><h3 style="margin-bottom: 0.5rem;">${workout.name} ${typeBadge}</h3><div class="badge">${workoutDate}</div></div><div class="workout-details"><span>${workout.duration} min</span> | <span>${workout.exercises.length} exo${workout.exercises.length > 1 ? 's' : ''}</span> | <span>${(workout.totalTonnage || 0).toFixed(1)} kg</span> | <span>${workout.satisfaction}%</span></div>`; workoutDiv.addEventListener('click', () => displayWorkoutDetails(workout.id)); workoutsList.appendChild(workoutDiv); }); } /* updateStats est appelé séparément après loadWorkouts ou deleteWorkout */ } | |
function displayWorkoutDetails(workoutId) { /* ... */ if (!currentFirebaseUser) return; const workout = workouts.find(w => w.id === workoutId); if (!workout) { alert("Détails de la séance introuvables."); showPage('home-page'); return; } const detailNameEl = document.getElementById('detail-workout-name'); const detailDateEl = document.getElementById('detail-date'); const detailDurationEl = document.getElementById('detail-duration'); const detailTonnageEl = document.getElementById('detail-tonnage'); const detailSatisfactionEl = document.getElementById('detail-satisfaction'); const detailExercisesCountEl = document.getElementById('detail-exercises-count'); const detailExercisesContainer = document.getElementById('detail-exercises-container'); if(detailWorkoutType) { if (workout.workoutTypeName && workout.workoutTypeName !== "Libre") { detailWorkoutType.textContent = workout.workoutTypeName; detailWorkoutType.classList.remove('hidden'); } else detailWorkoutType.classList.add('hidden'); } if(detailNameEl) detailNameEl.textContent = workout.name; if(detailDateEl) detailDateEl.textContent = new Date(workout.date).toLocaleDateString('fr-FR'); if(detailDurationEl) detailDurationEl.textContent = workout.duration; if(detailTonnageEl) detailTonnageEl.textContent = (workout.totalTonnage || 0).toFixed(1); if(detailSatisfactionEl) detailSatisfactionEl.textContent = `${workout.satisfaction}%`; if(detailExercisesCountEl) detailExercisesCountEl.textContent = workout.exercises.length; if(detailExercisesContainer) { detailExercisesContainer.innerHTML = ''; workout.exercises.forEach((exercise) => { const exerciseDiv = document.createElement('div'); exerciseDiv.className = 'card detail-exercise-card'; // Reuse card style let seriesHtml = ''; exercise.series.forEach((serie, sIndex) => { const degressiveLabel = serie.isDegressive ? ' <span class="badge" style="font-size: 0.7rem; background-color: var(--info); color: var(--text-light);">Dégr.</span>' : ''; const weightFactor = exercise.isUnilateral ? 2 : 1; const seriesTonnage = serie.reps * serie.weight * weightFactor; seriesHtml += `<div class="exercise-summary"><div class="flex-between"><span>Série ${sIndex + 1}: ${serie.reps} reps × ${serie.weight} kg${degressiveLabel}</span><span style="color: var(--text-secondary);">(${seriesTonnage.toFixed(1)} kg)</span></div></div>`; }); const unilateralLabel = exercise.isUnilateral ? ' <span class="badge" style="font-size: 0.7rem; background-color: var(--info); color: var(--text-light);">Unilat.</span>' : ''; exerciseDiv.innerHTML = `<h4 style="font-size: 1.1rem; margin-bottom: 0.8rem; color: var(--text-light); text-transform: none; font-family: var(--font-primary); letter-spacing: normal;">${exercise.name}${unilateralLabel}</h4> <div class="series-summary-container"> ${seriesHtml} </div>`; detailExercisesContainer.appendChild(exerciseDiv); }); } currentWorkoutId = workoutId; showPage('workout-details-page'); } | |
// --- Fonctionnalité STATS (Avec tendances) --- (Inchangé logiquement, utilise nouvelles couleurs/styles) | |
function updateStats() { | |
console.log("Mise à jour des statistiques..."); | |
if (!currentFirebaseUser) { console.log("Stats: non connecté."); return; } | |
if (!statsWorkoutCountEl || !statsAvgTonnageEl || !statsAvgSatisfactionEl) { console.warn("Éléments DOM des stats manquants."); return; } | |
const workoutCount = workouts.length; | |
statsWorkoutCountEl.textContent = workoutCount; | |
if (workoutCount === 0) { | |
statsAvgTonnageEl.textContent = '0'; | |
statsAvgSatisfactionEl.textContent = '0%'; | |
renderTypeTrends({}); | |
return; | |
} | |
const totalTonnageAll = workouts.reduce((sum, w) => sum + (w.totalTonnage || 0), 0); | |
statsAvgTonnageEl.textContent = (totalTonnageAll / workoutCount).toFixed(1); | |
const totalSatisfaction = workouts.reduce((sum, w) => sum + (w.satisfaction || 0), 0); | |
statsAvgSatisfactionEl.textContent = `${Math.round(totalSatisfaction / workoutCount)}%`; | |
console.log("Calcul tendances par type..."); | |
const trendsData = {}; | |
const structuredWorkouts = workouts.filter(w => w.workoutTypeName && w.workoutTypeName !== "Libre"); | |
const groupedByType = structuredWorkouts.reduce((acc, workout) => { | |
const type = workout.workoutTypeName; | |
if (!acc[type]) acc[type] = []; | |
acc[type].push(workout); | |
return acc; | |
}, {}); | |
for (const typeName in groupedByType) { | |
const sessionsOfType = groupedByType[typeName].sort((a, b) => new Date(a.date) - new Date(b.date)); // Tri chronologique | |
// Prend les 3 dernières séances pour la tendance | |
trendsData[typeName] = sessionsOfType.slice(-3).map(s => ({ date: s.date, tonnage: s.totalTonnage || 0 })); | |
} | |
console.log("Données tendances:", trendsData); | |
renderTypeTrends(trendsData); | |
} | |
function renderTypeTrends(trends) { | |
if (!typeTrendsContainer || !noTrendsMessage) { console.error("Éléments DOM pour tendances manquants."); return;} | |
if (trendsSpinner) trendsSpinner.classList.add('hidden'); // Cacher spinner | |
typeTrendsContainer.innerHTML = ''; // Vider | |
const trendTypes = Object.keys(trends); | |
if (trendTypes.length === 0) { | |
noTrendsMessage.classList.remove('hidden'); | |
} else { | |
noTrendsMessage.classList.add('hidden'); | |
trendTypes.sort().forEach(typeName => { | |
const typeData = trends[typeName]; | |
if (!typeData || typeData.length === 0) return; | |
const card = document.createElement('div'); | |
card.className = 'card type-trend-card'; | |
let listItems = ''; | |
typeData.forEach(session => { | |
const formattedDate = new Date(session.date).toLocaleDateString('fr-FR', { day: '2-digit', month: 'short' }); | |
const tonnageText = (session.tonnage !== undefined && session.tonnage !== null) ? `${session.tonnage.toFixed(1)} kg` : 'N/A'; | |
listItems += `<li><span>${formattedDate}</span> <strong>${tonnageText}</strong></li>`; | |
}); | |
// Utilise h4 pour le type, hérite du style des titres | |
card.innerHTML = `<h4>${typeName} (3 Dernières)</h4><ul>${listItems}</ul>`; | |
typeTrendsContainer.appendChild(card); | |
}); | |
} | |
} | |
function handleFirestoreError(error) { console.error("Erreur Firestore:", error); alert(`Erreur de base de données: ${error.message}`); } | |
// --- ÉCOUTEURS D'ÉVÉNEMENTS --- (Inchangé) | |
function initEventListeners() { | |
console.log("initEventListeners: Attachement des écouteurs..."); | |
if (loginForm) loginForm.addEventListener('submit', handleAuthAction); else console.error("!loginForm"); | |
if (authSwitchLink) authSwitchLink.addEventListener('click', authSwitchMode); else console.error("!authSwitchLink"); | |
if (logoutBtn) logoutBtn.addEventListener('click', handleLogout); else console.error("!logoutBtn"); | |
navItems.forEach((item, index) => { if(item) item.addEventListener('click', (e) => { e.preventDefault(); if (!currentFirebaseUser && item.getAttribute('data-page') !== 'login-page') { showLoginPage(); return; } const targetPageId = item.getAttribute('data-page'); showPage(targetPageId); }); else console.error(`!navItem #${index}`); }); | |
if (newWorkoutBtn) newWorkoutBtn.addEventListener('click', () => { if (!currentFirebaseUser) return; showPage('select-workout-type-page'); }); else console.error("!newWorkoutBtn"); | |
if (manageTypesBtn) manageTypesBtn.addEventListener('click', () => showPage('manage-types-page')); else console.error("!manageTypesBtn"); | |
if (addTypeForm) addTypeForm.addEventListener('submit', handleAddWorkoutType); else console.error("!addTypeForm"); | |
if (selectWorkoutTypeDropdown) selectWorkoutTypeDropdown.addEventListener('change', updateStartStructuredBtnState); else console.error("!selectWorkoutTypeDropdown"); | |
if (startStructuredWorkoutBtn) startStructuredWorkoutBtn.addEventListener('click', () => { if(selectWorkoutTypeDropdown) { const type = selectWorkoutTypeDropdown.value; if(type) { clearNewWorkoutForm(type); showPage('new-workout-page'); } else { alert("Veuillez sélectionner un type de séance.");} } }); else console.error("!startStructuredWorkoutBtn"); | |
if (startFreeWorkoutBtn) startFreeWorkoutBtn.addEventListener('click', () => { clearNewWorkoutForm("Libre"); showPage('new-workout-page'); }); else console.error("!startFreeWorkoutBtn"); | |
backToHomeBtns.forEach(btn => { if(btn) btn.addEventListener('click', () => showPage('home-page')); else console.error("!backToHomeBtn"); }); | |
if (cancelNewWorkoutBtn) cancelNewWorkoutBtn.addEventListener('click', () => { if(confirm("Êtes-vous sûr de vouloir annuler cette séance ? Les données non enregistrées seront perdues.")) showPage('home-page'); }); else console.error("!cancelNewWorkoutBtn"); | |
if (saveWorkoutBtn) saveWorkoutBtn.addEventListener('click', saveWorkout); else console.error("!saveWorkoutBtn"); | |
if (addExerciseBtn) addExerciseBtn.addEventListener('click', handleAddNewExercise); else console.error("!addExerciseBtn"); | |
if (prevExerciseBtn) prevExerciseBtn.addEventListener('click', () => navigateExerciseForm(-1)); else console.error("!prevExerciseBtn"); | |
if (nextExerciseBtn) nextExerciseBtn.addEventListener('click', () => navigateExerciseForm(1)); else console.error("!nextExerciseBtn"); | |
if (deleteWorkoutBtn) deleteWorkoutBtn.addEventListener('click', deleteWorkout); else console.error("!deleteWorkoutBtn"); | |
if (satisfactionRange) satisfactionRange.addEventListener('input', () => { if(satisfactionValue) satisfactionValue.textContent = `${satisfactionRange.value}%`; }); else console.error("!satisfactionRange"); | |
console.log("initEventListeners: Fin attachement."); | |
} | |
// ================================================== | |
// --- FIN DES DÉFINITIONS DE FONCTIONS --- | |
// ================================================== | |
// --- INITIALISATION --- | |
document.addEventListener('DOMContentLoaded', () => { | |
console.log("DOM chargé. Initialisation..."); | |
if (typeof firebase !== 'undefined' && firebase.auth) { | |
initAuthListener(); | |
} else { | |
console.error("Firebase Auth non prêt ou non chargé ! Vérifiez les scripts Firebase."); | |
alert("Erreur critique : Impossible d'initialiser l'authentification."); | |
} | |
initEventListeners(); | |
}); | |
</script> | |
</body> | |
</html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<meta name="viewport" content="width=device-width" /> | |
<title>My static Space</title> | |
<link rel="stylesheet" href="style.css" /> | |
</head> | |
<body> | |
<div class="card"> | |
<h1>Welcome to your static Space!</h1> | |
<p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p> | |
<p> | |
Also don't forget to check the | |
<a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>. | |
</p> | |
</div> | |
</body> | |
</html> | |