feat: update version to 0.7.9 and enhance exercise variant management
Deploy Development / deploy (push) Successful in 35s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 6s
Test Suite / playwright-tests (push) Failing after 2m0s

- Incremented application version to 0.7.9 and updated changelog to reflect new features.
- Added support for creating, updating, and deleting exercise variants via new API endpoints.
- Implemented functionality for reordering exercise variants, improving user experience in managing exercise options.
- Enhanced frontend components to display and manage exercise variants, including detailed information and editing capabilities.
This commit is contained in:
Lars committed 2026-04-28 10:59:09 +02:00
1 parent cf9f95377c
commit 1ee1a2f2d9
5 files changed
+837 -26

No files matched your search

+466 -2
View File
@@ -11,6 +11,82 @@ const INTENSITY_OPTIONS = [
{ value: 'hoch', label: 'hoch' },
]
const VARIANT_DIFFICULTY = [
{ value: '', label: '—' },
{ value: 'easier', label: 'Einfacher' },
{ value: 'same', label: 'Gleich' },
{ value: 'harder', label: 'Schwerer' },
{ value: 'adapted', label: 'Angepasst' },
]
function emptyVariantDraft() {
return {
variant_name: '',
description: '',
execution_changes: '',
duration_min: '',
duration_max: '',
equipment_lines: '',
difficulty_adjustment: '',
progression_level: 1,
prerequisite_variant_id: '',
}
}
function apiVariantToRow(v) {
let lines = ''
const eq = v.equipment_changes
if (Array.isArray(eq)) {
lines = eq.join('\n')
} else if (typeof eq === 'string' && eq.trim()) {
try {
const p = JSON.parse(eq)
lines = Array.isArray(p) ? p.join('\n') : eq
} catch {
lines = eq
}
}
return {
...v,
duration_min: v.duration_min ?? '',
duration_max: v.duration_max ?? '',
equipment_lines: lines,
progression_level: v.progression_level ?? 1,
prerequisite_variant_id: v.prerequisite_variant_id ?? '',
difficulty_adjustment: v.difficulty_adjustment ?? '',
}
}
function buildVariantPayloadFromRow(row) {
const lines = (row.equipment_lines || '')
.split(/[\n,]+/)
.map((s) => s.trim())
.filter(Boolean)
const pl =
row.progression_level === '' || row.progression_level == null
? 1
: parseInt(row.progression_level, 10)
const so =
row.sequence_order === '' || row.sequence_order == null
? null
: parseInt(row.sequence_order, 10)
return {
variant_name: (row.variant_name || '').trim(),
description: (row.description || '').trim() || null,
execution_changes: (row.execution_changes || '').trim() || null,
duration_min: row.duration_min === '' || row.duration_min == null ? null : parseInt(row.duration_min, 10),
duration_max: row.duration_max === '' || row.duration_max == null ? null : parseInt(row.duration_max, 10),
equipment_changes: lines,
difficulty_adjustment: row.difficulty_adjustment || null,
progression_level: Number.isNaN(pl) ? 1 : pl,
sequence_order: so !== null && Number.isNaN(so) ? null : so,
prerequisite_variant_id:
row.prerequisite_variant_id === '' || row.prerequisite_variant_id == null
? null
: parseInt(row.prerequisite_variant_id, 10),
}
}
function emptyForm() {
return {
title: '',
@@ -157,6 +233,10 @@ function ExerciseFormPage() {
const [loading, setLoading] = useState(!!isEdit)
const [saving, setSaving] = useState(false)
const [skillPick, setSkillPick] = useState('')
const [variants, setVariants] = useState([])
const [variantDraft, setVariantDraft] = useState(() => emptyVariantDraft())
const [variantSavingId, setVariantSavingId] = useState(null)
const [variantBusy, setVariantBusy] = useState(false)
const [mediaFile, setMediaFile] = useState(null)
const [mediaType, setMediaType] = useState('image')
@@ -202,6 +282,8 @@ function ExerciseFormPage() {
if (!isEdit) {
setFormData(emptyForm())
setMediaList([])
setVariants([])
setVariantDraft(emptyVariantDraft())
setLoading(false)
return
}
@@ -213,6 +295,8 @@ function ExerciseFormPage() {
if (cancelled) return
setFormData(detailToForm(exercise))
setMediaList(exercise.media || [])
setVariants((exercise.variants || []).map(apiVariantToRow))
setVariantDraft(emptyVariantDraft())
} catch (err) {
if (!cancelled) {
alert(err.message || 'Übung nicht ladbar')
@@ -304,6 +388,7 @@ function ExerciseFormPage() {
await api.updateExercise(exerciseId, payload)
const ex = await api.getExercise(exerciseId)
setMediaList(ex.media || [])
setVariants((ex.variants || []).map(apiVariantToRow))
alert('Gespeichert.')
} else {
const created = await api.createExercise(payload)
@@ -376,6 +461,85 @@ function ExerciseFormPage() {
}
}
const refreshVariants = async () => {
if (!exerciseId) return
const ex = await api.getExercise(exerciseId)
setVariants((ex.variants || []).map(apiVariantToRow))
}
const updateVariantField = (id, patch) => {
setVariants((prev) => prev.map((v) => (v.id === id ? { ...v, ...patch } : v)))
}
const saveVariantRow = async (row) => {
const payload = buildVariantPayloadFromRow(row)
if (payload.variant_name.length < 3) {
alert('Variantenname mindestens 3 Zeichen')
return
}
setVariantSavingId(row.id)
try {
await api.updateExerciseVariant(exerciseId, row.id, payload)
await refreshVariants()
} catch (e) {
alert(e.message || String(e))
} finally {
setVariantSavingId(null)
}
}
const deleteVariantRow = async (id) => {
if (!confirm('Variante wirklich löschen?')) return
setVariantBusy(true)
try {
await api.deleteExerciseVariant(exerciseId, id)
await refreshVariants()
} catch (e) {
alert(e.message || String(e))
} finally {
setVariantBusy(false)
}
}
const moveVariantRow = async (idx, dir) => {
const j = idx + dir
if (j < 0 || j >= variants.length) return
const next = [...variants]
const tmp = next[idx]
next[idx] = next[j]
next[j] = tmp
const ids = next.map((x) => x.id)
setVariantBusy(true)
try {
await api.reorderExerciseVariants(exerciseId, ids)
await refreshVariants()
} catch (e) {
alert(e.message || String(e))
} finally {
setVariantBusy(false)
}
}
const createVariantSubmit = async (e) => {
e.preventDefault()
if (!exerciseId) return
const payload = buildVariantPayloadFromRow(variantDraft)
if (payload.variant_name.length < 3) {
alert('Variantenname mindestens 3 Zeichen')
return
}
setVariantBusy(true)
try {
await api.createExerciseVariant(exerciseId, payload)
setVariantDraft(emptyVariantDraft())
await refreshVariants()
} catch (err) {
alert(err.message || String(err))
} finally {
setVariantBusy(false)
}
}
const availableSkills = skillsCatalog.filter((s) => !formData.skills.some((x) => x.skill_id === s.id))
if (loading) {
@@ -689,6 +853,307 @@ function ExerciseFormPage() {
</form>
</div>
{isEdit && (
<div className="card" style={{ marginTop: '16px' }}>
<h2 style={{ marginTop: 0, fontSize: '1.1rem' }}>Übungsvarianten</h2>
<p style={{ color: 'var(--text2)', fontSize: '13px', marginBottom: '12px' }}>
Alternative Ausführungen zur Stammübung. Reihenfolge (Nach oben/unten) steuert Darstellung und Auswahl in der
Trainingsplanung. „Voraussetzung“ verknüpft Varianten für spätere Progressions-Serien als Blöcke.
</p>
{variants.length === 0 && (
<p style={{ fontSize: '13px', color: 'var(--text3)', marginBottom: '12px' }}>Noch keine Varianten angelegt.</p>
)}
{variants.map((v, idx) => (
<div
key={v.id}
style={{
border: '1px solid var(--border)',
borderRadius: '10px',
padding: '12px',
marginBottom: '12px',
background: 'var(--surface2)',
}}
>
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '8px', alignItems: 'center', marginBottom: '10px' }}>
<span style={{ fontSize: '12px', color: 'var(--text3)' }}>#{idx + 1}</span>
<button
type="button"
className="btn btn-secondary"
style={{ fontSize: '11px', padding: '4px 8px' }}
disabled={variantBusy || idx === 0}
onClick={() => moveVariantRow(idx, -1)}
>
Nach oben
</button>
<button
type="button"
className="btn btn-secondary"
style={{ fontSize: '11px', padding: '4px 8px' }}
disabled={variantBusy || idx === variants.length - 1}
onClick={() => moveVariantRow(idx, 1)}
>
Nach unten
</button>
<button
type="button"
className="btn btn-primary"
style={{ fontSize: '12px', marginLeft: 'auto' }}
disabled={variantSavingId === v.id || variantBusy}
onClick={() => saveVariantRow(v)}
>
{variantSavingId === v.id ? 'Speichern…' : 'Speichern'}
</button>
<button
type="button"
className="btn"
style={{ fontSize: '12px', background: 'var(--danger)', color: '#fff', border: 'none' }}
disabled={variantBusy}
onClick={() => deleteVariantRow(v.id)}
>
Löschen
</button>
</div>
<div className="form-row">
<label className="form-label">Variantenname *</label>
<input
type="text"
className="form-input"
value={v.variant_name || ''}
onChange={(e) => updateVariantField(v.id, { variant_name: e.target.value })}
minLength={3}
/>
</div>
<div className="form-row">
<label className="form-label">Kurzbeschreibung</label>
<textarea
className="form-input"
rows={2}
value={v.description || ''}
onChange={(e) => updateVariantField(v.id, { description: e.target.value })}
/>
</div>
<div className="form-row">
<label className="form-label">Abweichungen zur Durchführung</label>
<RichTextEditor
value={v.execution_changes || ''}
onChange={(html) => updateVariantField(v.id, { execution_changes: html })}
placeholder="Was unterscheidet diese Variante?"
minHeight="100px"
/>
</div>
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '10px' }}>
<div className="form-row">
<label className="form-label">Dauer Min</label>
<input
type="number"
className="form-input"
value={v.duration_min}
onChange={(e) => updateVariantField(v.id, { duration_min: e.target.value })}
/>
</div>
<div className="form-row">
<label className="form-label">Dauer Max</label>
<input
type="number"
className="form-input"
value={v.duration_max}
onChange={(e) => updateVariantField(v.id, { duration_max: e.target.value })}
/>
</div>
</div>
<div className="form-row">
<label className="form-label">Materialänderungen (eine Zeile pro Eintrag)</label>
<textarea
className="form-input"
rows={2}
value={v.equipment_lines || ''}
onChange={(e) => updateVariantField(v.id, { equipment_lines: e.target.value })}
placeholder="+ Pratzen"
/>
</div>
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(160px, 1fr))', gap: '10px' }}>
<div className="form-row">
<label className="form-label">Schwere relativ</label>
<select
className="form-input"
value={v.difficulty_adjustment || ''}
onChange={(e) => updateVariantField(v.id, { difficulty_adjustment: e.target.value })}
>
{VARIANT_DIFFICULTY.map((o) => (
<option key={o.label} value={o.value}>
{o.label}
</option>
))}
</select>
</div>
<div className="form-row">
<label className="form-label">Progressions-Stufe (1–10)</label>
<input
type="number"
min={1}
max={10}
className="form-input"
value={v.progression_level}
onChange={(e) =>
updateVariantField(v.id, {
progression_level: e.target.value === '' ? '' : parseInt(e.target.value, 10),
})
}
/>
</div>
<div className="form-row">
<label className="form-label">Voraussetzungs-Variante</label>
<select
className="form-input"
value={
v.prerequisite_variant_id === '' || v.prerequisite_variant_id == null
? ''
: String(v.prerequisite_variant_id)
}
onChange={(e) =>
updateVariantField(v.id, {
prerequisite_variant_id: e.target.value === '' ? '' : parseInt(e.target.value, 10),
})
}
>
<option value="">— keine —</option>
{variants
.filter((o) => o.id !== v.id)
.map((o) => (
<option key={o.id} value={o.id}>
{o.variant_name || `Variante #${o.id}`}
</option>
))}
</select>
</div>
</div>
</div>
))}
<form
onSubmit={createVariantSubmit}
style={{ marginTop: '16px', paddingTop: '16px', borderTop: '1px solid var(--border)' }}
>
<h3 style={{ marginTop: 0, fontSize: '1rem' }}>Neue Variante anlegen</h3>
<div className="form-row">
<label className="form-label">Variantenname *</label>
<input
type="text"
className="form-input"
value={variantDraft.variant_name}
onChange={(e) => setVariantDraft((d) => ({ ...d, variant_name: e.target.value }))}
minLength={3}
/>
</div>
<div className="form-row">
<label className="form-label">Kurzbeschreibung</label>
<textarea
className="form-input"
rows={2}
value={variantDraft.description}
onChange={(e) => setVariantDraft((d) => ({ ...d, description: e.target.value }))}
/>
</div>
<div className="form-row">
<label className="form-label">Abweichungen zur Durchführung</label>
<RichTextEditor
value={variantDraft.execution_changes}
onChange={(html) => setVariantDraft((d) => ({ ...d, execution_changes: html }))}
placeholder="Optional: abweichende Schritte"
minHeight="100px"
/>
</div>
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '10px' }}>
<div className="form-row">
<label className="form-label">Dauer Min</label>
<input
type="number"
className="form-input"
value={variantDraft.duration_min}
onChange={(e) => setVariantDraft((d) => ({ ...d, duration_min: e.target.value }))}
/>
</div>
<div className="form-row">
<label className="form-label">Dauer Max</label>
<input
type="number"
className="form-input"
value={variantDraft.duration_max}
onChange={(e) => setVariantDraft((d) => ({ ...d, duration_max: e.target.value }))}
/>
</div>
</div>
<div className="form-row">
<label className="form-label">Materialänderungen</label>
<textarea
className="form-input"
rows={2}
value={variantDraft.equipment_lines}
onChange={(e) => setVariantDraft((d) => ({ ...d, equipment_lines: e.target.value }))}
/>
</div>
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(160px, 1fr))', gap: '10px' }}>
<div className="form-row">
<label className="form-label">Schwere relativ</label>
<select
className="form-input"
value={variantDraft.difficulty_adjustment}
onChange={(e) => setVariantDraft((d) => ({ ...d, difficulty_adjustment: e.target.value }))}
>
{VARIANT_DIFFICULTY.map((o) => (
<option key={o.label} value={o.value}>
{o.label}
</option>
))}
</select>
</div>
<div className="form-row">
<label className="form-label">Progressions-Stufe (1–10)</label>
<input
type="number"
min={1}
max={10}
className="form-input"
value={variantDraft.progression_level}
onChange={(e) =>
setVariantDraft((d) => ({
...d,
progression_level: e.target.value === '' ? 1 : parseInt(e.target.value, 10),
}))
}
/>
</div>
<div className="form-row">
<label className="form-label">Voraussetzungs-Variante</label>
<select
className="form-input"
value={
variantDraft.prerequisite_variant_id === '' || variantDraft.prerequisite_variant_id == null
? ''
: String(variantDraft.prerequisite_variant_id)
}
onChange={(e) =>
setVariantDraft((d) => ({
...d,
prerequisite_variant_id: e.target.value === '' ? '' : parseInt(e.target.value, 10),
}))
}
>
<option value="">— keine —</option>
{variants.map((o) => (
<option key={o.id} value={o.id}>
{o.variant_name || `Variante #${o.id}`}
</option>
))}
</select>
</div>
</div>
<button type="submit" className="btn btn-primary" disabled={variantBusy}>
{variantBusy ? 'Anlegen…' : 'Variante anlegen'}
</button>
</form>
</div>
)}
{isEdit && (
<div className="card" style={{ marginTop: '16px' }}>
<h2 style={{ marginTop: 0, fontSize: '1.1rem' }}>Medien</h2>
@@ -783,10 +1248,9 @@ function ExerciseFormPage() {
)}
<p style={{ fontSize: '12px', color: 'var(--text3)', marginTop: '16px' }}>
Varianten-Editor folgt später (API teilweise vorhanden).{' '}
<strong>KI-Ausbaustufe:</strong> Backend laut Spec{' '}
<code style={{ fontSize: '11px' }}>POST /api/exercises/ai/suggest</code> und{' '}
<code style={{ fontSize: '11px' }}>POST /api/exercises/{'{id}'}/ai/regenerate</code> — z. B.{' '}
<code style={{ fontSize: '11px' }}>POST /api/exercises/{'{id}'}/ai/regenerate</code> — z. B.{' '}
<code>OPENROUTER_API_KEY</code>, Vorschläge nur nach Trainer-Bestätigung übernehmen (siehe{' '}
<code>api.suggestExerciseAi</code>).
</p>