diff --git a/db.py b/db.py index c81e795..3c4ebe8 100644 --- a/db.py +++ b/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("") diff --git a/routes/workout.py b/routes/workout.py index 2f8bd00..f980a7f 100644 --- a/routes/workout.py +++ b/routes/workout.py @@ -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//exercise//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//workout/", methods=['GET']) def show_workout(person_id, workout_id): # Use the local helper function to get the view model diff --git a/templates/partials/exercise_history.html b/templates/partials/exercise_history.html new file mode 100644 index 0000000..98d4835 --- /dev/null +++ b/templates/partials/exercise_history.html @@ -0,0 +1,56 @@ +{% if offset == 0 %} +
+

History

+ + + + + + + + + {% endif %} + + {% for topset in topsets %} + + + + + {% endfor %} + + {% if topsets|length == limit %} + + + + {% elif topsets|length == 0 and offset == 0 %} + + + + {% endif %} + + {% if offset == 0 %} + +
DateSet & Achievements
+ {{ topset.start_date | strftime }} + +
+ {{ topset.repetitions }} x {{ topset.weight }}kg +
+ +
+
+
+ +
+ No history found. +
+
+{% endif %} \ No newline at end of file diff --git a/templates/partials/topset.html b/templates/partials/topset.html index 3e639ee..faefbf6 100644 --- a/templates/partials/topset.html +++ b/templates/partials/topset.html @@ -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 }} - +
+ + +
{% else %}
@@ -103,10 +117,10 @@
-{# Target row modified for dismissible graph #} - +{# Target row modified for dismissible extra content (graph or history) #} + -
- +
\ No newline at end of file