diff --git a/app.py b/app.py index 5a41021..95ebc1c 100644 --- a/app.py +++ b/app.py @@ -125,6 +125,8 @@ def get_calendar(person_id): if selected_view == 'all': return redirect(url_for('get_person', person_id=person_id)) + elif selected_view == 'notes': + return redirect(url_for('get_person_notes', person_id=person_id)) # selected_view = month | year | all date_info = get_date_info(selected_date, selected_view) @@ -133,6 +135,14 @@ def get_calendar(person_id): return render_block(app.jinja_env, 'calendar.html', 'content', person=person, selected_date=selected_date, selected_view=selected_view, **date_info, datetime=datetime, timedelta=timedelta, relativedelta=relativedelta, first_and_last_visible_days_in_month=first_and_last_visible_days_in_month) return render_template('calendar.html', person=person, selected_date=selected_date, selected_view=selected_view, **date_info, datetime=datetime, timedelta=timedelta, relativedelta=relativedelta, first_and_last_visible_days_in_month=first_and_last_visible_days_in_month) +@ app.route("/person//notes", methods=['GET']) +@ validate_person +def get_person_notes(person_id): + (person_name, workout_notes) = db.get_workout_notes_for_person(person_id) + if htmx: + return render_block(app.jinja_env, 'notes.html', 'content', person_id=person_id, person_name=person_name, workout_notes=workout_notes) + return render_template('notes.html', person_id=person_id, person_name=person_name, workout_notes=workout_notes) + @ app.route("/person//workout//modal", methods=['GET']) @ validate_workout diff --git a/db.py b/db.py index de9be92..b7c2f07 100644 --- a/db.py +++ b/db.py @@ -486,4 +486,54 @@ class DataBase(): exercise_progress = get_exercise_graph_model(topsets[0]['exercise_name'], estimated_1rm, repetitions, weight, start_dates, messages) - return exercise_progress \ No newline at end of file + return exercise_progress + + def get_workout_notes_for_person(self, person_id): + sql_query = """ + SELECT + p.name AS person_name, + w.workout_id, + to_char(w.start_date, 'Mon DD YYYY') AS formatted_start_date, + w.note, + t.filter as tag_filter, + t.name AS tag_name + FROM person p + LEFT JOIN workout w ON p.person_id = w.person_id AND w.note IS NOT NULL AND w.note <> '' + LEFT JOIN workout_tag wt ON w.workout_id = wt.workout_id + LEFT JOIN tag t ON wt.tag_id = t.tag_id + WHERE p.person_id = %s + ORDER BY w.start_date DESC, w.workout_id, t.name; + """ + + # Execute the SQL query + raw_workout_notes = self.execute(sql_query, [person_id]) + + # Initialize variables to hold the person's name and the workouts + person_name = None + workout_notes = {} + + for row in raw_workout_notes: + # Update person_name (it will be the same for all rows) + if person_name is None: + person_name = row['person_name'] + + # Process workout notes and tags if there's a note associated with the workout + if row['workout_id'] and row['note']: # Check if workout_id exists and note is not None or empty + workout_id = row['workout_id'] + if workout_id not in workout_notes: + workout_notes[workout_id] = { + 'workout_id': workout_id, + 'formatted_start_date': row['formatted_start_date'], + 'note': row['note'], + 'tags': [] + } + if row['tag_name']: # Only add the tag if it is not None + workout_notes[workout_id]['tags'].append({'tag_filter': row['tag_filter'], 'tag_name': row['tag_name'], 'person_id': person_id}) + + + # Convert the workout_notes dictionary back into a list as the final result + workout_notes_list = list(workout_notes.values()) + + # Return a tuple containing the person's name and their workout notes + return (person_name, workout_notes_list) + diff --git a/templates/calendar.html b/templates/calendar.html index 32ad9e5..6730eec 100644 --- a/templates/calendar.html +++ b/templates/calendar.html @@ -46,6 +46,7 @@ _="init js(me) tail.select(me, {}) end"> + diff --git a/templates/notes.html b/templates/notes.html new file mode 100644 index 0000000..8b7642b --- /dev/null +++ b/templates/notes.html @@ -0,0 +1,98 @@ +{% extends 'base.html' %} + +{% block content %} + + + +
+
+
+

Notes

+ {{person_name}} +
+ +
+ +
+
+ + {% if workout_notes %} +
+ + + + + + + + + + {% for workout_note in workout_notes %} + + + + + + {% endfor %} + +
+ Date + + Note + + Tags +
+
+ +
+ {{ workout_note.formatted_start_date + }} +
+
+
+ {{ render_partial('partials/workout_note.html', person_id=person_id, + workout_id=workout_note.workout_id, + note=workout_note.note) }} + + {{ render_partial('partials/workout_tags_list.html', workout_tags=workout_note.tags) }} +
+
+ {% endif %} + +
+ + + + + +{% endblock %} \ No newline at end of file diff --git a/templates/partials/workout_note.html b/templates/partials/workout_note.html index 30872f0..549284a 100644 --- a/templates/partials/workout_note.html +++ b/templates/partials/workout_note.html @@ -1,16 +1,16 @@ -
+
{% if is_edit|default(false, true) == false %} {% if note|length > 0 %} {{ note | replace('\n', '
') | safe }}
+ hx-target="#workout-note-{{workout_id}}"> Edit {% else %} + hx-target="#workout-note-{{workout_id}}"> Add note {% endif %} @@ -25,7 +25,7 @@