Fix for filter not working after selecting a single exercise

This commit is contained in:
Peter Stockings
2022-11-23 22:48:03 +11:00
parent 41bfce9513
commit 56ceb87867
2 changed files with 95 additions and 97 deletions

View File

@@ -3,6 +3,6 @@
{% block content %} {% block content %}
{{ render_partial('partials/page/dashboard.html', {{ render_partial('partials/page/dashboard.html',
people=people, exercises=exercises) }} model=model) }}
{% endblock %} {% endblock %}

View File

@@ -1,116 +1,114 @@
<div> <div class="flex justify-center">
<div class="flex justify-center"> <div class="bg-white shadow rounded-lg p-4 sm:w-full xl:p-8 md:w-full lg:w-10/12 xl:w-8/12 2xl:w-6/12">
<div class="bg-white shadow rounded-lg p-4 sm:w-full xl:p-8 md:w-full lg:w-10/12 xl:w-8/12 2xl:w-6/12">
<div class="mb-4 flex items-center justify-between"> <div class="mb-4 flex items-center justify-between">
<div> <div>
<h3 class="text-xl font-bold text-gray-900 mb-2">{{ person['PersonName'] }}</h3> <h3 class="text-xl font-bold text-gray-900 mb-2">{{ person['PersonName'] }}</h3>
<span class="text-base font-normal text-gray-500">List of workouts</span> <span class="text-base font-normal text-gray-500">List of workouts</span>
</div>
<div>
<form action="{{ url_for('create_workout', person_id=person['PersonId']) }}" method="post">
<button
class="sm:inline-flex text-white bg-cyan-600 hover:bg-cyan-700 focus:ring-4 focus:ring-cyan-200 font-medium rounded-lg text-sm px-5 py-2.5 text-center items-center mt-6">New
workout</button>
</form>
</div>
</div> </div>
<div>
<div class="flex"> <form action="{{ url_for('create_workout', person_id=person['PersonId']) }}" method="post">
{% set exercise_list = person['FilteredExercises'] if is_filtered else person['Exercises'] %} <button
class="sm:inline-flex text-white bg-cyan-600 hover:bg-cyan-700 focus:ring-4 focus:ring-cyan-200 font-medium rounded-lg text-sm px-5 py-2.5 text-center items-center mt-6">New
{% for e in person['Exercises'] %} workout</button>
<div class="flex items-center mr-4" </form>
hx-post="{{ url_for('filter_exercises_for_person', person_id=person['PersonId']) }}"
hx-include="[name='exercise_id']" hx-target="#container" hx-swap="outerHTML">
<input {{ is_checked(e['ExerciseId'], selected_exercise_ids) }} type="checkbox" name="exercise_id"
value="{{ e['ExerciseId'] }}"
class="w-4 h-4 text-blue-600 bg-gray-100 rounded border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
<label for="inline-checked-checkbox"
class="ml-2 text-sm font-medium text-gray-900 dark:text-gray-300">{{ e['ExerciseName']
}}</label>
</div>
{% endfor %}
</div> </div>
</div>
<div class="flex flex-col mt-8"> <div class="flex">
<div class="overflow-x-auto rounded-lg"> {% set exercise_list = person['FilteredExercises'] if is_filtered else person['Exercises'] %}
<div class="align-middle inline-block min-w-full">
<div class="shadow overflow-hidden sm:rounded-lg">
{% if person['Workouts']|length > 0 %} {% for e in person['Exercises'] %}
<table class="min-w-full divide-y divide-gray-200"> <div class="flex items-center mr-4"
<thead class="bg-gray-50"> hx-post="{{ url_for('filter_exercises_for_person', person_id=person['PersonId']) }}"
<tr> hx-include="[name='exercise_id']" hx-target="#container">
<th scope="col" <input {{ is_checked(e['ExerciseId'], selected_exercise_ids) }} type="checkbox" name="exercise_id"
class="p-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"> value="{{ e['ExerciseId'] }}"
Date class="w-4 h-4 text-blue-600 bg-gray-100 rounded border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
</th> <label for="inline-checked-checkbox"
{% for e in exercise_list %} class="ml-2 text-sm font-medium text-gray-900 dark:text-gray-300">{{ e['ExerciseName']
<th scope="col" }}</label>
class="p-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"> </div>
{{ e['ExerciseName'] }} {% endfor %}
</th> </div>
{% endfor %}
<th scope="col"
class="p-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider w-8">
</th>
</tr>
</thead>
<tbody class="bg-white">
{% for w in person['Workouts'] %} <div class="flex flex-col mt-8">
<tr> <div class="overflow-x-auto rounded-lg">
<td class="p-4 whitespace-nowrap text-sm font-normal text-gray-500"> <div class="align-middle inline-block min-w-full">
{{ w['StartDate'] }} <div class="shadow overflow-hidden sm:rounded-lg">
</td>
{% for e in exercise_list %} {% if person['Workouts']|length > 0 %}
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900"> <table class="min-w-full divide-y divide-gray-200">
{% set topset_exercise = <thead class="bg-gray-50">
get_first_element_from_list_with_matching_attribute(w['TopSets'], <tr>
'ExerciseId', <th scope="col"
e['ExerciseId']) %} class="p-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
{% if topset_exercise %} Date
{{ topset_exercise['Repetitions'] }} x {{ topset_exercise['Weight'] }}kg </th>
{% endif %} {% for e in exercise_list %}
</td> <th scope="col"
{% endfor %} class="p-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
{{ e['ExerciseName'] }}
</th>
{% endfor %}
<th scope="col"
class="p-4 text-left text-xs font-medium text-gray-500 uppercase tracking-wider w-8">
</th>
</tr>
</thead>
<tbody class="bg-white">
<td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900"> {% for w in person['Workouts'] %}
<a href="{{ url_for('get_workout' ,person_id=person['PersonId'], workout_id=w['WorkoutId']) }}" <tr>
class="text-sm font-medium text-cyan-600 hover:bg-gray-100 rounded-lg inline-flex items-center p-2 cursor-pointer"> <td class="p-4 whitespace-nowrap text-sm font-normal text-gray-500">
Edit {{ w['StartDate'] }}
</a> </td>
<form {% for e in exercise_list %}
action="{{ url_for('delete_workout', person_id=person['PersonId'], workout_id=w['WorkoutId']) }}" <td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
method="delete" class="inline"> {% set topset_exercise =
<button get_first_element_from_list_with_matching_attribute(w['TopSets'],
class="text-sm font-medium text-cyan-600 hover:bg-gray-100 rounded-lg inline-flex items-center p-2 cursor-pointer" 'ExerciseId',
type="submit">Delete</button> e['ExerciseId']) %}
</form> {% if topset_exercise %}
</td> {{ topset_exercise['Repetitions'] }} x {{ topset_exercise['Weight'] }}kg
</tr> {% endif %}
</td>
{% endfor %} {% endfor %}
</tbody> <td class="p-4 whitespace-nowrap text-sm font-semibold text-gray-900">
</table> <a href="{{ url_for('get_workout' ,person_id=person['PersonId'], workout_id=w['WorkoutId']) }}"
{% endif %} class="text-sm font-medium text-cyan-600 hover:bg-gray-100 rounded-lg inline-flex items-center p-2 cursor-pointer">
Edit
</a>
{% if person['Workouts']|length == 0 %} <form
<div class="bg-purple-100 rounded-lg py-5 px-6 mb-4 text-base text-purple-700 mb-3" action="{{ url_for('delete_workout', person_id=person['PersonId'], workout_id=w['WorkoutId']) }}"
role="alert"> method="delete" class="inline">
No workouts found. <button
</div> class="text-sm font-medium text-cyan-600 hover:bg-gray-100 rounded-lg inline-flex items-center p-2 cursor-pointer"
{% endif %} type="submit">Delete</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
{% if person['Workouts']|length == 0 %}
<div class="bg-purple-100 rounded-lg py-5 px-6 mb-4 text-base text-purple-700 mb-3"
role="alert">
No workouts found.
</div> </div>
{% endif %}
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
{{ render_partial('partials/stats.html', stats=person['Stats']) }}
</div> </div>
{{ render_partial('partials/stats.html', stats=person['Stats']) }}