Commit c7de5794 authored by Vegard Murvold Sporstøl's avatar Vegard Murvold Sporstøl
Browse files

Categorize exercises

parent a5378630
......@@ -5,6 +5,7 @@
"fields": {
"name": "Push-up",
"description": "A push-up (or press-up in British English) is a common calisthenics exercise beginning from the prone position.",
"category": "Strength",
"unit": "reps"
}
},
......@@ -14,6 +15,7 @@
"fields": {
"name": "Crunch",
"description": "The crunch is one of the most popular abdominal exercises.",
"category": "Strength",
"unit": "reps"
}
},
......@@ -23,6 +25,7 @@
"fields": {
"name": "Plank",
"description": "The plank is an isometric core strength exercise that involves maintaining a position similar to a push-up for the maximum possible time.",
"category": "Strength",
"unit": "seconds"
}
}
......
......@@ -29,6 +29,7 @@ class Migration(migrations.Migration):
),
("name", models.CharField(max_length=100)),
("description", models.TextField()),
("category", models.CharField(max_length=50)),
("unit", models.CharField(max_length=50)),
],
),
......
......@@ -76,11 +76,13 @@ class Exercise(models.Model):
Attributes:
name: Name of the exercise type
description: Description of the exercise type
category: What category the exercise fits in (e.g., endurance, strenght, balance, felxibility or other)
unit: Name of the unit for the exercise type (e.g., reps, seconds)
"""
name = models.CharField(max_length=100)
description = models.TextField()
category = models.CharField(max_length=50)
unit = models.CharField(max_length=50)
def __str__(self):
......
......@@ -201,7 +201,7 @@ class WorkoutSerializer(serializers.HyperlinkedModelSerializer):
class ExerciseSerializer(serializers.HyperlinkedModelSerializer):
"""Serializer for an Exercise. Hyperlinks are used for relationships by default.
Serialized fields: url, id, name, description, unit, instances
Serialized fields: url, id, name, description, category, unit, instances
Attributes:
instances: Associated exercise instances with this Exercise type. Hyperlinks.
......@@ -213,7 +213,7 @@ class ExerciseSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Exercise
fields = ["url", "id", "name", "description", "unit", "instances"]
fields = ["url", "id", "name", "description", "category", "unit", "instances"]
class RememberMeSerializer(serializers.HyperlinkedModelSerializer):
......
......@@ -21,70 +21,50 @@
<body>
<navbar-el></navbar-el>
<div class="container">
<div class="row">
<div class="col-lg">
<h3 class="mt-3">View/Edit Exercise</h3>
</div>
</div>
<form class="row g-3" id="form-exercise">
<div class="col-lg-6 ">
<label for="inputName" class="form-label">Name</label>
<input
type="text"
class="form-control"
id="inputName"
name="name"
readonly
/>
</div>
<div class="col-lg-6"></div>
<div class="col-lg-6">
<label for="inputDescription" class="form-label">Description</label>
<textarea
class="form-control"
id="inputDescription"
name="description"
readonly
></textarea>
</div>
<div class="col-lg-6"></div>
<div class="col-lg-6">
<label for="inputUnit" class="form-label">Unit</label>
<input
type="text"
class="form-control"
id="inputUnit"
name="unit"
readonly
/>
</div>
<div class="col-lg-6"></div>
<div class="col-lg-6">
<input
type="button"
class="btn btn-primary hide"
id="btn-ok-exercise"
value=" OK "
/>
<input
type="button"
class="btn btn-primary"
id="btn-edit-exercise"
value=" Edit "
/>
<input
type="button"
class="btn btn-secondary hide"
id="btn-cancel-exercise"
value="Cancel"
/>
<input
type="button"
class="btn btn-danger float-end hide"
id="btn-delete-exercise"
value="Delete"
/>
<div class="container">
<div class="row">
<div class="col-lg">
<h3 class="mt-3">View/Edit Exercise</h3>
</div>
</div>
<form class="row g-3" id="form-exercise">
<div class="col-lg-6 ">
<label for="inputName" class="form-label">Name</label>
<input type="text" class="form-control" id="inputName" name="name" readonly>
</div>
<div class="col-lg-6"></div>
<div class="col-lg-6">
<label for="inputDescription" class="form-label">Description</label>
<textarea class="form-control" id="inputDescription" name="description" readonly></textarea>
</div>
<div class="col-lg-6"></div>
<div class="col-lg-6">
<label for="inputCategory" class="form-label">Category</label>
<select id="inputCategory" class="form-select" name="category" disabled>
<option value="None"></option>
<option value="Endurance">Endurance</option>
<option value="Strength">Strength</option>
<option value="Balance">Balance</option>
<option value="Flexibility">Flexibility</option>
<option value="Other">Other</option>
</select>
</div>
<div class="col-lg-6"></div>
<div class="col-lg-6">
<label for="inputUnit" class="form-label">Unit</label>
<input type="text" class="form-control" id="inputUnit" name="unit" readonly>
</div>
<div class="col-lg-6"></div>
<div class="col-lg-6">
<input type="button" class="btn btn-primary hide" id="btn-ok-exercise" value=" OK ">
<input type="button" class="btn btn-primary" id="btn-edit-exercise" value=" Edit ">
<input type="button" class="btn btn-secondary hide" id="btn-cancel-exercise" value="Cancel">
<input type="button" class="btn btn-danger float-end hide" id="btn-delete-exercise" value="Delete">
</div>
<div class="col-lg-6">
</div>
</form>
</div>
<div class="col-lg-6"></div>
</form>
......
......@@ -17,10 +17,12 @@ function handleCancelButtonDuringEdit() {
let form = document.querySelector("#form-exercise");
if (oldFormData.has("name")) form.name.value = oldFormData.get("name");
if (oldFormData.has("description")) form.description.value = oldFormData.get("description");
if (oldFormData.has("category")) form.category.value = oldFormData.get("category");
if (oldFormData.has("unit")) form.unit.value = oldFormData.get("unit");
oldFormData.delete("name");
oldFormData.delete("description");
oldFormData.delete("category");
oldFormData.delete("unit");
}
......@@ -34,6 +36,7 @@ async function createExercise() {
let formData = new FormData(form);
let body = {"name": formData.get("name"),
"description": formData.get("description"),
"category": formData.get("category"),
"unit": formData.get("unit")};
let response = await sendRequest("POST", `${HOST}/api/exercises/`, body);
......@@ -90,6 +93,9 @@ async function retrieveExercise(id) {
let newVal = exerciseData[key];
input.value = newVal;
}
console.log("This is all the data: " + exerciseData)
let element = document.getElementById('inputCategory');
element.value = exerciseData.category;
}
}
......@@ -97,7 +103,8 @@ async function updateExercise(id) {
let form = document.querySelector("#form-exercise");
let formData = new FormData(form);
let body = {"name": formData.get("name"),
"description": formData.get("description"),
"description": formData.get("description"),
"category": formData.get("category"),
"unit": formData.get("unit")};
let response = await sendRequest("PUT", `${HOST}/api/exercises/${id}/`, body);
......@@ -118,6 +125,7 @@ async function updateExercise(id) {
oldFormData.delete("name");
oldFormData.delete("description");
oldFormData.delete("category");
oldFormData.delete("unit");
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment