This commit is contained in:
Jesko Dujmovic 2021-10-19 13:11:52 +02:00
parent 3dd31e4b35
commit 3229184d89
3 changed files with 89 additions and 34 deletions

View File

@ -12,25 +12,23 @@ var exerciseTypes = [
{ name: "Bench Press", tags: [] }, { name: "Bench Press", tags: [] },
{ name: "Bench Press Dumbbell", tags: [] }, { name: "Bench Press Dumbbell", tags: [] },
{ name: "Butterfly", tags: [] }, { name: "Butterfly", tags: [] },
/* { name: "Incline Bench Press", tags: [] },
"Incline Bench Press", { name: "Incline Bench Press Dumbbell", tags: [] },
"Incline Bench Press Dumbbell", { name: "Leg Press", tags: [] },
"Leg Press", { name: "Squat", tags: [] },
"Squat", { name: "Leg Curl", tags: [] },
"Leg Curl", { name: "Leg Extension", tags: [] },
"Leg Extension", { name: "Dips", tags: [] },
"Dips", { name: "Under Grip Pull Up", tags: [] },
"Under Grip Pull Up", { name: "Over Grip Pull Up", tags: [] },
"Over Grip Pull Up", { name: "Cable Biceps Curl", tags: [] },
"Cable Biceps Curl", { name: "Supported Biceps Curl", tags: [] },
"Supported Biceps Curl", { name: "Cable Triceps", tags: [] },
"Cable Triceps", { name: "Deadlift", tags: [] },
"Deadlift", { name: "Standing Calf Raises", tags: [] },
"Standing Calf Raises", { name: "Face Pull", tags: [] },
"Face Pull", { name: "Machine Shoulder Press", tags: [] },
"Machine Shoulder Press", { name: "Dumbbell Shoulder Press", tags: [] },
"Dumbbell Shoulder Press", { name: "Machine Bench Press", tags: [] },
"Machine Bench Press", { name: "21s", tags: [] }
"21s"
*/
]; ];

View File

@ -12,7 +12,7 @@
<h1>Workout</h1> <h1>Workout</h1>
<p> <p>
Today's workout muscle group: Today's workout muscle group:
<select name="workout-muscle"> <select id="workout-muscle">
<option value="chest-triceps">Chest, Triceps</option> <option value="chest-triceps">Chest, Triceps</option>
<option value="back-biceps">Back, Biceps</option> <option value="back-biceps">Back, Biceps</option>
<option value="leg">Leg</option> <option value="leg">Leg</option>
@ -20,7 +20,7 @@
</p> </p>
<p> <p>
Today's workout type: Today's workout type:
<select name="workout-type"> <select id="workout-type">
<option value="strength">Strength</option> <option value="strength">Strength</option>
<option value="strengthen-durance">Strength-Endurance</option> <option value="strengthen-durance">Strength-Endurance</option>
</select> </select>

79
main.js
View File

@ -1,15 +1,42 @@
exercises = [ // for debug purposes
{ exerciseType: exerciseTypes[0], repetitionType: "2-4", reps: "", weight: "2" }, const t = today()
{ exerciseType: exerciseTypes[0], repetitionType: "2-4", reps: "3", weight: "" } var exercises = {
] "2021-10-19": [
{ exerciseType: exerciseTypes[0], repetitionType: "2-4", reps: "", weight: "2" },
{ exerciseType: exerciseTypes[0], repetitionType: "2-4", reps: "3", weight: "" }
]
}
function updateExercises() {
var exerciseList = document.querySelectorAll("#exercise-list > li");
exercises[t] = [];
for (const element of exerciseList) {
exercises[t].push({
exerciseType: element.childNodes[3].value,
repetitionType: element.childNodes[4].value,
reps: element.childNodes[6].value,
weight: element.childNodes[8].value
});
}
}
var exerciseList = document.getElementById("exercise-list"); var exerciseList = document.getElementById("exercise-list");
function setExercises(exercises) { function setExercises(exercises) {
exerciseList.innerHTML = '' exerciseList.innerHTML = ''
exercises.forEach(element => { exercises.forEach(element => {
var li = document.createElement("li"); var li = document.createElement("li");
var upButton = document.createElement("button");
upButton.textContent = "▲"
upButton.id = "up";
li.appendChild(upButton);
var downButton = document.createElement("button");
downButton.textContent = "▼"
downButton.id = "down";
li.appendChild(downButton);
li.appendChild(document.createTextNode("Exercise ")); li.appendChild(document.createTextNode("Exercise "));
var exType = document.createElement("select"); var exType = document.createElement("select");
exType.onchange = updateExercises;
exerciseTypes.forEach(exercise => { exerciseTypes.forEach(exercise => {
exType.add(new Option(exercise.name, exercise.name)); exType.add(new Option(exercise.name, exercise.name));
}); });
@ -18,35 +45,65 @@ function setExercises(exercises) {
repetitionTypes.forEach(repetitionType => { repetitionTypes.forEach(repetitionType => {
repType.add(new Option(repetitionType, repetitionType)); repType.add(new Option(repetitionType, repetitionType));
}); });
repType.onchange = updateExercises;
li.appendChild(repType); li.appendChild(repType);
li.appendChild(document.createTextNode("Reps done: ")); li.appendChild(document.createTextNode("Reps done: "));
var reps = document.createElement("input"); var reps = document.createElement("input");
reps.setAttribute("type", "number"); reps.setAttribute("type", "number");
reps.value = element.reps; reps.value = element.reps;
reps.onchange = updateExercises;
li.appendChild(reps); li.appendChild(reps);
li.appendChild(document.createTextNode("Weight done: ")); li.appendChild(document.createTextNode("Weight done: "));
var weight = document.createElement("input"); var weight = document.createElement("input");
weight.setAttribute("type", "number"); weight.setAttribute("type", "number");
weight.value = element.weight; weight.value = element.weight;
weight.onchange = updateExercises;
li.appendChild(weight); li.appendChild(weight);
var deleteButton = document.createElement("button");
deleteButton.textContent = "Delete"
deleteButton.id = "delete-button";
li.appendChild(deleteButton);
exerciseList.appendChild(li); exerciseList.appendChild(li);
}); });
} }
function exercisesEdited() { function exercisesEdited(exercises) {
document.querySelectorAll("#exercise-list > li > input").forEach(element => { for (const element of exercises) {
if (element.value != "" && element.value != null) { if (element.reps != "" && element.reps != null) {
console.log("b"); return true;
} }
}); if (element.weight != "" && element.weight != null) {
return true;
}
};
return false; return false;
} }
function today() {
d = new Date;
return d.toISOString().split('T')[0];
}
var addExerciseButton = document.getElementById("add-exercise"); var addExerciseButton = document.getElementById("add-exercise");
addExerciseButton.onclick = () => { addExerciseButton.onclick = () => {
exercises.push({ exerciseType: "", repetitionType: "", reps: "", weight: "" }); exercises.push({ exerciseType: "", repetitionType: "", reps: "", weight: "" });
setExercises(exercises); setExercises(exercises);
} }
setExercises(exercises); function f() {
console.log(exercisesEdited()); if (!exercisesEdited(exercises[t])) {
console.log("fish");
exercises[t] = [
{ exerciseType: exerciseTypes[0], repetitionType: "2-4", reps: "", weight: "2" },
{ exerciseType: exerciseTypes[0], repetitionType: "2-4", reps: "3", weight: "" }
];
setExercises(exercises[t]);
}
}
var muscleGroupSelector = document.getElementById("workout-muscle");
muscleGroupSelector.onchange = f;
var workoutTypeSelector = document.getElementById("workout-type");
workoutTypeSelector.onchange = f;
setExercises(exercises[t]);