Update programs functionality

This commit is contained in:
Peter Stockings
2026-02-03 15:10:59 +11:00
parent b26ae1e319
commit ac093ec2e0
7 changed files with 849 additions and 210 deletions

View File

@@ -96,7 +96,7 @@
{# Nested Template for a single exercise row within a session #}
<template id="exercise-row-template">
<div class="exercise-row flex items-center space-x-2">
<div class="exercise-row flex items-center space-x-4 bg-white p-2 rounded border border-gray-100 shadow-sm">
<div class="flex-grow relative">
{{ render_partial('partials/custom_select.html',
name='exercises_SESSION_INDEX_PLACEHOLDER',
@@ -106,6 +106,16 @@
placeholder='Select Exercise...')
}}
</div>
<div class="w-16">
<input type="number" name="sets_SESSION_INDEX_PLACEHOLDER" placeholder="Sets"
class="block w-full border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"
min="1" value="3">
</div>
<div class="w-24">
<input type="text" name="reps_SESSION_INDEX_PLACEHOLDER" placeholder="Reps (e.g. 8-10)"
class="block w-full border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"
value="8-10">
</div>
<button type="button" class="remove-exercise-btn text-red-500 hover:text-red-700 flex-shrink-0"
title="Remove Exercise">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
@@ -180,10 +190,19 @@
function addExerciseSelect(container, sessionIndex) {
const newExFragment = exerciseTemplate.content.cloneNode(true);
const nativeSelect = newExFragment.querySelector('.native-select');
const setsInput = newExFragment.querySelector('input[name^="sets_"]');
const repsInput = newExFragment.querySelector('input[name^="reps_"]');
const removeBtn = newExFragment.querySelector('.remove-exercise-btn');
if (nativeSelect) {
nativeSelect.name = `exercises_${sessionIndex}`;
}
if (setsInput) {
setsInput.name = `sets_${sessionIndex}`;
}
if (repsInput) {
repsInput.name = `reps_${sessionIndex}`;
}
container.appendChild(newExFragment);
@@ -251,12 +270,22 @@
nameInput.name = `session_name_${newIndex}`;
}
// Update names for the exercise selects within this session
const exerciseSelects = row.querySelectorAll('.native-select'); // Target hidden selects
// Update names for the exercise selects and metadata within this session
const exerciseSelects = row.querySelectorAll('.native-select');
exerciseSelects.forEach(select => {
select.name = `exercises_${newIndex}`;
});
const setsInputs = row.querySelectorAll('input[name^="sets_"]');
setsInputs.forEach(input => {
input.name = `sets_${newIndex}`;
});
const repsInputs = row.querySelectorAll('input[name^="reps_"]');
repsInputs.forEach(input => {
input.name = `reps_${newIndex}`;
});
// Update listener for the "Add Exercise" button
const addExerciseBtn = row.querySelector('.add-exercise-btn');
if (addExerciseBtn) {