Switch to using multiple select for exercise selection on list view

considering adding graphs for data viewed
This commit is contained in:
Peter Stockings
2023-03-20 21:32:00 +11:00
parent d286d97470
commit f3c96ca11f
2 changed files with 33 additions and 20 deletions

14
app.py
View File

@@ -62,7 +62,8 @@ def get_person(person_id):
'max_date'), '%Y-%m-%d') or max_date
selected_exercise_ids = [int(i)
for i in request.args.getlist('exercise_id')] or [e['ExerciseId'] for e in person['Exercises']]
for i in request.args.getlist('exercise_id')]
# or [e['ExerciseId'] for e in person['Exercises']]
person['Workouts'] = [filter_workout_topsets(workout, selected_exercise_ids) for workout in person['Workouts'] if
workout['StartDate'] <= max_date and workout['StartDate'] >= min_date]
@@ -310,15 +311,18 @@ def my_utility_processor():
return element
return None
def is_checked(val, checked_vals):
def in_list(val, checked_vals, attr='checked'):
if not checked_vals:
return 'checked'
return 'checked' if val in checked_vals else ''
return attr
return attr if val in checked_vals else ''
def strftime(date, format="%b %d %Y"):
return date.strftime(format)
return dict(get_list_of_people_and_workout_count=get_list_of_people_and_workout_count, is_selected_page=is_selected_page, get_first_element_from_list_with_matching_attribute=get_first_element_from_list_with_matching_attribute, is_checked=is_checked, strftime=strftime, datetime=datetime, timedelta=timedelta, relativedelta=relativedelta, first_and_last_visible_days_in_month=first_and_last_visible_days_in_month)
def list_to_string(list):
return [str(i) for i in list]
return dict(get_list_of_people_and_workout_count=get_list_of_people_and_workout_count, is_selected_page=is_selected_page, get_first_element_from_list_with_matching_attribute=get_first_element_from_list_with_matching_attribute, in_list=in_list, strftime=strftime, datetime=datetime, timedelta=timedelta, relativedelta=relativedelta, first_and_last_visible_days_in_month=first_and_last_visible_days_in_month, list_to_string=list_to_string)
if __name__ == '__main__':

View File

@@ -26,22 +26,31 @@
<div class="flex">
{% set exercise_list = person['FilteredExercises'] %}
{% for e in person['Exercises'] %}
<div class="flex items-center mr-4" hx-get="{{ url_for('get_person', person_id=person['PersonId']) }}"
hx-include="[name='exercise_id'],[name='min_date'],[name='max_date']" hx-target="#container"
hx-push-url="true">
<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 class="flex flex-wrap -mx-3 mb-2 mt-4">
<div class="w-full md:w-1/2 px-3 mb-6 md:mb-0">
<div class="flex flex-wrap -mx-3 mb-2">
<div class="w-full md:w-1/3 px-3 mb-6 md:mb-0">
<div class="mb-3 w-full">
<label class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for="grid-city">
Exercises
</label>
<select id="multiSelection" data-te-select-init name="exercise_id"
class="bg-gray-50 border border-gray-300 " multiple hx-trigger="change"
hx-get="{{ url_for('get_person', person_id=person['PersonId']) }}"
hx-include="[name='min_date'],[name='max_date']" hx-target="#container" hx-push-url="true">
{% for e in person['Exercises'] %}
<option value="{{ e['ExerciseId'] }}" {{ in_list(e['ExerciseId'],
selected_exercise_ids, 'selected' ) }}>{{
e['ExerciseName']
}}</option>
{% endfor %}
</select>
</div>
<script>
te.Select.getOrCreateInstance(document.querySelector("#multiSelection")).setValue({{ list_to_string(selected_exercise_ids) | safe }});
</script>
</div>
<div class="w-full md:w-1/3 px-3 mb-6 md:mb-0">
<label class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for="grid-city">
Min date
</label>
@@ -62,7 +71,7 @@
hx-push-url="true" hx-trigger="change">
</div>
</div>
<div class="w-full md:w-1/2 px-3 mb-6 md:mb-0">
<div class="w-full md:w-1/3 px-3 mb-6 md:mb-0">
<label class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for="grid-zip">
Max date
</label>