Fix issue selecting a new exercise
This commit is contained in:
6
app.py
6
app.py
@@ -393,14 +393,14 @@ def get_most_recent_topset_for_exercise(person_id, workout_id):
|
|||||||
exercises = db.get_all_exercises()
|
exercises = db.get_all_exercises()
|
||||||
|
|
||||||
if not exercise_id:
|
if not exercise_id:
|
||||||
return render_template('partials/new_set_form.html', person_id=person_id, workout_id=workout_id, exercises=exercises, has_value=False)
|
return render_template('partials/new_set_form.html', person_id=person_id, workout_id=workout_id, exercises=exercises)
|
||||||
|
|
||||||
topset = db.get_most_recent_topset_for_exercise(person_id, exercise_id)
|
topset = db.get_most_recent_topset_for_exercise(person_id, exercise_id)
|
||||||
if not topset:
|
if not topset:
|
||||||
return render_template('partials/new_set_form.html', person_id=person_id, workout_id=workout_id, exercises=exercises, exercise_id=exercise_id, has_value=False)
|
return render_template('partials/new_set_form.html', person_id=person_id, workout_id=workout_id, exercises=exercises, exercise_id=exercise_id)
|
||||||
|
|
||||||
(repetitions, weight, exercise_name) = topset
|
(repetitions, weight, exercise_name) = topset
|
||||||
return render_template('partials/new_set_form.html', person_id=person_id, workout_id=workout_id, has_value=True, exercise_id=exercise_id, exercise_name=exercise_name, repetitions=repetitions, weight=weight)
|
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)
|
||||||
|
|
||||||
|
|
||||||
def calculate_relative_positions(start_dates):
|
def calculate_relative_positions(start_dates):
|
||||||
|
|||||||
15
db.py
15
db.py
@@ -460,22 +460,23 @@ class DataBase():
|
|||||||
SELECT
|
SELECT
|
||||||
t.repetitions,
|
t.repetitions,
|
||||||
t.weight,
|
t.weight,
|
||||||
e.name as "exercise_name"
|
e.name AS "exercise_name"
|
||||||
FROM
|
FROM
|
||||||
topset t JOIN workout w ON t.workout_id = w.workout_id
|
exercise e
|
||||||
JOIN exercise e ON t.exercise_id = e.exercise_id
|
LEFT JOIN topset t ON e.exercise_id = t.exercise_id
|
||||||
|
LEFT JOIN workout w ON t.workout_id = w.workout_id
|
||||||
WHERE
|
WHERE
|
||||||
w.person_id = %s AND t.exercise_id = %s
|
e.exercise_id = %s AND (w.person_id = %s OR w.person_id IS NULL)
|
||||||
ORDER BY
|
ORDER BY
|
||||||
w.start_date DESC
|
w.start_date DESC
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
""", [person_id, exercise_id], one=True)
|
""", [exercise_id, person_id], one=True)
|
||||||
|
|
||||||
if not topset:
|
if not topset:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
return (topset['repetitions'], topset['weight'], topset['exercise_name'])
|
return (topset.get('repetitions'), topset.get('weight'), topset['exercise_name'])
|
||||||
|
|
||||||
def get_all_exercises(self):
|
def get_all_exercises(self):
|
||||||
exercises = self.execute(
|
exercises = self.execute(
|
||||||
'SELECT exercise_id, name FROM exercise')
|
'SELECT exercise_id, name FROM exercise')
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
class="appearance-none block w-full bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
|
class="appearance-none block w-full bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
|
||||||
id="exercise-search" type="search" name="query" placeholder="Search exercises..."
|
id="exercise-search" type="search" name="query" placeholder="Search exercises..."
|
||||||
hx-get="{{ url_for('get_exercises', person_id=person_id) }}" hx-target="#exercise-results"
|
hx-get="{{ url_for('get_exercises', person_id=person_id) }}" hx-target="#exercise-results"
|
||||||
hx-trigger="keyup changed delay:500ms" hx-swap="innerHTML" autocomplete="off" {% if has_value==True %}
|
hx-trigger="keyup changed delay:500ms" hx-swap="innerHTML" autocomplete="off" {% if exercise_name %}
|
||||||
value="{{ exercise_name }}" {% endif %} _="
|
value="{{ exercise_name }}" {% endif %} _="
|
||||||
on input
|
on input
|
||||||
if this.value is empty
|
if this.value is empty
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
<!-- Results will be injected here -->
|
<!-- Results will be injected here -->
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input type="hidden" name="exercise_id" id="selected-exercise" {% if has_value==True %} value="{{ exercise_id }}" {%
|
<input type="hidden" name="exercise_id" id="selected-exercise" {% if exercise_id %} value="{{ exercise_id }}" {%
|
||||||
endif %}>
|
endif %}>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
<label class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for="grid-state">
|
<label class="block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" for="grid-state">
|
||||||
Exercise
|
Exercise
|
||||||
</label>
|
</label>
|
||||||
{{ render_partial('partials/exercise/exercise_select.html', person_id=person_id, has_value=has_value,
|
{{ render_partial('partials/exercise/exercise_select.html', person_id=person_id,
|
||||||
exercise_id=exercise_id, exercise_name=exercise_name) }}
|
exercise_id=exercise_id, exercise_name=exercise_name) }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
class="appearance-none block w-full bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
|
class="appearance-none block w-full bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
|
||||||
id="grid-city" type="number" name="repetitions" {% if has_value==True %} placeholder="{{ repetitions }}"
|
id="grid-city" type="number" name="repetitions" {% if repetitions %} placeholder="{{ repetitions }}"
|
||||||
_="on clearNewSetInputs set my.placeholder to ''" {% endif %}>
|
_="on clearNewSetInputs set my.placeholder to ''" {% endif %}>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@
|
|||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
class="appearance-none block w-full bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
|
class="appearance-none block w-full bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
|
||||||
id="grid-zip" type="number" name="weight" step="any" {% if has_value==True %} placeholder="{{ weight }}"
|
id="grid-zip" type="number" name="weight" step="any" {% if weight %} placeholder="{{ weight }}"
|
||||||
_="on clearNewSetInputs set my.placeholder to ''" {% endif %}>
|
_="on clearNewSetInputs set my.placeholder to ''" {% endif %}>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user