feat: add Phase 4 Logging & Tracking — inline set logging, history views

Add workout logging so users can track sets, reps, weight, and a
"felt easy?" toggle inline from the workout day view via HTMX.
Sessions auto-create on first log. History page shows past sessions
with detailed per-exercise breakdowns.

New services: WorkoutSessionService, LogService
New routes: POST /log, /log/{id}/edit, /log/{id}/delete, GET /history, /history/{id}
New templates: log_form, log_entry, session_card, log_history, session_detail
Modified: exercise_card (inline logging), nav (History link), workouts route (session context)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-24 12:12:23 -06:00
parent 23754ea239
commit e35b78ae87
17 changed files with 1071 additions and 1 deletions

View File

@@ -24,5 +24,18 @@
<p>{{ exercise.form_cues }}</p>
</details>
<!-- Phase 4 adds: inline logging form here -->
<!-- Inline logging (Phase 4) -->
{% if active_profile %}
<div id="logs-exercise-{{ exercise.id }}">
{% if existing_logs and existing_logs[exercise.id] %}
{% set logs = existing_logs[exercise.id] %}
{% set exercise_id = exercise.id %}
{% set next_set = logs|length + 1 %}
{% include "partials/log_entry.html" %}
{% else %}
{% set next_set = 1 %}
{% include "partials/log_form.html" %}
{% endif %}
</div>
{% endif %}
</article>

View File

@@ -0,0 +1,39 @@
<!-- Displays logged sets for a single exercise within a session -->
{% if logs %}
<table>
<thead>
<tr>
<th>Set</th>
<th>Reps</th>
<th>Weight</th>
<th>Easy?</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for log in logs %}
<tr>
<td>{{ log.set_number }}</td>
<td>{{ log.reps_completed }}</td>
<td>{{ log.weight_used }}</td>
<td>{{ "Yes" if log.felt_easy else "No" }}</td>
<td>
<form hx-post="/log/{{ log.id }}/delete"
hx-target="#logs-exercise-{{ exercise_id }}"
hx-swap="innerHTML"
hx-confirm="Delete this set?"
style="display:inline; margin:0;">
<button type="submit" class="outline secondary"
style="padding:0.2rem 0.5rem; font-size:0.8rem;">
Delete
</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
<!-- Next set form -->
{% include "partials/log_form.html" %}

View File

@@ -0,0 +1,24 @@
<!-- Inline logging form, included inside each exercise_card.html -->
<form hx-post="/log"
hx-target="#logs-exercise-{{ exercise.id }}"
hx-swap="innerHTML"
style="margin-bottom:0;">
<input type="hidden" name="exercise_id" value="{{ exercise.id }}">
<input type="hidden" name="workout_day_id" value="{{ workout_day_id }}">
<input type="hidden" name="set_number" value="{{ next_set|default(1) }}">
<div style="display:flex; align-items:center; gap:0.5rem; flex-wrap:wrap;">
<small style="white-space:nowrap; opacity:0.7;">Set {{ next_set|default(1) }}</small>
<input type="number" name="reps" placeholder="Reps"
min="0" max="100" required
style="width:5rem; margin-bottom:0;">
<input type="text" name="weight" placeholder="Weight (lbs)"
required
style="width:8rem; margin-bottom:0;">
<label style="display:flex; align-items:center; gap:0.3rem; margin-bottom:0; white-space:nowrap;">
<input type="checkbox" name="felt_easy" role="switch" style="margin-bottom:0;">
Easy?
</label>
<button type="submit" style="margin-bottom:0; width:auto; white-space:nowrap;">Log Set</button>
</div>
</form>

View File

@@ -27,6 +27,7 @@
</details>
</li>
<li><a href="/workouts">Workouts</a></li>
<li><a href="/history">History</a></li>
<li><a href="/exercises">Exercises</a></li>
<li><a href="/profiles">Profiles</a></li>
<li><a href="/logout">Logout</a></li>

View File

@@ -0,0 +1,16 @@
<article>
<header>
<hgroup>
<h3>{{ day.name if day else "Unknown" }} Day</h3>
<p>{{ ws.date.strftime('%A, %B %d, %Y') }}</p>
</hgroup>
</header>
{% if ws.notes %}
<p>{{ ws.notes }}</p>
{% endif %}
<footer>
<a href="/history/{{ ws.id }}" role="button" class="outline">
View Details
</a>
</footer>
</article>