From c457002d1e182a491295dc5467994408ea5d9fa2 Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Wed, 12 Jul 2023 19:35:55 +1000 Subject: [PATCH] Add editable notes to workouts --- app.py | 22 +++ db.py | 12 +- templates/partials/start_date.html | 62 ++++---- templates/partials/workout_modal.html | 201 +++++++++++++------------- templates/partials/workout_note.html | 35 +++++ 5 files changed, 203 insertions(+), 129 deletions(-) create mode 100644 templates/partials/workout_note.html diff --git a/app.py b/app.py index 2ebe53e..8c7533b 100644 --- a/app.py +++ b/app.py @@ -364,6 +364,28 @@ def delete_tag(tag_id): return redirect(url_for('dashboard') + tag_filter) +@ app.route("/person//workout//note/edit", methods=['GET']) +@ validate_workout +def get_workout_note_edit_form(person_id, workout_id): + workout = db.get_workout(person_id, workout_id) + return render_template('partials/workout_note.html', person_id=person_id, workout_id=workout_id, note=workout['Note'], is_edit=True) + + +@ app.route("/person//workout//note", methods=['PUT']) +@ validate_workout +def update_workout_note(person_id, workout_id): + note = request.form.get('note') + db.update_workout_note_for_person(person_id, workout_id, note) + return render_template('partials/workout_note.html', person_id=person_id, workout_id=workout_id, note=note) + + +@ app.route("/person//workout//note", methods=['GET']) +@ validate_workout +def get_workout_note(person_id, workout_id): + workout = db.get_workout(person_id, workout_id) + return render_template('partials/workout_note.html', person_id=person_id, workout_id=workout_id, note=workout['Note']) + + @ app.context_processor def my_utility_processor(): diff --git a/db.py b/db.py index 792447b..d1d3644 100644 --- a/db.py +++ b/db.py @@ -185,7 +185,8 @@ class DataBase(): E.exercise_id AS "ExerciseId", E.name AS "ExerciseName", T.repetitions AS "Repetitions", - T.weight AS "Weight" + T.weight AS "Weight", + W.note AS "Note" FROM Person P LEFT JOIN Workout W ON P.person_id=W.person_id LEFT JOIN TopSet T ON W.workout_id=T.workout_id @@ -193,13 +194,16 @@ class DataBase(): WHERE P.person_id=%s AND W.workout_id = %s""", [person_id, workout_id]) + note = next((t['Note'] for t in topsets), '') + return { 'PersonId': next((t['PersonId'] for t in topsets), -1), 'PersonName': next((t['PersonName'] for t in topsets), 'Unknown'), 'WorkoutId': workout_id, 'StartDate': topsets[0]['StartDate'], 'Exercises': self.get_exercises(), - 'TopSets': [{"TopSetId": t['TopSetId'], "ExerciseId": t['ExerciseId'], "ExerciseName": t['ExerciseName'], "Weight": t['Weight'], "Repetitions": t['Repetitions']} for t in topsets if t['TopSetId'] is not None] + 'TopSets': [{"TopSetId": t['TopSetId'], "ExerciseId": t['ExerciseId'], "ExerciseName": t['ExerciseName'], "Weight": t['Weight'], "Repetitions": t['Repetitions']} for t in topsets if t['TopSetId'] is not None], + 'Note': note } def get_topset(self, person_id, workout_id, topset_id): @@ -297,3 +301,7 @@ class DataBase(): def delete_tag_for_dashboard(self, tag_id): self.execute('DELETE FROM Tag WHERE tag_id=%s', [tag_id], commit=True) + + def update_workout_note_for_person(self, person_id, workout_id, note): + self.execute('UPDATE workout SET note=%s WHERE person_id=%s AND workout_id=%s', [ + note, person_id, workout_id], commit=True) diff --git a/templates/partials/start_date.html b/templates/partials/start_date.html index cfc275c..650061a 100644 --- a/templates/partials/start_date.html +++ b/templates/partials/start_date.html @@ -1,31 +1,33 @@ -{% if is_edit|default(false, true) == false %} -{{ strftime(start_date, "%b %d %Y") }} - - Edit - -{% else %} -
-
-
- -
- -
- - - Cancel + -{% endif %} \ No newline at end of file + {% else %} +
+
+
+ +
+ +
+ + + Cancel + +
+ {% endif %} +
\ No newline at end of file diff --git a/templates/partials/workout_modal.html b/templates/partials/workout_modal.html index 916b60d..fa31e32 100644 --- a/templates/partials/workout_modal.html +++ b/templates/partials/workout_modal.html @@ -11,23 +11,29 @@
-
+

{{ workout['PersonName'] }}

- -
+
{{ render_partial('partials/start_date.html', person_id=workout['PersonId'], workout_id=workout['WorkoutId'], start_date=workout['StartDate']) }} + + + {{ render_partial('partials/workout_note.html', person_id=workout['PersonId'], + workout_id=workout['WorkoutId'], + note=workout['Note']) }} +
+
- -
- - - - - - - - - - {% for t in workout['TopSets'] %} - {{ render_partial('partials/topset.html', person_id=workout['PersonId'], - workout_id=workout['WorkoutId'], - topset_id=t['TopSetId'], exercise_name=t['ExerciseName'], repetitions=t['Repetitions'], - weight=t['Weight']) }} - {% endfor %} - -
- Exercise - Top Set -
- {% if workout['TopSets']|length == 0 %} - - {% endif %} +
+ +
+ + + + + + + + + + {% for t in workout['TopSets'] %} + {{ render_partial('partials/topset.html', person_id=workout['PersonId'], + workout_id=workout['WorkoutId'], + topset_id=t['TopSetId'], exercise_name=t['ExerciseName'], repetitions=t['Repetitions'], + weight=t['Weight']) }} + {% endfor %} + +
+ Exercise + Top Set +
+ + {% if workout['TopSets']|length == 0 %} + - -
-
+ {% endif %} +
+ +
+ -
-
- -
+
+
+ +
-
- -
- +
+
-
- -
- - -
- -
- - +
-
- - +
+ +
- -
+ +
+ + +
+
+
+ + + +
+
+
\ No newline at end of file diff --git a/templates/partials/workout_note.html b/templates/partials/workout_note.html new file mode 100644 index 0000000..8c8b6be --- /dev/null +++ b/templates/partials/workout_note.html @@ -0,0 +1,35 @@ +
+ {% if is_edit|default(false, true) == false %} + {% if note|length > 0 %} + {{ note }} + + Edit + + {% else %} + + Add note + + {% endif %} + {% else %} +
+ + +
+ {% endif %} +
\ No newline at end of file