From ceb76e7b1d75623b09a9c85a3e48752404a9077d Mon Sep 17 00:00:00 2001 From: stilbruch Date: Sat, 23 Apr 2022 17:08:53 -0500 Subject: Work on exercise type support for create workout --- app/forms/workout.py | 1 + app/static/js/create.js | 4 +- app/tables/workout.py | 14 ++++- app/templates/base/form.html | 20 +++---- app/templates/workout/create.html | 114 ++++++++++++++++++++------------------ 5 files changed, 86 insertions(+), 67 deletions(-) (limited to 'app') diff --git a/app/forms/workout.py b/app/forms/workout.py index ecc72c8..a84eb6a 100644 --- a/app/forms/workout.py +++ b/app/forms/workout.py @@ -7,6 +7,7 @@ class ExerciseCreateForm(Form): name = StringField("name", [DataRequired()]) sets = IntegerField("sets", [DataRequired()]) units = IntegerField("units", [DataRequired()]) + type = StringField("type", [DataRequired()]) # TODO: make sure its time or reps class SetForm(Form): lbs = IntegerField("lbs", [DataRequired()]) diff --git a/app/static/js/create.js b/app/static/js/create.js index 7cdf328..832bbe2 100644 --- a/app/static/js/create.js +++ b/app/static/js/create.js @@ -18,7 +18,9 @@ function handleAdd() { exerciseUnitInput.placeholder = 'Reps'; exerciseUnitInput.name = 'exercises-' + rowId + '-units'; - exerciseUnitInput.parentNode.children[0].children[0].children[0].addEventListener("input", handleChange); + exerciseUnitSelect = exerciseUnitInput.parentNode.children[0].children[0].children[0]; + exerciseUnitSelect.addEventListener("input", handleChange); + exerciseUnitSelect.name = 'exercises-' + rowId + '-type'; rowId++; rowsDiv.append(newRow); diff --git a/app/tables/workout.py b/app/tables/workout.py index cff0762..164f547 100644 --- a/app/tables/workout.py +++ b/app/tables/workout.py @@ -1,4 +1,9 @@ from app import db, login_manager +import enum + +class ExerciseType(enum.Enum): + TIME = "Seconds" + REPS = "Reps" # Represents an individual exercise class Exercise(db.Model): @@ -7,13 +12,15 @@ class Exercise(db.Model): name = db.Column(db.String(100), nullable=False) sets = db.Column(db.Integer) units = db.Column(db.Integer) + type = db.Column(db.Enum(ExerciseType)) # Workout Relationship workout_id = db.Column(db.Integer, db.ForeignKey('workouts.id')) - def __init__(self, name, sets, units): + def __init__(self, name, sets, units, type): self.name = name self.sets = sets - self.unit = units + self.units = units + self.type = type def __repr__(self): return f'' @@ -34,7 +41,8 @@ class Workout(db.Model): # Create exercises for exercise in exercises: - self.exercises.append(Exercise(exercise['name'], exercise['sets'], exercise['units'])) + type = ExerciseType.TIME if exercise['type'] == 'time'else ExerciseType.REPS; + self.exercises.append(Exercise(exercise['name'], exercise['sets'], exercise['units'], type)) def __repr__(self): return f'' diff --git a/app/templates/base/form.html b/app/templates/base/form.html index 9f356e0..98200c9 100644 --- a/app/templates/base/form.html +++ b/app/templates/base/form.html @@ -8,17 +8,17 @@ {% with messages = get_flashed_messages(with_categories=true) %} - {% if messages %} - {% for category, message in messages %} - {% if category == "message" %} -
- {% else %} -
+ {% if messages %} + {% for category, message in messages %} + {% if category == "message" %} +
+ {% else %} +
+ {% endif %} + {{ message }} +
+ {% endfor %} {% endif %} - {{ message }} -
- {% endfor %} - {% endif %} {% endwith %}
diff --git a/app/templates/workout/create.html b/app/templates/workout/create.html index d5178fc..88095f7 100644 --- a/app/templates/workout/create.html +++ b/app/templates/workout/create.html @@ -1,5 +1,7 @@ {% extends 'base/form.html' %} +{% block title %}Create Workout{% endblock %} + {% block form %}
@@ -12,67 +14,73 @@
-
{% for entry in form.exercises.entries %}
-
-
-

+ +

+ {% for entry in form.exercises.entries %} +
+
+
+

- - - -

-

- - - - -

-
-
-

- - - - -

-
-
-
-
- -
-
- -
-
- + + + +

+

+ + + + +

+
+
+

+ + + + +

+
+
+
+
+ +
+
+ +
-

- - - -

+
+

+ + + +

+
{% endfor %}
+
-

- - - -

+

+ + + +

+
- +
- + + {% endblock %} -- cgit v1.2.3