Ugly but functional
This commit is contained in:
parent
3229184d89
commit
dfdb88ec54
@ -22,7 +22,7 @@
|
|||||||
Today's workout type:
|
Today's workout type:
|
||||||
<select id="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="strength-endurance">Strength-Endurance</option>
|
||||||
</select>
|
</select>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
108
main.js
108
main.js
@ -1,11 +1,14 @@
|
|||||||
// for debug purposes
|
// for debug purposes
|
||||||
const t = today()
|
const t = today();
|
||||||
var exercises = {
|
var exercises = {};
|
||||||
"2021-10-19": [
|
const exercisesString = localStorage.getItem("exercises");
|
||||||
{ exerciseType: exerciseTypes[0], repetitionType: "2-4", reps: "", weight: "2" },
|
if (exercisesString != null) {
|
||||||
{ exerciseType: exerciseTypes[0], repetitionType: "2-4", reps: "3", weight: "" }
|
exercises = JSON.parse(exercisesString);
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
if (exercises[t] != null) {
|
||||||
|
exercises[t] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function updateExercises() {
|
function updateExercises() {
|
||||||
var exerciseList = document.querySelectorAll("#exercise-list > li");
|
var exerciseList = document.querySelectorAll("#exercise-list > li");
|
||||||
@ -18,53 +21,82 @@ function updateExercises() {
|
|||||||
weight: element.childNodes[8].value
|
weight: element.childNodes[8].value
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
localStorage.setItem("exercises", JSON.stringify(exercises));
|
||||||
|
}
|
||||||
|
|
||||||
|
function swap_right(i) {
|
||||||
|
if (0 <= i && i < exercises[t].length && 0 <= i + 1 && i + 1 < exercises[t].length) {
|
||||||
|
[exercises[t][i], exercises[t][i + 1]] = [exercises[t][i + 1], exercises[t][i]]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var exerciseList = document.getElementById("exercise-list");
|
var exerciseList = document.getElementById("exercise-list");
|
||||||
|
|
||||||
function setExercises(exercises) {
|
function setExercises() {
|
||||||
exerciseList.innerHTML = ''
|
exerciseList.innerHTML = ''
|
||||||
exercises.forEach(element => {
|
for (let i = 0; i < exercises[t].length; i++) {
|
||||||
var li = document.createElement("li");
|
var li = document.createElement("li");
|
||||||
|
// Up Button
|
||||||
var upButton = document.createElement("button");
|
var upButton = document.createElement("button");
|
||||||
upButton.textContent = "▲"
|
upButton.textContent = "▲"
|
||||||
upButton.id = "up";
|
upButton.id = "up";
|
||||||
|
upButton.onclick = () => {
|
||||||
|
swap_right(i - 1);
|
||||||
|
setExercises(exercises[t]);
|
||||||
|
localStorage.setItem("exercises", JSON.stringify(exercises));
|
||||||
|
};
|
||||||
li.appendChild(upButton);
|
li.appendChild(upButton);
|
||||||
|
// Down Button
|
||||||
var downButton = document.createElement("button");
|
var downButton = document.createElement("button");
|
||||||
downButton.textContent = "▼"
|
downButton.textContent = "▼"
|
||||||
downButton.id = "down";
|
downButton.id = "down";
|
||||||
|
downButton.onclick = () => {
|
||||||
|
swap_right(i);
|
||||||
|
setExercises(exercises[t]);
|
||||||
|
localStorage.setItem("exercises", JSON.stringify(exercises));
|
||||||
|
};
|
||||||
li.appendChild(downButton);
|
li.appendChild(downButton);
|
||||||
li.appendChild(document.createTextNode("Exercise "));
|
li.appendChild(document.createTextNode("Exercise "));
|
||||||
|
// Select Exercise Type
|
||||||
var exType = document.createElement("select");
|
var exType = document.createElement("select");
|
||||||
exType.onchange = updateExercises;
|
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));
|
||||||
});
|
});
|
||||||
|
exType.value = exercises[t][i].exerciseType
|
||||||
li.appendChild(exType);
|
li.appendChild(exType);
|
||||||
|
// Select Repetition Type
|
||||||
var repType = document.createElement("select");
|
var repType = document.createElement("select");
|
||||||
repetitionTypes.forEach(repetitionType => {
|
repetitionTypes.forEach(repetitionType => {
|
||||||
repType.add(new Option(repetitionType, repetitionType));
|
repType.add(new Option(repetitionType, repetitionType));
|
||||||
});
|
});
|
||||||
repType.onchange = updateExercises;
|
repType.onchange = updateExercises;
|
||||||
|
repType.value = exercises[t][i].repetitionType
|
||||||
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 = exercises[t][i].reps;
|
||||||
reps.onchange = updateExercises;
|
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 = exercises[t][i].weight;
|
||||||
weight.onchange = updateExercises;
|
weight.onchange = updateExercises;
|
||||||
li.appendChild(weight);
|
li.appendChild(weight);
|
||||||
|
// Delete Button
|
||||||
var deleteButton = document.createElement("button");
|
var deleteButton = document.createElement("button");
|
||||||
deleteButton.textContent = "Delete"
|
deleteButton.textContent = "Delete"
|
||||||
deleteButton.id = "delete-button";
|
deleteButton.id = "delete-button";
|
||||||
|
deleteButton.onclick = () => {
|
||||||
|
exercises[t].splice(i, 1);
|
||||||
|
setExercises(exercises[t]);
|
||||||
|
localStorage.setItem("exercises", JSON.stringify(exercises));
|
||||||
|
}
|
||||||
li.appendChild(deleteButton);
|
li.appendChild(deleteButton);
|
||||||
exerciseList.appendChild(li);
|
exerciseList.appendChild(li);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function exercisesEdited(exercises) {
|
function exercisesEdited(exercises) {
|
||||||
@ -86,24 +118,54 @@ function today() {
|
|||||||
|
|
||||||
var addExerciseButton = document.getElementById("add-exercise");
|
var addExerciseButton = document.getElementById("add-exercise");
|
||||||
addExerciseButton.onclick = () => {
|
addExerciseButton.onclick = () => {
|
||||||
exercises.push({ exerciseType: "", repetitionType: "", reps: "", weight: "" });
|
exercises[t].push({ exerciseType: exerciseTypes[0].name, repetitionType: repetitionTypes[0], reps: "", weight: "" });
|
||||||
setExercises(exercises);
|
setExercises(exercises);
|
||||||
}
|
}
|
||||||
|
|
||||||
function f() {
|
var muscleGroupSelector = document.getElementById("workout-muscle");
|
||||||
|
muscleGroupSelector.onchange = loadPredefinedWorkouts;
|
||||||
|
var workoutTypeSelector = document.getElementById("workout-type");
|
||||||
|
workoutTypeSelector.onchange = loadPredefinedWorkouts;
|
||||||
|
|
||||||
|
function loadPredefinedWorkouts() {
|
||||||
if (!exercisesEdited(exercises[t])) {
|
if (!exercisesEdited(exercises[t])) {
|
||||||
console.log("fish");
|
switch ((muscleGroupSelector.value, workoutTypeSelector.value)) {
|
||||||
exercises[t] = [
|
case ("leg", "strength"):
|
||||||
{ exerciseType: exerciseTypes[0], repetitionType: "2-4", reps: "", weight: "2" },
|
exercises[t] = [
|
||||||
{ exerciseType: exerciseTypes[0], repetitionType: "2-4", reps: "3", weight: "" }
|
{ exerciseType: "Squat", repetitionType: "2-4", reps: "", weight: "" },
|
||||||
];
|
{ exerciseType: "Leg Press", repetitionType: "2-4", reps: "", weight: "" },
|
||||||
|
{ exerciseType: "Deadlift", repetitionType: "2-4", reps: "", weight: "" }
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case ("back-biceps", "strength-endurance"):
|
||||||
|
exercises[t] = [
|
||||||
|
{ exerciseType: "One Arm Dumbbell Row", repetitionType: "3-5", reps: "", weight: "" },
|
||||||
|
{ exerciseType: "Lat Pulldown Wide", repetitionType: "2-4", reps: "", weight: "" },
|
||||||
|
{ exerciseType: "Lat Pulldown Narrow", repetitionType: "2-4", reps: "", weight: "" },
|
||||||
|
{ exerciseType: "Cable Row w/ Wide Neutral Grip", repetitionType: "2-4", reps: "", weight: "" },
|
||||||
|
{ exerciseType: "Rear Deltoid Machine", repetitionType: "2-4", reps: "", weight: "" },
|
||||||
|
{ exerciseType: "Biceps Curl", repetitionType: "pyramid", reps: "", weight: "" }
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
exercises[t] = [];
|
||||||
|
break;
|
||||||
|
}
|
||||||
setExercises(exercises[t]);
|
setExercises(exercises[t]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var muscleGroupSelector = document.getElementById("workout-muscle");
|
setExercises(exercises[t]);
|
||||||
muscleGroupSelector.onchange = f;
|
|
||||||
var workoutTypeSelector = document.getElementById("workout-type");
|
|
||||||
workoutTypeSelector.onchange = f;
|
|
||||||
|
|
||||||
setExercises(exercises[t]);
|
var body = document.querySelector("body");
|
||||||
|
var pre = document.createElement("pre");
|
||||||
|
const jsn = JSON.parse(localStorage.getItem("exercises"));
|
||||||
|
var s = "";
|
||||||
|
for (let [date, value] of Object.entries(jsn)) {
|
||||||
|
s += date + "\n";
|
||||||
|
for (let exercise of value) {
|
||||||
|
s += " " + exercise.exerciseType + ": " + exercise.weight + "kg x " + exercise.reps + " of " + exercise.repetitionType + "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pre.textContent = s;
|
||||||
|
body.appendChild(pre);
|
Loading…
Reference in New Issue
Block a user