Add button to topsets to show history as a table
This commit is contained in:
22
db.py
22
db.py
@@ -380,6 +380,28 @@ class DataBase():
|
||||
return None
|
||||
else:
|
||||
return (topset.get('repetitions'), topset.get('weight'), topset['exercise_name'])
|
||||
|
||||
def get_recent_topsets_for_exercise(self, person_id, exercise_id, limit=5, offset=0):
|
||||
topsets = self.execute("""
|
||||
SELECT
|
||||
t.topset_id,
|
||||
t.repetitions,
|
||||
t.weight,
|
||||
w.start_date,
|
||||
w.workout_id,
|
||||
e.name AS "exercise_name"
|
||||
FROM
|
||||
exercise e
|
||||
JOIN topset t ON e.exercise_id = t.exercise_id
|
||||
JOIN workout w ON t.workout_id = w.workout_id
|
||||
WHERE
|
||||
e.exercise_id = %s AND w.person_id = %s
|
||||
ORDER BY
|
||||
w.start_date DESC, t.topset_id DESC
|
||||
LIMIT %s OFFSET %s;
|
||||
""", [exercise_id, person_id, limit, offset])
|
||||
|
||||
return topsets
|
||||
|
||||
def get_all_exercises(self):
|
||||
return self.exercises.get("")
|
||||
|
||||
@@ -296,6 +296,22 @@ def get_most_recent_topset_for_exercise(person_id, workout_id):
|
||||
(repetitions, weight, exercise_name) = topset
|
||||
return render_template('partials/new_set_form.html', person_id=person_id, workout_id=workout_id, exercise_id=exercise_id, exercise_name=exercise_name, repetitions=repetitions, weight=weight)
|
||||
|
||||
@workout_bp.route("/person/<int:person_id>/exercise/<int:exercise_id>/history", methods=['GET'])
|
||||
def get_exercise_history(person_id, exercise_id):
|
||||
limit = request.args.get('limit', type=int, default=5)
|
||||
offset = request.args.get('offset', type=int, default=0)
|
||||
source_topset_id = request.args.get('source_topset_id', type=int)
|
||||
|
||||
topsets = db.get_recent_topsets_for_exercise(person_id, exercise_id, limit, offset)
|
||||
|
||||
return render_template('partials/exercise_history.html',
|
||||
person_id=person_id,
|
||||
exercise_id=exercise_id,
|
||||
topsets=topsets,
|
||||
limit=limit,
|
||||
offset=offset,
|
||||
source_topset_id=source_topset_id)
|
||||
|
||||
@workout_bp.route("/person/<int:person_id>/workout/<int:workout_id>", methods=['GET'])
|
||||
def show_workout(person_id, workout_id):
|
||||
# Use the local helper function to get the view model
|
||||
|
||||
56
templates/partials/exercise_history.html
Normal file
56
templates/partials/exercise_history.html
Normal file
@@ -0,0 +1,56 @@
|
||||
{% if offset == 0 %}
|
||||
<div
|
||||
class="w-full bg-gray-50 dark:bg-gray-800 p-4 border-t border-gray-200 dark:border-gray-700 shadow-inner overflow-x-auto">
|
||||
<h4 class="text-sm font-semibold text-gray-900 dark:text-white mb-2">History</h4>
|
||||
<table class="w-full text-left text-sm text-gray-500 dark:text-gray-400">
|
||||
<thead class="text-xs text-gray-700 uppercase bg-gray-100 dark:bg-gray-700 dark:text-gray-400">
|
||||
<tr>
|
||||
<th scope="col" class="px-3 py-2">Date</th>
|
||||
<th scope="col" class="px-3 py-2">Set & Achievements</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% endif %}
|
||||
|
||||
{% for topset in topsets %}
|
||||
<tr class="border-b dark:border-gray-700 bg-white dark:bg-gray-800">
|
||||
<td class="px-3 py-2 text-sm text-gray-900 dark:text-white whitespace-nowrap">
|
||||
{{ topset.start_date | strftime }}
|
||||
</td>
|
||||
<td class="px-3 py-2 text-sm text-gray-900 dark:text-white">
|
||||
<div class="flex flex-wrap items-center gap-x-2 gap-y-1">
|
||||
<span class="whitespace-nowrap">{{ topset.repetitions }} x {{ topset.weight }}kg</span>
|
||||
<div hx-get="{{ url_for('workout.get_topset_achievements', person_id=person_id, workout_id=topset.workout_id, topset_id=topset.topset_id) }}"
|
||||
hx-trigger="load" hx-target="this" hx-swap="innerHTML"
|
||||
class="flex flex-wrap items-center gap-1">
|
||||
<!-- Badges load here -->
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
{% if topsets|length == limit %}
|
||||
<tr id="history-load-more-{{ source_topset_id }}-{{ offset + limit }}">
|
||||
<td colspan="2" class="px-3 py-3 text-center">
|
||||
<button
|
||||
class="text-sm text-blue-600 hover:underline dark:text-blue-500 font-medium px-4 py-2 border border-blue-600 rounded"
|
||||
hx-get="{{ url_for('workout.get_exercise_history', person_id=person_id, exercise_id=exercise_id, limit=limit, offset=offset + limit, source_topset_id=source_topset_id) }}"
|
||||
hx-target="#history-load-more-{{ source_topset_id }}-{{ offset + limit }}" hx-swap="outerHTML">
|
||||
Load More
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
{% elif topsets|length == 0 and offset == 0 %}
|
||||
<tr>
|
||||
<td colspan="2" class="px-3 py-4 text-center text-gray-500 dark:text-gray-400">
|
||||
No history found.
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
|
||||
{% if offset == 0 %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endif %}
|
||||
@@ -6,18 +6,32 @@
|
||||
hx-vals='{"filter": "?exercise_id={{ exercise_id }}", "person_id" : "{{ person_id }}" }'
|
||||
hx-target="#container" hx-swap="innerHTML" hx-push-url="true"
|
||||
_='on click trigger closeModalWithoutRefresh'>{{ exercise_name }}</span>
|
||||
<button
|
||||
class="inline-flex justify-center p-1 text-gray-500 rounded cursor-pointer hover:text-gray-900 hover:bg-gray-100 dark:text-gray-400 dark:hover:text-white dark:hover:bg-gray-600"
|
||||
title="Show Progress Graph"
|
||||
hx-get="{{ url_for('get_exercise_progress_for_user', person_id=person_id, exercise_id=exercise_id) }}"
|
||||
hx-target="#graph-content-{{ topset_id }}" hx-swap="innerHTML">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"
|
||||
xmlns="http://www.w3.org/2000/svg">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||
d="M13 7h8m0 0v8m0-8l-8 8-4-4-6 6"></path>
|
||||
</svg>
|
||||
<span class="sr-only">Show Progress Graph</span>
|
||||
</button>
|
||||
<div class="flex flex-col sm:flex-row space-y-1 sm:space-y-0 sm:space-x-1">
|
||||
<button
|
||||
class="inline-flex justify-center p-1 text-gray-500 rounded cursor-pointer hover:text-gray-900 hover:bg-gray-100 dark:text-gray-400 dark:hover:text-white dark:hover:bg-gray-600"
|
||||
title="Show Progress Graph"
|
||||
hx-get="{{ url_for('get_exercise_progress_for_user', person_id=person_id, exercise_id=exercise_id) }}"
|
||||
hx-target="#extra-content-{{ topset_id }}" hx-swap="innerHTML">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"
|
||||
xmlns="http://www.w3.org/2000/svg">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||
d="M13 7h8m0 0v8m0-8l-8 8-4-4-6 6"></path>
|
||||
</svg>
|
||||
<span class="sr-only">Show Progress Graph</span>
|
||||
</button>
|
||||
<button
|
||||
class="inline-flex justify-center p-1 text-gray-500 rounded cursor-pointer hover:text-gray-900 hover:bg-gray-100 dark:text-gray-400 dark:hover:text-white dark:hover:bg-gray-600"
|
||||
title="Show History"
|
||||
hx-get="{{ url_for('workout.get_exercise_history', person_id=person_id, exercise_id=exercise_id, source_topset_id=topset_id) }}"
|
||||
hx-target="#extra-content-{{ topset_id }}" hx-swap="innerHTML">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"
|
||||
xmlns="http://www.w3.org/2000/svg">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||
d="M4 6h16M4 10h16M4 14h16M4 18h16"></path>
|
||||
</svg>
|
||||
<span class="sr-only">Show History</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="w-full">
|
||||
@@ -103,10 +117,10 @@
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{# Target row modified for dismissible graph #}
|
||||
<tr id="graph-target-{{ topset_id }}">
|
||||
{# Target row modified for dismissible extra content (graph or history) #}
|
||||
<tr id="extra-target-{{ topset_id }}">
|
||||
<td colspan="3" class="p-0 relative">
|
||||
<div id="graph-content-{{ topset_id }}" class="graph-content-container" _="
|
||||
<div id="extra-content-{{ topset_id }}" class="extra-content-container" _="
|
||||
on htmx:afterSwap
|
||||
get the next <button.dismiss-button/>
|
||||
if my.innerHTML is not empty and my.innerHTML is not ' '
|
||||
@@ -115,12 +129,12 @@
|
||||
add .hidden to it
|
||||
end
|
||||
end">
|
||||
<!-- Progress graph will be loaded here -->
|
||||
<!-- Progress graph or history will be loaded here -->
|
||||
</div>
|
||||
<button
|
||||
class="absolute top-1 right-1 p-1 bg-white rounded-full text-gray-500 hover:text-gray-700 hover:bg-gray-100 z-10 dismiss-button hidden"
|
||||
title="Dismiss Graph" _="on click
|
||||
get #graph-content-{{ topset_id }}
|
||||
title="Dismiss Content" _="on click
|
||||
get #extra-content-{{ topset_id }}
|
||||
set its innerHTML to ''
|
||||
add .hidden to me
|
||||
end">
|
||||
@@ -129,7 +143,7 @@
|
||||
d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"
|
||||
clip-rule="evenodd"></path>
|
||||
</svg>
|
||||
<span class="sr-only">Dismiss Graph</span>
|
||||
<span class="sr-only">Dismiss Content</span>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
Reference in New Issue
Block a user