summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstilbruch <stilbruch@protonmail.com>2022-04-23 19:21:36 -0500
committerstilbruch <stilbruch@protonmail.com>2022-04-23 19:21:36 -0500
commit87d241a10f55793e1add6b16933748cc64932173 (patch)
treefe9463a5c3ba6b55288c699093228d97c113758d
parenteff104b1e2840ad40131e7ab811448a34a896f9f (diff)
downloadStrengthy-87d241a10f55793e1add6b16933748cc64932173.tar.xz
Strengthy-87d241a10f55793e1add6b16933748cc64932173.zip
More progress on forms
-rw-r--r--app/forms/workout.py18
-rw-r--r--app/static/js/record.js5
-rw-r--r--app/tables/workout.py4
-rw-r--r--app/templates/workout/create.html21
4 files changed, 22 insertions, 26 deletions
diff --git a/app/forms/workout.py b/app/forms/workout.py
index a84eb6a..b406024 100644
--- a/app/forms/workout.py
+++ b/app/forms/workout.py
@@ -1,14 +1,20 @@
from flask_wtf import FlaskForm, Form
-from wtforms import FieldList, FormField, IntegerField, StringField
+from wtforms import FieldList, FormField, IntegerField, SelectField, StringField
from wtforms.validators import DataRequired, Email
-# Subclasses
+# /workout/create
class ExerciseCreateForm(Form):
- name = StringField("name", [DataRequired()])
+ # TODO no exercise_*, breaks workout_edit endpoint
+ exercise_name = StringField("name", [DataRequired()])
sets = IntegerField("sets", [DataRequired()])
units = IntegerField("units", [DataRequired()])
- type = StringField("type", [DataRequired()]) # TODO: make sure its time or reps
+ exercise_type = SelectField("type", [DataRequired()], choices=[('reps', 'Reps'), ('time', 'Time')])
+class WorkoutCreateForm(FlaskForm):
+ name = StringField("name", [DataRequired()])
+ exercises = FieldList(FormField(ExerciseCreateForm), min_entries=1)
+
+# /workout/record
class SetForm(Form):
lbs = IntegerField("lbs", [DataRequired()])
reps = IntegerField("reps", [DataRequired()])
@@ -17,9 +23,5 @@ class ExerciseRecordForm(Form):
sets = FieldList(FormField(SetForm))
# Actual forms
-class WorkoutCreateForm(FlaskForm):
- name = StringField("name", [DataRequired()])
- exercises = FieldList(FormField(ExerciseCreateForm), min_entries=1)
-
class WorkoutRecordForm(FlaskForm):
exercises = FieldList(FormField(ExerciseRecordForm))
diff --git a/app/static/js/record.js b/app/static/js/record.js
index 67ad2a6..aa5a3b3 100644
--- a/app/static/js/record.js
+++ b/app/static/js/record.js
@@ -4,10 +4,7 @@ allInputs = Array.from(document.getElementsByClassName('input'))
allInputs.forEach(e => e.addEventListener('keypress', handleEnterKey));
function handleEnterKey(event) {
-
- // add ids to each input programatically
-
- if (event.key = 'Enter') {
+ if (event.key === "Enter") {
event.preventDefault();
//Isolate the node that we're after
diff --git a/app/tables/workout.py b/app/tables/workout.py
index 164f547..564caf1 100644
--- a/app/tables/workout.py
+++ b/app/tables/workout.py
@@ -41,8 +41,8 @@ class Workout(db.Model):
# Create exercises
for exercise in exercises:
- type = ExerciseType.TIME if exercise['type'] == 'time'else ExerciseType.REPS;
- self.exercises.append(Exercise(exercise['name'], exercise['sets'], exercise['units'], type))
+ type = ExerciseType.TIME if exercise['exercise_type'] == 'time' else ExerciseType.REPS;
+ self.exercises.append(Exercise(exercise['exercise_name'], exercise['sets'], exercise['units'], type))
def __repr__(self):
return f'<Workout {self.name}>'
diff --git a/app/templates/workout/create.html b/app/templates/workout/create.html
index 88095f7..0336e1c 100644
--- a/app/templates/workout/create.html
+++ b/app/templates/workout/create.html
@@ -6,10 +6,11 @@
<div class="field is-horizontal">
<div class="field-body">
<div class="field">
- <p class="control is-expanded has-icons-left"> <input class="input" name="name" type="text" placeholder="Workout Name", value="{{ form.name.data or "" }}">
- <span class="icon is-small is-left">
- <i class="fa fa-tag"></i>
- </span>
+ <p class="control is-expanded has-icons-left">
+ {{ form.name(class_='input', placeholder='Workout Name') }}
+ <span class="icon is-small is-left">
+ <i class="fa fa-tag"></i>
+ </span>
</p>
</div>
</div>
@@ -21,13 +22,12 @@
<div class="field-body">
<div class="field">
<p class="control is-expanded has-icons-left">
- <input class="input" name='exercises-0-name' type="text" placeholder="Exercise Name", value="{{ entry.data['name'] or "" }}">
+ {{ entry.exercise_name(class_='input', placeholder='Name') }}
<span class="icon is-small is-left">
<i class="fa fa-tag"></i>
</span>
</p>
<p class="control is-expanded has-icons-left">
- <input class="input" name='exercises-0-reps' type="hidden" placeholder="Reps" min="1" value="{{ entry.data['reps'] or "" }}">
<span class="icon is-small is-left">
<i class="fa"></i>
</span>
@@ -35,7 +35,7 @@
</div>
<div class="field">
<p class="control is-expanded has-icons-left">
- <input class="input" name='exercises-0-sets' type="number" placeholder="Sets" min="1" value="{{ entry.data['sets'] or "" }}">
+ {{ entry.sets(class_='input', placeholder='Sets') }}
<span class="icon is-small is-left">
<i class="fa fa-calculator"></i>
</span>
@@ -44,16 +44,13 @@
<div class="field has-addons">
<div class="control has-icons-left">
<div class="select">
- <select name="exercise-0-type">
- <option value="reps">Reps</option>
- <option value="time">Time</option>
- </select>
+ {{ entry.exercise_type() }}
</div>
<div class="icon is-small is-left">
<i class="fa fa-calculator"></i>
</div>
</div>
- <input class="input" name='exercises-0-units' type="number" placeholder="Reps" min="1" value="{{ entry.data['units'] or "" }}">
+ {{ entry.units(class_='input') }}
</div>
<p class="button is-danger" onclick="handleDel(this)">
<span class="icon is-small">