feat(exercises): introduce combination exercises and enhance exercise management
Deploy Development / deploy (push) Successful in 39s
Test Suite / pytest-backend (push) Successful in 36s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 12s
Test Suite / playwright-tests (push) Successful in 1m1s

- Updated app version to 0.8.99, reflecting the addition of combination exercises.
- Implemented new data structures and validation for combination slots and archetypes in the backend.
- Enhanced frontend components to support selection and display of combination exercises, including new UI elements for managing slots and archetypes.
- Updated API payload handling to accommodate new exercise types and their associated data.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 4.6 committed 2026-05-13 06:12:47 +02:00
1 parent f4f5642c21
commit 8a9f9f960f
8 files changed
+716 -12

No files matched your search

@@ -225,6 +225,7 @@ export default function ExercisePickerModal({
...queryBase,
include_archived: true,
include_variants: true,
exercise_kind_any: ['simple'],
limit: PAGE_SIZE,
offset: 0,
})
@@ -253,6 +254,7 @@ export default function ExercisePickerModal({
...queryBase,
include_archived: true,
include_variants: true,
exercise_kind_any: ['simple'],
limit: PAGE_SIZE,
offset,
})
+36
View File
@@ -136,6 +136,42 @@ function ExerciseDetailPage() {
{meta.length > 0 && <p className="exercise-meta-line">{meta.join(' · ')}</p>}
</div>
{(exercise.exercise_kind || '').toLowerCase().trim() === 'combination' &&
Array.isArray(exercise.combination_slots) &&
exercise.combination_slots.length > 0 && (
<section className="card exercise-detail-section">
<h2>Stationen und Übungspools</h2>
{exercise.method_archetype ? (
<p style={{ fontSize: '14px', color: 'var(--text2)', marginTop: 0 }}>
Archetyp: <code>{String(exercise.method_archetype)}</code>
</p>
) : null}
<ol style={{ paddingLeft: '1.25rem', marginBottom: 0 }}>
{exercise.combination_slots.map((s) => (
<li key={`${s.slot_index}-${(s.title || '').slice(0, 8)}`} style={{ marginBottom: '10px' }}>
<strong>
Station {s.slot_index != null ? s.slot_index : '?'}{s.title ? ` — ${s.title}` : ''}
</strong>
<ul style={{ margin: '4px 0 0', paddingLeft: '1.2rem' }}>
{(s.candidates && s.candidates.length
? s.candidates
: (s.candidate_exercise_ids || []).map((id) => ({
exercise_id: id,
title: null,
}))
).map((c) => (
<li key={c.exercise_id}>
<Link to={`/exercises/${c.exercise_id}`}>Übung #{c.exercise_id}</Link>
{c.title ? ` — ${c.title}` : ''}
</li>
))}
</ul>
</li>
))}
</ol>
</section>
)}
{exercise.goal && (
<section className="card exercise-detail-section">
<h2>Ziel</h2>
+215 -2
View File
@@ -30,6 +30,29 @@ const VARIANT_DIFFICULTY = [
{ value: 'adapted', label: 'Angepasst' },
]
/** An API `method_archetype` (Backend `COMBINATION_ARCHETYPE_IDS`) */
const COMBINATION_ARCHETYPE_OPTIONS = [
{ id: 'sequence_linear', label: 'Lineare Sequenz' },
{ id: 'circuit_rotate_time', label: 'Rotierender Zirkel (Zeit)' },
{ id: 'circuit_all_parallel', label: 'Parallele Stationen' },
{ id: 'station_parcour', label: 'Parcours' },
{ id: 'pair_superset', label: 'Partner- / Paarwechsel' },
{ id: 'time_domain_interval', label: 'Intervallblock (Zeitdomäne)' },
{ id: 'free_method_block', label: 'Freier Methodenblock' },
]
function comboSlotsFromDetail(exercise) {
const raw = exercise?.combination_slots
if (!Array.isArray(raw) || raw.length === 0) {
return [{ slot_index: 0, title: '', idsText: '' }]
}
return raw.map((s, i) => ({
slot_index: s.slot_index != null ? Number(s.slot_index) : i,
title: s.title != null ? String(s.title) : '',
idsText: Array.isArray(s.candidate_exercise_ids) ? s.candidate_exercise_ids.join(', ') : '',
}))
}
function emptyVariantDraft() {
return {
variant_name: '',
@@ -249,6 +272,10 @@ function emptyForm() {
visibility: 'private',
status: 'draft',
skills: [],
exercise_kind: 'simple',
method_archetype: '',
method_profile_json: '{}',
combination_slots: [{ slot_index: 0, title: '', idsText: '' }],
}
}
@@ -291,6 +318,18 @@ function detailToForm(exercise) {
required_level: normalizeSkillLevelSlug(s.required_level),
target_level: normalizeSkillLevelSlug(s.target_level),
})) || [],
exercise_kind:
String(exercise.exercise_kind || 'simple').toLowerCase() === 'combination'
? 'combination'
: 'simple',
method_archetype: exercise.method_archetype != null ? String(exercise.method_archetype) : '',
method_profile_json:
typeof exercise.method_profile === 'object' &&
exercise.method_profile != null &&
!Array.isArray(exercise.method_profile)
? JSON.stringify(exercise.method_profile, null, 2)
: '{}',
combination_slots: comboSlotsFromDetail(exercise),
}
}
@@ -949,6 +988,180 @@ function ExerciseFormPage() {
/>
</div>
<div
style={{
padding: '12px',
borderRadius: '8px',
border: '1px solid var(--border)',
background: 'var(--surface2)',
marginBottom: '12px',
}}
>
<h3 style={{ marginTop: 0, marginBottom: '10px', fontSize: '1rem' }}>Übungstyp</h3>
<div className="form-row">
<label className="form-label">Art</label>
<select
className="form-input"
value={formData.exercise_kind === 'combination' ? 'combination' : 'simple'}
onChange={(e) => {
const nk = e.target.value
setFormDirty(true)
setFormData((prev) => ({
...prev,
exercise_kind: nk,
...(nk === 'simple'
? {
method_archetype: '',
method_profile_json: '{}',
combination_slots: [{ slot_index: 0, title: '', idsText: '' }],
}
: {}),
}))
}}
>
<option value="simple">Einzelübung</option>
<option value="combination">Kombinationsübung (Stationen / Pool)</option>
</select>
</div>
{formData.exercise_kind === 'combination' ? (
<>
<div className="form-row">
<label className="form-label">Methoden-Archetyp (optional)</label>
<select
className="form-input"
value={formData.method_archetype || ''}
onChange={(e) => updateFormField('method_archetype', e.target.value)}
>
<option value="">— später wählen —</option>
{COMBINATION_ARCHETYPE_OPTIONS.map((o) => (
<option key={o.id} value={o.id}>
{o.label}
</option>
))}
</select>
</div>
<div className="form-row">
<label className="form-label">Ablaufprofil (JSON, optional)</label>
<textarea
className="form-input"
rows={4}
value={formData.method_profile_json || '{}'}
onChange={(e) => updateFormField('method_profile_json', e.target.value)}
spellCheck={false}
placeholder='{"work_seconds":45,"rest_seconds":15,"rounds":3}'
/>
</div>
<div>
<strong style={{ fontSize: '14px' }}>Stationen</strong>
<p style={{ fontSize: '12px', color: 'var(--text2)', margin: '6px 0 10px' }}>
Index (Reihenfolge), optional Stationstitel und kommaseparierte IDs von{' '}
<strong>Einzelübungen</strong> im Pool (nur Übungen mit Art „Einzelübung“).
</p>
{(formData.combination_slots || []).map((row, idx) => (
<div
key={`cs-${idx}`}
style={{
display: 'grid',
gridTemplateColumns: 'minmax(0, 72px) minmax(0, 1fr) minmax(0, 1.2fr) auto',
gap: '8px',
marginBottom: '8px',
alignItems: 'end',
}}
>
<div className="form-row">
<label className="form-label" style={{ fontSize: '12px' }}>
Idx.
</label>
<input
type="number"
min={0}
max={99}
className="form-input"
value={row.slot_index}
onChange={(e) => {
const next = [...(formData.combination_slots || [])]
const v = e.target.value
next[idx] = {
...row,
slot_index: v === '' ? '' : parseInt(v, 10),
}
updateFormField('combination_slots', next)
}}
/>
</div>
<div className="form-row">
<label className="form-label" style={{ fontSize: '12px' }}>
Titel
</label>
<input
type="text"
className="form-input"
value={row.title || ''}
onChange={(e) => {
const next = [...(formData.combination_slots || [])]
next[idx] = { ...row, title: e.target.value }
updateFormField('combination_slots', next)
}}
/>
</div>
<div className="form-row">
<label className="form-label" style={{ fontSize: '12px' }}>
Übungs-IDs
</label>
<input
type="text"
className="form-input"
value={row.idsText || ''}
onChange={(e) => {
const next = [...(formData.combination_slots || [])]
next[idx] = { ...row, idsText: e.target.value }
updateFormField('combination_slots', next)
}}
placeholder="z. B. 12, 34, 56"
/>
</div>
<button
type="button"
className="btn"
style={{ fontSize: '12px', padding: '6px 8px' }}
onClick={() => {
const prev = formData.combination_slots || []
const next = prev.filter((_, j) => j !== idx)
updateFormField(
'combination_slots',
next.length ? next : [{ slot_index: 0, title: '', idsText: '' }],
)
}}
>
Entf.
</button>
</div>
))}
<button
type="button"
className="btn btn-secondary"
style={{ fontSize: '12px', marginTop: '4px' }}
onClick={() => {
const cur = formData.combination_slots || []
const ixList = cur
.map((r) =>
typeof r.slot_index === 'number' && !Number.isNaN(r.slot_index) ? r.slot_index : null,
)
.filter((n) => n != null)
const nextIx = ixList.length ? Math.max(...ixList) + 1 : 0
updateFormField('combination_slots', [
...cur,
{ slot_index: nextIx, title: '', idsText: '' },
])
}}
>
+ Station
</button>
</div>
</>
) : null}
</div>
<div className="form-row">
<label className="form-label">Ziel *</label>
<RichTextEditor
@@ -1219,7 +1432,7 @@ function ExerciseFormPage() {
</form>
</div>
{isEdit && (
{isEdit && formData.exercise_kind !== 'combination' && (
<details ref={variantsDetailsRef} className="card exercise-variants-details" style={{ marginTop: '16px' }}>
<summary className="exercise-variants-summary">
<span className="exercise-variants-summary__title">Übungsvarianten</span>
@@ -1380,7 +1593,7 @@ function ExerciseFormPage() {
</details>
)}
{isEdit && (
{isEdit && formData.exercise_kind !== 'combination' && (
<details className="card exercise-variants-details" style={{ marginTop: '16px' }}>
<summary className="exercise-variants-summary">
<span className="exercise-variants-summary__title">Progressionsgraph</span>
+5
View File
@@ -1408,6 +1408,11 @@ function ExercisesListPage() {
{typeNames.map((name) => (
<span key={`tt:${name}`} className="exercise-tag exercise-tag--training">{name}</span>
))}
{(exercise.exercise_kind || '').toLowerCase().trim() === 'combination' ? (
<span className="exercise-tag" style={{ background: 'var(--accent-soft)', color: 'var(--accent-dark)' }}>
Kombination
</span>
) : null}
</div>
{exercise.summary && String(exercise.summary).trim() ? (
<div className="exercise-card-summary exercise-card-summary--rich">
+58 -1
View File
@@ -451,7 +451,7 @@ export function buildExerciseApiPayload(formData, extras = {}) {
.filter((x) => x && x.target_group_id)
.map((x) => ({ target_group_id: Number(x.target_group_id), is_primary: !!x.is_primary }))
return {
const payload = {
title: (formData.title || '').trim(),
summary: formData.summary || null,
goal: goalHtml.trim() ? goalHtml : null,
@@ -478,8 +478,65 @@ export function buildExerciseApiPayload(formData, extras = {}) {
visibility: formData.visibility || 'private',
status: formData.status || 'draft',
club_id: formData.club_id ?? null,
exercise_kind:
String(formData.exercise_kind || 'simple').toLowerCase() === 'combination'
? 'combination'
: 'simple',
...extras,
}
const isCombo = payload.exercise_kind === 'combination'
if (isCombo) {
let mpObj = {}
const mpRaw = typeof formData.method_profile_json === 'string' ? formData.method_profile_json.trim() : ''
if (mpRaw) {
try {
const parsed = JSON.parse(mpRaw)
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
throw new Error('Ablaufprofil muss ein JSON-Objekt sein.')
}
mpObj = parsed
} catch (e) {
if (e instanceof SyntaxError) {
throw new Error('Ablaufprofil (JSON): Syntax ungültig.')
}
throw e
}
}
const slotRows = Array.isArray(formData.combination_slots) ? formData.combination_slots : []
const combination_slots = []
for (let i = 0; i < slotRows.length; i += 1) {
const row = slotRows[i] || {}
const ix =
row.slot_index === '' || row.slot_index == null ? i : parseInt(row.slot_index, 10)
if (Number.isNaN(ix) || ix < 0 || ix > 99) {
throw new Error(`Station Index ungültig (Zeile ${i + 1}).`)
}
const idsText = typeof row.idsText === 'string' ? row.idsText : ''
const candidate_exercise_ids = idsText
.split(/[\s,;]+/)
.map((s) => s.trim())
.filter(Boolean)
.map((s) => parseInt(s, 10))
.filter((n) => Number.isFinite(n))
combination_slots.push({
slot_index: ix,
title: (typeof row.title === 'string' && row.title.trim()) || null,
candidate_exercise_ids,
})
}
payload.method_archetype = (formData.method_archetype || '').trim() || null
payload.method_profile = mpObj
payload.combination_slots = combination_slots
} else {
payload.method_archetype = null
payload.method_profile = {}
}
return payload
}
export async function uploadExerciseMedia(exerciseId, formData) {