feat: update version to 0.7.8 and enhance exercise variant handling
- Incremented application version to 0.7.8 and updated database schema version to 20260427030. - Added support for including exercise variants in the exercise listing API, improving training planning capabilities. - Enhanced training unit creation and update logic to validate exercise variant IDs, ensuring proper associations. - Updated frontend components to support exercise variant selection, improving user experience in training planning.
This commit is contained in:
1 parent
2c831d6cea
commit
cf9f95377c
6 files changed
+190
-39
No files matched your search
@@ -50,7 +50,7 @@ function TrainingPlanningPage() {
|
||||
try {
|
||||
const [groupsData, exercisesData] = await Promise.all([
|
||||
api.listTrainingGroups({ status: 'active' }),
|
||||
api.listExercises()
|
||||
api.listExercises({ include_variants: true })
|
||||
])
|
||||
setGroups(groupsData)
|
||||
setExercises(exercisesData)
|
||||
@@ -179,9 +179,20 @@ function TrainingPlanningPage() {
|
||||
...formData,
|
||||
group_id: parseInt(formData.group_id),
|
||||
attendance_count: formData.attendance_count ? parseInt(formData.attendance_count) : null,
|
||||
exercises: formData.exercises.map((ex, idx) => ({
|
||||
exercises: formData.exercises
|
||||
.filter(
|
||||
(ex) =>
|
||||
ex.exercise_id !== '' &&
|
||||
ex.exercise_id != null &&
|
||||
!Number.isNaN(Number(ex.exercise_id))
|
||||
)
|
||||
.map((ex, idx) => ({
|
||||
exercise_id: ex.exercise_id,
|
||||
order_index: idx,
|
||||
exercise_variant_id:
|
||||
ex.exercise_variant_id !== '' && ex.exercise_variant_id != null
|
||||
? parseInt(ex.exercise_variant_id, 10)
|
||||
: null,
|
||||
planned_duration_min: ex.planned_duration_min ? parseInt(ex.planned_duration_min) : null,
|
||||
actual_duration_min: ex.actual_duration_min ? parseInt(ex.actual_duration_min) : null,
|
||||
notes: ex.notes || null,
|
||||
@@ -211,6 +222,7 @@ function TrainingPlanningPage() {
|
||||
...prev,
|
||||
exercises: [...prev.exercises, {
|
||||
exercise_id: '',
|
||||
exercise_variant_id: '',
|
||||
planned_duration_min: '',
|
||||
actual_duration_min: '',
|
||||
notes: '',
|
||||
@@ -222,9 +234,14 @@ function TrainingPlanningPage() {
|
||||
const updateExercise = (index, field, value) => {
|
||||
setFormData(prev => ({
|
||||
...prev,
|
||||
exercises: prev.exercises.map((ex, i) =>
|
||||
i === index ? { ...ex, [field]: value } : ex
|
||||
)
|
||||
exercises: prev.exercises.map((ex, i) => {
|
||||
if (i !== index) return ex
|
||||
const next = { ...ex, [field]: value }
|
||||
if (field === 'exercise_id') {
|
||||
next.exercise_variant_id = ''
|
||||
}
|
||||
return next
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -496,17 +513,21 @@ function TrainingPlanningPage() {
|
||||
</p>
|
||||
) : (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: '0.5rem', marginBottom: '1rem' }}>
|
||||
{formData.exercises.map((ex, idx) => (
|
||||
{formData.exercises.map((ex, idx) => {
|
||||
const picked = exercises.find((e) => e.id === ex.exercise_id)
|
||||
const variantOpts = Array.isArray(picked?.variants) ? picked.variants : []
|
||||
|
||||
return (
|
||||
<div key={idx} style={{
|
||||
display: 'grid',
|
||||
gridTemplateColumns: '30px 1fr 80px auto',
|
||||
gridTemplateColumns: '30px minmax(0, 1fr) 80px auto',
|
||||
gap: '0.5rem',
|
||||
alignItems: 'center',
|
||||
alignItems: 'start',
|
||||
padding: '0.5rem',
|
||||
background: 'var(--surface2)',
|
||||
borderRadius: '8px'
|
||||
}}>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: '2px' }}>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: '2px', paddingTop: '6px' }}>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => moveExercise(idx, -1)}
|
||||
@@ -539,19 +560,47 @@ function TrainingPlanningPage() {
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<select
|
||||
className="form-input"
|
||||
value={ex.exercise_id}
|
||||
onChange={(e) => updateExercise(idx, 'exercise_id', parseInt(e.target.value))}
|
||||
style={{ margin: 0 }}
|
||||
>
|
||||
<option value="">Übung wählen</option>
|
||||
{exercises.map(exercise => (
|
||||
<option key={exercise.id} value={exercise.id}>
|
||||
{exercise.title}
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: '6px', minWidth: 0 }}>
|
||||
<select
|
||||
className="form-input"
|
||||
value={ex.exercise_id === '' || ex.exercise_id == null ? '' : String(ex.exercise_id)}
|
||||
onChange={(e) => {
|
||||
const raw = e.target.value
|
||||
updateExercise(idx, 'exercise_id', raw === '' ? '' : parseInt(raw, 10))
|
||||
}}
|
||||
style={{ margin: 0 }}
|
||||
>
|
||||
<option value="">Übung wählen</option>
|
||||
{exercises.map(exercise => (
|
||||
<option key={exercise.id} value={exercise.id}>
|
||||
{exercise.title}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<select
|
||||
className="form-input"
|
||||
value={
|
||||
ex.exercise_variant_id === '' || ex.exercise_variant_id == null
|
||||
? ''
|
||||
: String(ex.exercise_variant_id)
|
||||
}
|
||||
onChange={(e) => {
|
||||
const raw = e.target.value
|
||||
updateExercise(idx, 'exercise_variant_id', raw === '' ? '' : parseInt(raw, 10))
|
||||
}}
|
||||
disabled={!ex.exercise_id || variantOpts.length === 0}
|
||||
style={{ margin: 0, fontSize: '0.875rem' }}
|
||||
>
|
||||
<option value="">
|
||||
{variantOpts.length === 0 ? 'Keine Varianten hinterlegt' : 'Stammübung (ohne Variante)'}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
{variantOpts.map((v) => (
|
||||
<option key={v.id} value={v.id}>
|
||||
{v.variant_name || `Variante #${v.id}`}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<input
|
||||
type="number"
|
||||
@@ -576,7 +625,8 @@ function TrainingPlanningPage() {
|
||||
✗
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
@@ -214,6 +214,10 @@ export async function listExercises(filters = {}) {
|
||||
const q = new URLSearchParams()
|
||||
Object.entries(filters).forEach(([k, v]) => {
|
||||
if (v === undefined || v === null) return
|
||||
if (typeof v === 'boolean') {
|
||||
if (v) q.set(k, 'true')
|
||||
return
|
||||
}
|
||||
if (Array.isArray(v)) {
|
||||
if (v.length === 0) return
|
||||
v.forEach((item) => {
|
||||
|
||||
Reference in new issue
Block a user