Modified Group Selector to allow None. Workout no longer saved back to
Template.
This commit is contained in:
parent
2a3574652f
commit
3cbaaf82f6
6 changed files with 270 additions and 50 deletions
37
csv files/back_202603181941.csv
Normal file
37
csv files/back_202603181941.csv
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
date,group,type,exercise,set,weight,reps,notes
|
||||||
|
2024-11-21,Primary,Back,One-arm row,1,40,8,
|
||||||
|
2024-11-21,Secondary,Arms,Hammer curl,1,20,8,
|
||||||
|
2024-11-21,Core,Core,Swiss-ball crunch,1,0,25,
|
||||||
|
2024-11-21,Primary,Back,One-arm row,2,40,8,
|
||||||
|
2024-11-21,Secondary,Arms,Hammer curl,2,20,8,
|
||||||
|
2024-11-21,Core,Core,Swiss-ball crunch,2,0,25,
|
||||||
|
2024-11-21,Primary,Back,One-arm row,3,40,8,
|
||||||
|
2024-11-21,Secondary,Arms,Hammer curl,3,20,8,
|
||||||
|
2024-11-21,Core,Core,Swiss-ball crunch,3,0,25,
|
||||||
|
2024-11-21,Primary,Back,One-arm row,4,40,8,SS 35 30
|
||||||
|
2024-11-21,Secondary,Arms,Hammer curl,4,20,8,SS 15 10
|
||||||
|
2024-11-21,Core,Core,Swiss-ball crunch,4,0,25,
|
||||||
|
2024-11-21,Primary,Back,Lat pulldown,1,90,8,
|
||||||
|
2024-11-21,Secondary,Arms,Concentration dumbbell curl,1,15,8,
|
||||||
|
2024-11-21,Core,Core,Decline twisting ab crunch,1,0,10,
|
||||||
|
2024-11-21,Primary,Back,Lat pulldown,2,90,8,
|
||||||
|
2024-11-21,Secondary,Arms,Concentration dumbbell curl,2,15,8,
|
||||||
|
2024-11-21,Core,Core,Decline twisting ab crunch,2,0,10,
|
||||||
|
2024-11-21,Primary,Back,Lat pulldown,3,90,8,
|
||||||
|
2024-11-21,Secondary,Arms,Concentration dumbbell curl,3,15,8,
|
||||||
|
2024-11-21,Core,Core,Decline twisting ab crunch,3,0,10,
|
||||||
|
2024-11-21,Primary,Back,Lat pulldown,4,90,8,SS 80 70
|
||||||
|
2024-11-21,Secondary,Arms,Concentration dumbbell curl,4,15,8,SS 12.5 10
|
||||||
|
2024-11-21,Core,Core,Decline twisting ab crunch,4,0,10,
|
||||||
|
2024-11-21,Primary,Back,Cable seated close row,1,70,8,
|
||||||
|
2024-11-21,Secondary,Arms,Cable Underhand Close Grip Pulldown,1,70,8,
|
||||||
|
2024-11-21,Core,Core,Abdominal reverse curl,1,0,10,
|
||||||
|
2024-11-21,Primary,Back,Cable seated close row,2,70,8,
|
||||||
|
2024-11-21,Secondary,Arms,Cable Underhand Close Grip Pulldown,2,70,8,
|
||||||
|
2024-11-21,Core,Core,Abdominal reverse curl,2,0,10,
|
||||||
|
2024-11-21,Primary,Back,Cable seated close row,3,70,8,
|
||||||
|
2024-11-21,Secondary,Arms,Cable Underhand Close Grip Pulldown,3,70,8,
|
||||||
|
2024-11-21,Core,Core,Abdominal reverse curl,3,0,10,
|
||||||
|
2024-11-21,Primary,Back,Cable seated close row,4,70,8,SS 60 50
|
||||||
|
2024-11-21,Secondary,Arms,Cable Underhand Close Grip Pulldown,4,70,8,SS 60 50
|
||||||
|
2024-11-21,Core,Core,Abdominal reverse curl,4,0,10,
|
||||||
|
37
csv files/chest_202603181941.csv
Normal file
37
csv files/chest_202603181941.csv
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
date,group,type,exercise,set,weight,reps,notes
|
||||||
|
2024-11-21,Primary,Chest,Barbell bench press,1,40,8,
|
||||||
|
2024-11-21,Secondary,Arms,Triceps kickback,1,15,8,
|
||||||
|
2024-11-21,Core,Core,Swiss-ball crunch,1,0,25,
|
||||||
|
2024-11-21,Primary,Chest,Barbell bench press,2,40,8,
|
||||||
|
2024-11-21,Secondary,Arms,Triceps kickback,2,15,8,
|
||||||
|
2024-11-21,Core,Core,Swiss-ball crunch,2,0,25,
|
||||||
|
2024-11-21,Primary,Chest,Barbell bench press,3,40,8,
|
||||||
|
2024-11-21,Secondary,Arms,Triceps kickback,3,15,8,
|
||||||
|
2024-11-21,Core,Core,Swiss-ball crunch,3,0,25,
|
||||||
|
2024-11-21,Primary,Chest,Barbell bench press,4,40,8,SS 35 30
|
||||||
|
2024-11-21,Secondary,Arms,Triceps kickback,4,15,8,SS 12.5 10
|
||||||
|
2024-11-21,Core,Core,Swiss-ball crunch,4,0,25,
|
||||||
|
2024-11-21,Primary,Chest,Decline dumbbell bench press,1,35,8,
|
||||||
|
2024-11-21,Secondary,Core,Decline twisting ab crunch,1,0,10,
|
||||||
|
2024-11-21,Core,Arms,Cable triceps pushdown,1,35,8,
|
||||||
|
2024-11-21,Primary,Chest,Decline dumbbell bench press,2,35,8,
|
||||||
|
2024-11-21,Secondary,Core,Decline twisting ab crunch,2,0,10,
|
||||||
|
2024-11-21,Core,Arms,Cable triceps pushdown,2,35,8,
|
||||||
|
2024-11-21,Primary,Chest,Decline dumbbell bench press,3,35,8,
|
||||||
|
2024-11-21,Secondary,Core,Decline twisting ab crunch,3,0,10,
|
||||||
|
2024-11-21,Core,Arms,Cable triceps pushdown,3,35,8,
|
||||||
|
2024-11-21,Primary,Chest,Decline dumbbell bench press,4,35,8,SS 30 25
|
||||||
|
2024-11-21,Secondary,Core,Decline twisting ab crunch,4,0,10,
|
||||||
|
2024-11-21,Core,Arms,Cable triceps pushdown,4,35,8,SS 30 25
|
||||||
|
2024-11-21,Primary,Chest,Incline dumbbell fly,1,15,8,
|
||||||
|
2024-11-21,Secondary,Arms,Standing single-arm triceps extension,1,15,8,
|
||||||
|
2024-11-21,Core,Core,Abdominal reverse curl,1,0,10,
|
||||||
|
2024-11-21,Primary,Chest,Incline dumbbell fly,2,15,8,
|
||||||
|
2024-11-21,Secondary,Arms,Standing single-arm triceps extension,2,15,8,
|
||||||
|
2024-11-21,Core,Core,Abdominal reverse curl,2,0,10,
|
||||||
|
2024-11-21,Primary,Chest,Incline dumbbell fly,3,15,8,
|
||||||
|
2024-11-21,Secondary,Arms,Standing single-arm triceps extension,3,15,8,
|
||||||
|
2024-11-21,Core,Core,Abdominal reverse curl,3,0,10,
|
||||||
|
2024-11-21,Primary,Chest,Incline dumbbell fly,4,15,8,SS 12.5 10
|
||||||
|
2024-11-21,Secondary,Arms,Standing single-arm triceps extension,4,15,8,SS 12.5 10
|
||||||
|
2024-11-21,Core,Core,Abdominal reverse curl,4,0,10,
|
||||||
|
67
csv files/exercises_202603181942.csv
Normal file
67
csv files/exercises_202603181942.csv
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
exercise,type,group
|
||||||
|
Cable biceps curl,Arms,Secondary
|
||||||
|
Cable triceps pushdown,Arms,Secondary
|
||||||
|
Cable Underhand Close Grip Pulldown,Arms,Secondary
|
||||||
|
Chair dip (no weights),Arms,Secondary
|
||||||
|
Concentration dumbbell curl,Arms,Secondary
|
||||||
|
Drag curl,Arms,Secondary
|
||||||
|
Dumbbell biceps curl,Arms,Secondary
|
||||||
|
Dumbbell row kickback,Arms,Secondary
|
||||||
|
Hammer curl,Arms,Secondary
|
||||||
|
Kettlebell pullover,Arms,Secondary
|
||||||
|
Lying triceps extension,Arms,Secondary
|
||||||
|
Machine biceps curl,Arms,Secondary
|
||||||
|
Overhead bar press,Arms,Secondary
|
||||||
|
Prone curl,Arms,Secondary
|
||||||
|
Seated preacher curl,Arms,Secondary
|
||||||
|
Standing biceps curl,Arms,Secondary
|
||||||
|
Standing single-arm triceps extension,Arms,Secondary
|
||||||
|
Triceps kickback,Arms,Secondary
|
||||||
|
Assisted pull-up,Back,Primary
|
||||||
|
Barbell bent-over row,Back,Primary
|
||||||
|
Cable seated close row,Back,Primary
|
||||||
|
Cable seated low row,Back,Primary
|
||||||
|
Dumbbell upright row,Back,Primary
|
||||||
|
Incline y raise,Back,Primary
|
||||||
|
Lat pulldown,Back,Primary
|
||||||
|
One-arm row,Back,Primary
|
||||||
|
Seated reverse fly,Back,Primary
|
||||||
|
Barbell bench press,Chest,Primary
|
||||||
|
Cable diagonal raise,Chest,Primary
|
||||||
|
Decline dumbbell bench press,Chest,Primary
|
||||||
|
Decline dumbbell fly,Chest,Primary
|
||||||
|
Dumbbell bench press,Chest,Primary
|
||||||
|
Dumbbell incline bench press,Chest,Primary
|
||||||
|
Incline dumbbell fly,Chest,Primary
|
||||||
|
Machine chest flye,Chest,Primary
|
||||||
|
Ab crunch on a ball,Core,Core
|
||||||
|
Abdominal reverse curl,Core,Core
|
||||||
|
Bench leg raise,Core,Core
|
||||||
|
Bicycle kick,Core,Core
|
||||||
|
Decline twisting ab crunch,Core,Core
|
||||||
|
Elevated-feet plank,Core,Core
|
||||||
|
Jackknife,Core,Core
|
||||||
|
Kettlebell russian twist,Core,Core
|
||||||
|
Plank,Core,Core
|
||||||
|
Russian twist,Core,Core
|
||||||
|
Side plank,Core,Core
|
||||||
|
Superman,Core,Core
|
||||||
|
Swiss-ball crunch,Core,Core
|
||||||
|
Swiss-ball glute bridge,Core,Core
|
||||||
|
Twisting windmill,Core,Core
|
||||||
|
Two-point bridge,Core,Core
|
||||||
|
Burpees,HIIT,Core
|
||||||
|
Mountain climbers,HIIT,Core
|
||||||
|
Squat Jump,HIIT,Core
|
||||||
|
Assisted dumbbell lunge,Legs,Primary
|
||||||
|
Back squat,Legs,Primary
|
||||||
|
Beginner squat,Legs,Primary
|
||||||
|
Bulgarian split squat (no weights),Legs,Primary
|
||||||
|
Dumbbell lunge,Legs,Primary
|
||||||
|
Machine leg curl,Legs,Primary
|
||||||
|
Machine leg extension,Legs,Primary
|
||||||
|
Machine leg press,Legs,Primary
|
||||||
|
Dumbbell front raise,Shoulders,Secondary
|
||||||
|
Dumbbell lateral raise,Shoulders,Secondary
|
||||||
|
Seated dumbbell shoulder press,Shoulders,Secondary
|
||||||
|
Shrug,Shoulders,Secondary
|
||||||
|
49
csv files/legs_202603181942.csv
Normal file
49
csv files/legs_202603181942.csv
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
date,group,type,exercise,set,weight,reps,notes
|
||||||
|
2024-11-21,Primary,Shoulders,Dumbbell front raise,1,15,10,
|
||||||
|
2024-11-21,Secondary,Legs,Dumbbell Lunge,1,5,8,
|
||||||
|
2024-11-21,Core,Core,Decline twisting ab crunch,1,0,10,
|
||||||
|
2024-11-21,Primary,Shoulders,Dumbbell front raise,2,15,10,
|
||||||
|
2024-11-21,Secondary,Legs,Dumbbell lunge,2,5,8,
|
||||||
|
2024-11-21,Core,Core,Decline twisting ab crunch,2,0,10,
|
||||||
|
2024-11-21,Primary,Shoulders,Dumbbell front raise,3,15,10,
|
||||||
|
2024-11-21,Secondary,Legs,Dumbbell lunge,3,5,8,
|
||||||
|
2024-11-21,Core,Core,Decline twisting ab crunch,3,0,10,
|
||||||
|
2024-11-21,Primary,Shoulders,Dumbbell front raise,4,15,10,
|
||||||
|
2024-11-21,Secondary,Legs,Dumbbell lunge,4,5,8,
|
||||||
|
2024-11-21,Core,Core,Decline twisting ab crunch,4,0,10,
|
||||||
|
2024-11-21,Primary,Legs,Back squat,1,50,8,
|
||||||
|
2024-11-21,Secondary,Shoulders,Seated dumbbell shoulder press,1,20,8,
|
||||||
|
2024-11-21,Core,Core,Swiss-ball glute bridge,1,0,10,
|
||||||
|
2024-11-21,Primary,Legs,Back squat,2,50,8,
|
||||||
|
2024-11-21,Secondary,Shoulders,Seated dumbbell shoulder press,2,20,8,
|
||||||
|
2024-11-21,Core,Core,Swiss-ball glute bridge,2,0,10,
|
||||||
|
2024-11-21,Primary,Legs,Back squat,3,50,8,
|
||||||
|
2024-11-21,Secondary,Shoulders,Seated dumbbell shoulder press,3,20,8,
|
||||||
|
2024-11-21,Core,Core,Swiss-ball glute bridge,3,0,10,
|
||||||
|
2024-11-21,Primary,Legs,Back squat,4,50,8,
|
||||||
|
2024-11-21,Secondary,Shoulders,Seated dumbbell shoulder press,4,20,8,
|
||||||
|
2024-11-21,Core,Core,Swiss-ball glute bridge,4,0,10,
|
||||||
|
2024-11-21,Primary,Legs,Machine leg extension,1,75,8,
|
||||||
|
2024-11-21,Secondary,Shoulders,Dumbbell lateral raise,1,10,8,
|
||||||
|
2024-11-21,Core,Core,Abdominal reverse curl,1,0,10,
|
||||||
|
2024-11-21,Primary,Legs,Machine leg extension,2,75,8,
|
||||||
|
2024-11-21,Secondary,Shoulders,Dumbbell lateral raise,2,10,8,
|
||||||
|
2024-11-21,Core,Core,Abdominal reverse curl,2,0,10,
|
||||||
|
2024-11-21,Primary,Legs,Machine leg extension,3,75,8,
|
||||||
|
2024-11-21,Secondary,Shoulders,Dumbbell lateral raise,3,10,8,
|
||||||
|
2024-11-21,Core,Core,Abdominal reverse curl,3,0,10,
|
||||||
|
2024-11-21,Primary,Legs,Machine leg extension,4,75,8,
|
||||||
|
2024-11-21,Secondary,Shoulders,Dumbbell lateral raise,4,10,8,
|
||||||
|
2024-11-21,Core,Core,Abdominal reverse curl,4,0,10,
|
||||||
|
2024-11-21,Primary,Legs,Machine leg curl,1,35,8,
|
||||||
|
2024-11-21,Secondary,Shoulders,Shrug,1,40,8,
|
||||||
|
2024-11-21,Core,Core,Swiss-ball crunch,1,0,20,
|
||||||
|
2024-11-21,Primary,Legs,Machine leg curl,2,35,8,
|
||||||
|
2024-11-21,Secondary,Shoulders,Shrug,2,40,8,
|
||||||
|
2024-11-21,Core,Core,Swiss-ball crunch,2,0,20,
|
||||||
|
2024-11-21,Primary,Legs,Machine leg curl,3,35,8,
|
||||||
|
2024-11-21,Secondary,Shoulders,Shrug,3,40,8,
|
||||||
|
2024-11-21,Core,Core,Swiss-ball crunch,3,0,20,
|
||||||
|
2024-11-21,Primary,Legs,Machine leg curl,4,35,8,
|
||||||
|
2024-11-21,Secondary,Shoulders,Shrug,4,40,8,
|
||||||
|
2024-11-21,Core,Core,Swiss-ball crunch,4,0,20,
|
||||||
|
|
|
@ -160,8 +160,8 @@
|
||||||
<thead class="table-dark">
|
<thead class="table-dark">
|
||||||
<tr>
|
<tr>
|
||||||
<th class="col-ex">Exercise</th>
|
<th class="col-ex">Exercise</th>
|
||||||
<th class="col-grp">Group</th>
|
<th class="col-grp text-center">Group</th>
|
||||||
<th class="col-set">Set</th>
|
<th class="col-set text-center">Set</th>
|
||||||
<th class="col-rp">Reps</th>
|
<th class="col-rp">Reps</th>
|
||||||
<th class="col-wt">Weight</th>
|
<th class="col-wt">Weight</th>
|
||||||
<th class="col-nt">Note</th>
|
<th class="col-nt">Note</th>
|
||||||
|
|
@ -212,7 +212,7 @@
|
||||||
<thead>
|
<thead>
|
||||||
<tr class="small text-muted">
|
<tr class="small text-muted">
|
||||||
<th>Exercise</th>
|
<th>Exercise</th>
|
||||||
<th>Set</th>
|
<th class="text-center">Set</th>
|
||||||
<th>Reps</th>
|
<th>Reps</th>
|
||||||
<th>Weight</th>
|
<th>Weight</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
@ -231,6 +231,26 @@
|
||||||
const exercises = {{ exercises_json|safe }};
|
const exercises = {{ exercises_json|safe }};
|
||||||
const templates = {{ templates_json|safe }};
|
const templates = {{ templates_json|safe }};
|
||||||
|
|
||||||
|
// Object to track if a user has explicitly made a selection for a dropdown
|
||||||
|
const userMadeSelection = {
|
||||||
|
primarySelect: false,
|
||||||
|
secondarySelect: false,
|
||||||
|
coreSelect: false
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add event listeners to track user selections when the DOM is fully loaded
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
document.getElementById('primarySelect').addEventListener('change', () => {
|
||||||
|
userMadeSelection.primarySelect = true;
|
||||||
|
});
|
||||||
|
document.getElementById('secondarySelect').addEventListener('change', () => {
|
||||||
|
userMadeSelection.secondarySelect = true;
|
||||||
|
});
|
||||||
|
document.getElementById('coreSelect').addEventListener('change', () => {
|
||||||
|
userMadeSelection.coreSelect = true;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
function filterExercises() {
|
function filterExercises() {
|
||||||
const template = document.getElementById('templateSelect').value;
|
const template = document.getElementById('templateSelect').value;
|
||||||
document.getElementById('formTemplateName').value = template;
|
document.getElementById('formTemplateName').value = template;
|
||||||
|
|
@ -248,7 +268,7 @@
|
||||||
|
|
||||||
function populateDropdown(id, group, types) {
|
function populateDropdown(id, group, types) {
|
||||||
const select = document.getElementById(id);
|
const select = document.getElementById(id);
|
||||||
select.innerHTML = '<option value="">...</option>';
|
select.innerHTML = '<option value="">None</option>'; // Changed default option to "None"
|
||||||
exercises.forEach(ex => {
|
exercises.forEach(ex => {
|
||||||
if (ex.group === group && (types.length === 0 || types.includes(ex.type))) {
|
if (ex.group === group && (types.length === 0 || types.includes(ex.type))) {
|
||||||
const opt = document.createElement('option');
|
const opt = document.createElement('option');
|
||||||
|
|
@ -277,10 +297,10 @@
|
||||||
return `
|
return `
|
||||||
<tr>
|
<tr>
|
||||||
<td class="col-ex text-truncate-mobile">${exName}<input type="hidden" class="d-ex" value="${exName}"></td>
|
<td class="col-ex text-truncate-mobile">${exName}<input type="hidden" class="d-ex" value="${exName}"></td>
|
||||||
<td class="col-grp">${group}<input type="hidden" class="d-gr" value="${group}"><input type="hidden" class="d-ty" value="${type}"></td>
|
<td class="col-grp text-center">${group}<input type="hidden" class="d-gr" value="${group}"><input type="hidden" class="d-ty" value="${type}"></td>
|
||||||
<td class="col-set">${set}<input type="hidden" class="d-st" value="${set}"></td>
|
<td class="col-set text-center">${set}<input type="hidden" class="d-st" value="${set}"></td>
|
||||||
<td class="col-rp"><input type="number" inputmode="numeric" class="table-input d-rp" value="${reps}"></td>
|
<td class="col-rp"><input type="number" inputmode="numeric" class="table-input d-rp" value="${reps}"></td>
|
||||||
<td class="col-wt"><input type="number" inputmode="decimal" class="table-input d-wt" step="0.5" value="${weight}"></td>
|
<td class="col-wt"><input type="number" inputmode="decimal" class="table-input d-wt" step="2.5" value="${parseFloat(weight).toFixed(1)}"></td>
|
||||||
<td class="col-nt"><input type="text" class="table-input d-nt" value="${notes}" placeholder="..."></td>
|
<td class="col-nt"><input type="text" class="table-input d-nt" value="${notes}" placeholder="..."></td>
|
||||||
</tr>`;
|
</tr>`;
|
||||||
}
|
}
|
||||||
|
|
@ -301,7 +321,12 @@
|
||||||
|
|
||||||
function setDropdownIfEmpty(id, value) {
|
function setDropdownIfEmpty(id, value) {
|
||||||
const select = document.getElementById(id);
|
const select = document.getElementById(id);
|
||||||
if (select && select.value === "") select.value = value;
|
// Only set the value if the dropdown is currently "None" (empty value)
|
||||||
|
// AND the user has not explicitly made a selection for this dropdown before.
|
||||||
|
// This prevents overwriting a user's explicit "None" choice or another selection.
|
||||||
|
if (select && select.value === "" && !userMadeSelection[id]) {
|
||||||
|
select.value = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateTable() {
|
function generateTable() {
|
||||||
|
|
@ -315,13 +340,17 @@
|
||||||
{ el: document.getElementById('coreSelect'), group: 'Core' }
|
{ el: document.getElementById('coreSelect'), group: 'Core' }
|
||||||
];
|
];
|
||||||
|
|
||||||
if (selects.some(s => !s.el.value)) { alert("Select 3 exercises"); return; }
|
// Removed the check that required 3 exercises to be selected, allowing "None"
|
||||||
|
// if (selects.some(s => !s.el.value)) { alert("Select 3 exercises"); return; }
|
||||||
|
|
||||||
for (let set = 1; set <= 4; set++) {
|
for (let set = 1; set <= 4; set++) {
|
||||||
selects.forEach(s => {
|
selects.forEach(s => {
|
||||||
const opt = s.el.options[s.el.selectedIndex];
|
// Only generate rows for exercises that are actually selected (not "None")
|
||||||
const match = templateData.find(row => row.exercise === s.el.value && row.set === set);
|
if (s.el.value) {
|
||||||
tbody.insertAdjacentHTML('beforeend', getRowHtml(s.el.value, s.group, opt.dataset.type, set, match?.reps || 0, match?.weight || 0, match?.notes || ''));
|
const opt = s.el.options[s.el.selectedIndex];
|
||||||
|
const match = templateData.find(row => row.exercise === s.el.value && row.set === set);
|
||||||
|
tbody.insertAdjacentHTML('beforeend', getRowHtml(s.el.value, s.group, opt.dataset.type, set, match?.reps || 0, match?.weight || 0, match?.notes || ''));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -362,7 +391,7 @@
|
||||||
nt: row.querySelector('.d-nt').value
|
nt: row.querySelector('.d-nt').value
|
||||||
};
|
};
|
||||||
|
|
||||||
logBody.insertAdjacentHTML('beforeend', `<tr><td>${data.ex}</td><td>${data.st}</td><td>${data.rp}</td><td>${data.wt}</td></tr>`);
|
logBody.insertAdjacentHTML('beforeend', `<tr><td>${data.ex}</td><td class="text-center">${data.st}</td><td>${data.rp}</td><td>${data.wt}</td></tr>`);
|
||||||
hiddenDiv.insertAdjacentHTML('beforeend', `
|
hiddenDiv.insertAdjacentHTML('beforeend', `
|
||||||
<input type="hidden" name="exercise[]" value="${data.ex}">
|
<input type="hidden" name="exercise[]" value="${data.ex}">
|
||||||
<input type="hidden" name="group[]" value="${data.gr}">
|
<input type="hidden" name="group[]" value="${data.gr}">
|
||||||
|
|
|
||||||
|
|
@ -1,64 +1,65 @@
|
||||||
from django.shortcuts import render, redirect
|
|
||||||
from django.db import transaction
|
|
||||||
from .models import Exercise, Workout, ChestTemplate, BackTemplate, LegsTemplate
|
|
||||||
import json
|
import json
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
from django.core.serializers.json import DjangoJSONEncoder
|
from django.core.serializers.json import DjangoJSONEncoder
|
||||||
|
from django.db import transaction
|
||||||
|
from django.shortcuts import redirect, render
|
||||||
|
|
||||||
|
from .models import BackTemplate, ChestTemplate, Exercise, LegsTemplate, Workout
|
||||||
|
|
||||||
|
|
||||||
def workout_tracker(request):
|
def workout_tracker(request):
|
||||||
template_models = {
|
template_models = {
|
||||||
'Chest': ChestTemplate,
|
"Chest": ChestTemplate,
|
||||||
'Back': BackTemplate,
|
"Back": BackTemplate,
|
||||||
'Legs': LegsTemplate,
|
"Legs": LegsTemplate,
|
||||||
}
|
}
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == "POST":
|
||||||
# Data comes in as lists from the form
|
# Data comes in as lists from the form
|
||||||
selected_template = request.POST.get('template_name')
|
selected_template = request.POST.get("template_name")
|
||||||
exercises = request.POST.getlist('exercise[]')
|
exercises = request.POST.getlist("exercise[]")
|
||||||
groups = request.POST.getlist('group[]')
|
groups = request.POST.getlist("group[]")
|
||||||
types = request.POST.getlist('type[]')
|
types = request.POST.getlist("type[]")
|
||||||
sets = request.POST.getlist('set[]')
|
sets = request.POST.getlist("set[]")
|
||||||
weights = request.POST.getlist('weight[]')
|
weights = request.POST.getlist("weight[]")
|
||||||
reps = request.POST.getlist('reps[]')
|
reps = request.POST.getlist("reps[]")
|
||||||
notes = request.POST.getlist('notes[]')
|
notes = request.POST.getlist("notes[]")
|
||||||
|
|
||||||
TemplateModel = template_models.get(selected_template)
|
TemplateModel = template_models.get(selected_template)
|
||||||
|
|
||||||
if TemplateModel and exercises:
|
if TemplateModel and exercises:
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
# 1. Clear the specific Template table to replace with new data
|
# Iterate and save to Workouts (History) only
|
||||||
TemplateModel.objects.all().delete()
|
|
||||||
|
|
||||||
# 2. Iterate and save to both Workouts (History) and Template (Current)
|
|
||||||
for i in range(len(exercises)):
|
for i in range(len(exercises)):
|
||||||
row_data = {
|
row_data = {
|
||||||
'group': groups[i],
|
"group": groups[i],
|
||||||
'type': types[i],
|
"type": types[i],
|
||||||
'exercise': exercises[i],
|
"exercise": exercises[i],
|
||||||
'set': int(sets[i]),
|
"set": int(sets[i]),
|
||||||
'weight': float(weights[i] or 0),
|
"weight": float(weights[i] or 0),
|
||||||
'reps': int(reps[i] or 0),
|
"reps": int(reps[i] or 0),
|
||||||
'notes': notes[i]
|
"notes": notes[i],
|
||||||
}
|
}
|
||||||
|
|
||||||
# Save to history
|
# Save to history
|
||||||
Workout.objects.create(**row_data)
|
Workout.objects.create(**row_data)
|
||||||
# Save to template (date will auto-set to today)
|
|
||||||
TemplateModel.objects.create(**row_data)
|
|
||||||
|
|
||||||
return redirect('workout_tracker')
|
return redirect("workout_tracker")
|
||||||
|
|
||||||
# GET: Fetch exercises for dropdowns
|
# GET: Fetch exercises for dropdowns
|
||||||
exercises = list(Exercise.objects.values('exercise', 'type', 'group'))
|
exercises = list(Exercise.objects.values("exercise", "type", "group"))
|
||||||
|
|
||||||
# Fetch current template data to seed the view
|
# Fetch current template data to seed the view
|
||||||
templates_data = {
|
templates_data = {
|
||||||
name: list(model.objects.values())
|
name: list(model.objects.values()) for name, model in template_models.items()
|
||||||
for name, model in template_models.items()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return render(request, 'tracker/index.html', {
|
return render(
|
||||||
'exercises_json': json.dumps(exercises),
|
request,
|
||||||
'templates_json': json.dumps(templates_data, cls=DjangoJSONEncoder)
|
"tracker/index.html",
|
||||||
})
|
{
|
||||||
|
"exercises_json": json.dumps(exercises),
|
||||||
|
"templates_json": json.dumps(templates_data, cls=DjangoJSONEncoder),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue