feat(training-modules): implement training module functionality and UI integration
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 56s
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 56s
- Added new API endpoints for managing training modules, including listing, creating, updating, and deleting modules. - Implemented the ability to apply training modules to training units, allowing users to copy module content into specific sections. - Enhanced the frontend with new pages for managing training modules and integrated modal functionality for applying modules within the training planning page. - Updated version to 0.8.97 and adjusted database schema version accordingly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
59d53d6154
commit
c1243651bb
13 files changed
+2114
-10
No files matched your search
@@ -26,6 +26,8 @@ import SkillsPage from './pages/SkillsPage'
|
||||
import TrainingPlanningPage from './pages/TrainingPlanningPage'
|
||||
import TrainingFrameworkProgramsListPage from './pages/TrainingFrameworkProgramsListPage'
|
||||
import TrainingFrameworkProgramEditPage from './pages/TrainingFrameworkProgramEditPage'
|
||||
import TrainingModulesListPage from './pages/TrainingModulesListPage'
|
||||
import TrainingModuleEditPage from './pages/TrainingModuleEditPage'
|
||||
import TrainingUnitRunPage from './pages/TrainingUnitRunPage'
|
||||
import TrainingCoachPage from './pages/TrainingCoachPage'
|
||||
import AdminCatalogsPage from './pages/AdminCatalogsPage'
|
||||
@@ -199,6 +201,9 @@ function AppRoutes() {
|
||||
<Route path="planning/framework-programs/new" element={<TrainingFrameworkProgramEditPage />} />
|
||||
<Route path="planning/framework-programs/:id" element={<TrainingFrameworkProgramEditPage />} />
|
||||
<Route path="planning/framework-programs" element={<TrainingFrameworkProgramsListPage />} />
|
||||
<Route path="planning/training-modules/new" element={<TrainingModuleEditPage />} />
|
||||
<Route path="planning/training-modules/:id" element={<TrainingModuleEditPage />} />
|
||||
<Route path="planning/training-modules" element={<TrainingModulesListPage />} />
|
||||
<Route path="planning/run/:unitId/coach" element={<TrainingCoachPage />} />
|
||||
<Route path="planning/run/:unitId" element={<TrainingUnitRunPage />} />
|
||||
<Route path="planning" element={<TrainingPlanningPage />} />
|
||||
|
||||
@@ -0,0 +1,443 @@
|
||||
import React, { useCallback, useEffect, useState } from 'react'
|
||||
import { Link, useNavigate, useParams } from 'react-router-dom'
|
||||
import api from '../utils/api'
|
||||
import ExercisePickerModal from '../components/ExercisePickerModal'
|
||||
import { hydrateExercisePlanningRow } from '../utils/trainingUnitSectionsForm'
|
||||
|
||||
function nextLocalKey() {
|
||||
return `m-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`
|
||||
}
|
||||
|
||||
function swapItems(arr, i, j) {
|
||||
if (i === j || i < 0 || j < 0 || i >= arr.length || j >= arr.length) return [...arr]
|
||||
const n = [...arr]
|
||||
;[n[i], n[j]] = [n[j], n[i]]
|
||||
return n
|
||||
}
|
||||
|
||||
export default function TrainingModuleEditPage() {
|
||||
const { id: routeId } = useParams()
|
||||
const navigate = useNavigate()
|
||||
const isNew = !routeId || routeId === 'new'
|
||||
const moduleId = !isNew ? parseInt(routeId, 10) : NaN
|
||||
|
||||
const [loading, setLoading] = useState(!isNew)
|
||||
const [saving, setSaving] = useState(false)
|
||||
const [methods, setMethods] = useState([])
|
||||
const [pickerOpen, setPickerOpen] = useState(false)
|
||||
const [error, setError] = useState('')
|
||||
|
||||
const [title, setTitle] = useState('')
|
||||
const [summary, setSummary] = useState('')
|
||||
const [goal, setGoal] = useState('')
|
||||
const [recommendedDurationMin, setRecommendedDurationMin] = useState('')
|
||||
const [targetGroupNotes, setTargetGroupNotes] = useState('')
|
||||
const [deploymentContextNotes, setDeploymentContextNotes] = useState('')
|
||||
const [visibility, setVisibility] = useState('club')
|
||||
const [clubIdField, setClubIdField] = useState('')
|
||||
const [primaryMethodId, setPrimaryMethodId] = useState('')
|
||||
const [items, setItems] = useState([])
|
||||
|
||||
const itemsPayload = items.map((it, i) => {
|
||||
if (it.item_type === 'note') {
|
||||
return { item_type: 'note', order_index: i, note_body: it.note_body ?? '' }
|
||||
}
|
||||
const vid =
|
||||
it.exercise_variant_id !== '' && it.exercise_variant_id != null
|
||||
? parseInt(it.exercise_variant_id, 10)
|
||||
: null
|
||||
return {
|
||||
item_type: 'exercise',
|
||||
order_index: i,
|
||||
exercise_id: parseInt(it.exercise_id, 10),
|
||||
exercise_variant_id: Number.isFinite(vid) ? vid : null,
|
||||
planned_duration_min:
|
||||
it.planned_duration_min !== '' && it.planned_duration_min != null
|
||||
? parseInt(String(it.planned_duration_min), 10)
|
||||
: null,
|
||||
notes: it.notes?.trim() ? it.notes.trim() : null,
|
||||
}
|
||||
})
|
||||
|
||||
const loadCatalogs = useCallback(async () => {
|
||||
try {
|
||||
const m = await api.listMethods({})
|
||||
setMethods(Array.isArray(m) ? m : [])
|
||||
} catch {
|
||||
setMethods([])
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
loadCatalogs()
|
||||
}, [loadCatalogs])
|
||||
|
||||
useEffect(() => {
|
||||
if (isNew || !Number.isFinite(moduleId)) {
|
||||
setLoading(false)
|
||||
return
|
||||
}
|
||||
let cancelled = false
|
||||
async function load() {
|
||||
setLoading(true)
|
||||
setError('')
|
||||
try {
|
||||
const m = await api.getTrainingModule(moduleId)
|
||||
if (cancelled) return
|
||||
setTitle((m.title || '').trim())
|
||||
setSummary((m.summary || '').trim())
|
||||
setGoal(m.goal || '')
|
||||
setRecommendedDurationMin(
|
||||
m.recommended_duration_min != null && m.recommended_duration_min !== ''
|
||||
? String(m.recommended_duration_min)
|
||||
: ''
|
||||
)
|
||||
setTargetGroupNotes(m.target_group_notes || '')
|
||||
setDeploymentContextNotes(m.deployment_context_notes || '')
|
||||
setVisibility((m.visibility || 'club').trim())
|
||||
setClubIdField(m.club_id != null ? String(m.club_id) : '')
|
||||
setPrimaryMethodId(m.primary_method_id != null ? String(m.primary_method_id) : '')
|
||||
const nextItems = []
|
||||
for (const row of Array.isArray(m.items) ? m.items : []) {
|
||||
if (row.item_type === 'note') {
|
||||
nextItems.push({ localKey: nextLocalKey(), item_type: 'note', note_body: row.note_body || '' })
|
||||
continue
|
||||
}
|
||||
const ex = await hydrateExercisePlanningRow({
|
||||
id: row.exercise_id,
|
||||
title: '',
|
||||
variants: [],
|
||||
})
|
||||
if (ex) {
|
||||
ex.localKey = nextLocalKey()
|
||||
if (row.exercise_variant_id) ex.exercise_variant_id = String(row.exercise_variant_id)
|
||||
ex.planned_duration_min =
|
||||
row.planned_duration_min != null && row.planned_duration_min !== ''
|
||||
? String(row.planned_duration_min)
|
||||
: ''
|
||||
ex.notes = row.notes || ''
|
||||
nextItems.push(ex)
|
||||
}
|
||||
}
|
||||
setItems(nextItems)
|
||||
} catch (e) {
|
||||
if (!cancelled) setError(e.message || 'Laden fehlgeschlagen')
|
||||
} finally {
|
||||
if (!cancelled) setLoading(false)
|
||||
}
|
||||
}
|
||||
load()
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [isNew, moduleId])
|
||||
|
||||
const buildBody = () => {
|
||||
const cid =
|
||||
visibility === 'club' && clubIdField !== '' ? parseInt(clubIdField, 10) : null
|
||||
const pm =
|
||||
primaryMethodId !== '' && primaryMethodId != null ? parseInt(primaryMethodId, 10) : null
|
||||
return {
|
||||
title: title.trim(),
|
||||
summary: summary.trim() || null,
|
||||
goal: goal.trim() || null,
|
||||
recommended_duration_min:
|
||||
recommendedDurationMin !== '' ? parseInt(recommendedDurationMin, 10) : null,
|
||||
target_group_notes: targetGroupNotes.trim() || null,
|
||||
deployment_context_notes: deploymentContextNotes.trim() || null,
|
||||
visibility,
|
||||
club_id:
|
||||
cid != null && Number.isFinite(cid) && cid >= 1
|
||||
? cid
|
||||
: visibility === 'club'
|
||||
? undefined
|
||||
: null,
|
||||
primary_method_id:
|
||||
pm != null && Number.isFinite(pm) && pm >= 1 ? pm : null,
|
||||
items: itemsPayload.filter((row) =>
|
||||
row.item_type === 'note' ? true : Number.isFinite(row.exercise_id) && row.exercise_id >= 1
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
const handleSave = async (e) => {
|
||||
e.preventDefault()
|
||||
if (!title.trim()) {
|
||||
alert('Titel ist Pflicht.')
|
||||
return
|
||||
}
|
||||
setSaving(true)
|
||||
setError('')
|
||||
try {
|
||||
const body = buildBody()
|
||||
if (isNew) {
|
||||
const created = await api.createTrainingModule(body)
|
||||
navigate(`/planning/training-modules/${created.id}`, { replace: true })
|
||||
} else {
|
||||
await api.updateTrainingModule(moduleId, body)
|
||||
alert('Trainingsmodul gespeichert.')
|
||||
}
|
||||
} catch (err) {
|
||||
setError(err.message || 'Speichern fehlgeschlagen')
|
||||
} finally {
|
||||
setSaving(false)
|
||||
}
|
||||
}
|
||||
|
||||
const pickExercise = async (ex) => {
|
||||
if (!ex?.id) return
|
||||
const row = await hydrateExercisePlanningRow(ex)
|
||||
if (row) row.localKey = nextLocalKey()
|
||||
if (row) setItems((prev) => [...prev, row])
|
||||
setPickerOpen(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="app-page">
|
||||
<p style={{ marginBottom: '0.75rem' }}>
|
||||
<Link to="/planning/training-modules" style={{ color: 'var(--accent-dark)', fontWeight: 600 }}>
|
||||
← Zurück zur Modul‑Bibliothek
|
||||
</Link>
|
||||
</p>
|
||||
<h1 className="page-title">{isNew ? 'Neues Trainingsmodul' : 'Trainingsmodul bearbeiten'}</h1>
|
||||
<p style={{ color: 'var(--text2)', fontSize: '0.95rem', marginBottom: '1.25rem', maxWidth: '40rem' }}>
|
||||
Reihenfolge der Positionen entspricht der späteren Übernahme in einen Abschnitt der Einheit (Kopie).
|
||||
</p>
|
||||
|
||||
{error ? <p style={{ color: 'var(--danger)', marginBottom: '1rem' }}>{error}</p> : null}
|
||||
{loading ? (
|
||||
<p style={{ color: 'var(--text2)' }}>Laden …</p>
|
||||
) : (
|
||||
<form className="card" style={{ padding: 'clamp(14px, 3vw, 1.75rem)', maxWidth: '720px' }} onSubmit={handleSave}>
|
||||
<div className="form-row">
|
||||
<label className="form-label">Titel *</label>
|
||||
<input className="form-input" value={title} onChange={(e) => setTitle(e.target.value)} />
|
||||
</div>
|
||||
<div className="form-row">
|
||||
<label className="form-label">Kurzbeschreibung</label>
|
||||
<textarea className="form-input" rows={2} value={summary} onChange={(e) => setSummary(e.target.value)} />
|
||||
</div>
|
||||
<div className="form-row">
|
||||
<label className="form-label">Ziel</label>
|
||||
<textarea className="form-input" rows={3} value={goal} onChange={(e) => setGoal(e.target.value)} />
|
||||
</div>
|
||||
<div className="form-row" style={{ display: 'grid', gap: '1rem', gridTemplateColumns: '1fr 1fr' }}>
|
||||
<div>
|
||||
<label className="form-label">Empfohlene Dauer (Min.)</label>
|
||||
<input
|
||||
className="form-input"
|
||||
type="number"
|
||||
min={0}
|
||||
value={recommendedDurationMin}
|
||||
onChange={(e) => setRecommendedDurationMin(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="form-label">Primäre Trainingsmethode</label>
|
||||
<select
|
||||
className="form-input"
|
||||
value={primaryMethodId}
|
||||
onChange={(e) => setPrimaryMethodId(e.target.value)}
|
||||
>
|
||||
<option value="">—</option>
|
||||
{methods.map((m) => (
|
||||
<option key={m.id} value={String(m.id)}>
|
||||
{(m.name || '').trim() || `Methode #${m.id}`}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div className="form-row">
|
||||
<label className="form-label">Empfohlene Zielgruppe (Freitext)</label>
|
||||
<textarea
|
||||
className="form-input"
|
||||
rows={2}
|
||||
value={targetGroupNotes}
|
||||
onChange={(e) => setTargetGroupNotes(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="form-row">
|
||||
<label className="form-label">Einsatz / Kontext</label>
|
||||
<textarea
|
||||
className="form-input"
|
||||
rows={2}
|
||||
value={deploymentContextNotes}
|
||||
onChange={(e) => setDeploymentContextNotes(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="form-row" style={{ display: 'grid', gap: '1rem', gridTemplateColumns: '1fr 1fr' }}>
|
||||
<div>
|
||||
<label className="form-label">Sichtbarkeit</label>
|
||||
<select className="form-input" value={visibility} onChange={(e) => setVisibility(e.target.value)}>
|
||||
<option value="private">Privat</option>
|
||||
<option value="club">Vereinsintern</option>
|
||||
<option value="official">Offiziell</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="form-label">Vereins‑ID (optional, bei Vereins‑Sichtbarkeit)</label>
|
||||
<input
|
||||
className="form-input"
|
||||
type="number"
|
||||
min={1}
|
||||
value={clubIdField}
|
||||
onChange={(e) => setClubIdField(e.target.value)}
|
||||
placeholder="Leer = aktiver Verein (Server)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr style={{ border: 'none', borderTop: '1px solid var(--border)', margin: '1.25rem 0' }} />
|
||||
|
||||
<h3 style={{ fontSize: '1rem', marginBottom: '0.75rem' }}>Positionen</h3>
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '8px', marginBottom: '12px' }}>
|
||||
<button type="button" className="btn btn-secondary" onClick={() => setPickerOpen(true)}>
|
||||
Übung hinzufügen
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary"
|
||||
onClick={() =>
|
||||
setItems((prev) => [...prev, { localKey: nextLocalKey(), item_type: 'note', note_body: '' }])
|
||||
}
|
||||
>
|
||||
Notiz hinzufügen
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<ul style={{ listStyle: 'none', padding: 0, margin: 0, display: 'flex', flexDirection: 'column', gap: '10px' }}>
|
||||
{items.map((it, idx) => (
|
||||
<li key={it.localKey || idx} style={{ padding: '10px', background: 'var(--surface2)', borderRadius: '8px' }}>
|
||||
{it.item_type === 'note' ? (
|
||||
<div>
|
||||
<span style={{ fontWeight: 600, fontSize: '0.85rem', color: 'var(--text3)' }}>Notiz</span>
|
||||
<textarea
|
||||
className="form-input"
|
||||
style={{ marginTop: '8px' }}
|
||||
rows={2}
|
||||
value={it.note_body}
|
||||
onChange={(e) => {
|
||||
const v = e.target.value
|
||||
setItems((prev) =>
|
||||
prev.map((x, j) =>
|
||||
j === idx && x.item_type === 'note' ? { ...x, note_body: v } : x
|
||||
)
|
||||
)
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div style={{ fontWeight: 700, wordBreak: 'break-word', marginBottom: '8px' }}>
|
||||
{(it.exercise_title || '').trim() || `Übung #${it.exercise_id}`}
|
||||
</div>
|
||||
<div style={{ display: 'grid', gap: '8px', gridTemplateColumns: '1fr 1fr' }}>
|
||||
<div>
|
||||
<label className="form-label" style={{ fontSize: '0.78rem' }}>
|
||||
Variante
|
||||
</label>
|
||||
<select
|
||||
className="form-input"
|
||||
value={String(it.exercise_variant_id ?? '')}
|
||||
onChange={(e) => {
|
||||
const v = e.target.value
|
||||
setItems((prev) =>
|
||||
prev.map((row, j) =>
|
||||
j === idx && row.item_type === 'exercise' ? { ...row, exercise_variant_id: v } : row
|
||||
)
|
||||
)
|
||||
}}
|
||||
>
|
||||
<option value="">—</option>
|
||||
{(it.variants || []).map((v) => (
|
||||
<option key={v.id} value={String(v.id)}>
|
||||
{(v.name || '').trim() || `Variante #${v.id}`}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="form-label" style={{ fontSize: '0.78rem' }}>
|
||||
Minuten (plan)
|
||||
</label>
|
||||
<input
|
||||
className="form-input"
|
||||
type="number"
|
||||
min={0}
|
||||
value={it.planned_duration_min}
|
||||
onChange={(e) =>
|
||||
setItems((prev) =>
|
||||
prev.map((row, j) =>
|
||||
j === idx && row.item_type === 'exercise'
|
||||
? { ...row, planned_duration_min: e.target.value }
|
||||
: row
|
||||
)
|
||||
)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ marginTop: '8px' }}>
|
||||
<label className="form-label" style={{ fontSize: '0.78rem' }}>
|
||||
Hinweis zur Position
|
||||
</label>
|
||||
<input
|
||||
className="form-input"
|
||||
value={it.notes ?? ''}
|
||||
onChange={(e) =>
|
||||
setItems((prev) =>
|
||||
prev.map((row, j) =>
|
||||
j === idx && row.item_type === 'exercise' ? { ...row, notes: e.target.value } : row
|
||||
)
|
||||
)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
<div style={{ display: 'flex', gap: '8px', marginTop: '10px', flexWrap: 'wrap' }}>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary"
|
||||
disabled={idx < 1}
|
||||
onClick={() => setItems((prev) => swapItems(prev, idx, idx - 1))}
|
||||
>
|
||||
Nach oben
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary"
|
||||
disabled={idx >= items.length - 1}
|
||||
onClick={() => setItems((prev) => swapItems(prev, idx, idx + 1))}
|
||||
>
|
||||
Nach unten
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary"
|
||||
onClick={() => setItems((prev) => prev.filter((_, j) => j !== idx))}
|
||||
>
|
||||
Entfernen
|
||||
</button>
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
<div style={{ display: 'flex', gap: '10px', marginTop: '1.5rem', flexWrap: 'wrap' }}>
|
||||
<button type="submit" className="btn btn-primary" disabled={saving}>
|
||||
{saving ? 'Speichern …' : isNew ? 'Anlegen' : 'Speichern'}
|
||||
</button>
|
||||
<Link to="/planning/training-modules" className="btn btn-secondary" style={{ textDecoration: 'none' }}>
|
||||
Abbrechen
|
||||
</Link>
|
||||
</div>
|
||||
</form>
|
||||
)}
|
||||
|
||||
<ExercisePickerModal open={pickerOpen} onClose={() => setPickerOpen(false)} onSelectExercise={pickExercise} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
import React, { useCallback, useEffect, useState } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import api from '../utils/api'
|
||||
|
||||
export default function TrainingModulesListPage() {
|
||||
const [rows, setRows] = useState([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [error, setError] = useState('')
|
||||
|
||||
const load = useCallback(async () => {
|
||||
setLoading(true)
|
||||
setError('')
|
||||
try {
|
||||
const list = await api.listTrainingModules()
|
||||
setRows(Array.isArray(list) ? list : [])
|
||||
} catch (e) {
|
||||
setError(e.message || 'Laden fehlgeschlagen')
|
||||
setRows([])
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
load()
|
||||
}, [load])
|
||||
|
||||
async function handleDelete(id, title) {
|
||||
if (!confirm(`Trainingsmodul „${title || id}“ wirklich löschen?`)) return
|
||||
try {
|
||||
await api.deleteTrainingModule(id)
|
||||
await load()
|
||||
} catch (e) {
|
||||
alert(e.message || 'Löschen fehlgeschlagen')
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="app-page">
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexWrap: 'wrap',
|
||||
alignItems: 'flex-start',
|
||||
justifyContent: 'space-between',
|
||||
gap: '1rem',
|
||||
marginBottom: '1.25rem',
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<h1 className="page-title" style={{ marginBottom: '0.35rem' }}>
|
||||
Trainingsmodule
|
||||
</h1>
|
||||
<p style={{ color: 'var(--text2)', fontSize: '0.95rem', maxWidth: '38rem', margin: 0 }}>
|
||||
Wiederverwendbare Übungsfolgen für die{' '}
|
||||
<Link to="/planning" style={{ fontWeight: 600, color: 'var(--accent-dark)' }}>
|
||||
Trainingsplanung
|
||||
</Link>
|
||||
. Übernahme in eine Einheit erfolgt dort als lokale Kopie (mit Herkunftsmarkierung).
|
||||
</p>
|
||||
</div>
|
||||
<Link to="/planning/training-modules/new" className="btn btn-primary" style={{ textDecoration: 'none' }}>
|
||||
Neues Modul
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
{error ? (
|
||||
<p style={{ color: 'var(--danger)', marginBottom: '1rem' }}>{error}</p>
|
||||
) : null}
|
||||
{loading ? (
|
||||
<p style={{ color: 'var(--text2)' }}>Laden …</p>
|
||||
) : rows.length === 0 ? (
|
||||
<div className="card" style={{ padding: '1.25rem' }}>
|
||||
<p style={{ margin: 0, color: 'var(--text2)' }}>Noch keine Module angelegt.</p>
|
||||
</div>
|
||||
) : (
|
||||
<ul style={{ listStyle: 'none', padding: 0, margin: 0, display: 'flex', flexDirection: 'column', gap: '10px' }}>
|
||||
{rows.map((r) => (
|
||||
<li key={r.id} className="card" style={{ padding: '1rem 1.15rem' }}>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexWrap: 'wrap',
|
||||
justifyContent: 'space-between',
|
||||
gap: '10px',
|
||||
alignItems: 'flex-start',
|
||||
}}
|
||||
>
|
||||
<div style={{ flex: '1 1 220px', minWidth: 0 }}>
|
||||
<Link
|
||||
to={`/planning/training-modules/${r.id}`}
|
||||
style={{
|
||||
fontWeight: 700,
|
||||
fontSize: '1.05rem',
|
||||
color: 'var(--accent-dark)',
|
||||
textDecoration: 'none',
|
||||
wordBreak: 'break-word',
|
||||
}}
|
||||
>
|
||||
{(r.title || '').trim() || `Modul #${r.id}`}
|
||||
</Link>
|
||||
<p style={{ margin: '0.35rem 0 0', fontSize: '0.88rem', color: 'var(--text2)', lineHeight: 1.45 }}>
|
||||
{(r.summary || '').trim() || '—'}{' '}
|
||||
<span style={{ color: 'var(--text3)' }}>
|
||||
({Number(r.items_count) || 0} Position{r.items_count === 1 ? '' : 'en'})
|
||||
</span>
|
||||
</p>
|
||||
<p style={{ margin: '0.35rem 0 0', fontSize: '0.8rem', color: 'var(--text3)' }}>
|
||||
Sichtbarkeit: <strong>{r.visibility || '—'}</strong>
|
||||
</p>
|
||||
</div>
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '8px' }}>
|
||||
<Link
|
||||
className="btn btn-secondary"
|
||||
style={{ textDecoration: 'none' }}
|
||||
to={`/planning/training-modules/${r.id}`}
|
||||
>
|
||||
Bearbeiten
|
||||
</Link>
|
||||
<button type="button" className="btn btn-secondary" onClick={() => handleDelete(r.id, r.title)}>
|
||||
Löschen
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -144,6 +144,13 @@ function TrainingPlanningPage() {
|
||||
const [fwImportIntervalDays, setFwImportIntervalDays] = useState(7)
|
||||
const [fwImportSubmitting, setFwImportSubmitting] = useState(false)
|
||||
|
||||
const [moduleApplyOpen, setModuleApplyOpen] = useState(false)
|
||||
const [moduleApplyBusy, setModuleApplyBusy] = useState(false)
|
||||
const [moduleApplyList, setModuleApplyList] = useState([])
|
||||
const [moduleApplyModuleId, setModuleApplyModuleId] = useState('')
|
||||
const [moduleApplySectionIx, setModuleApplySectionIx] = useState(0)
|
||||
const [moduleApplyErr, setModuleApplyErr] = useState('')
|
||||
|
||||
const [startDate, setStartDate] = useState(today)
|
||||
const [endDate, setEndDate] = useState(thirtyDaysLater)
|
||||
const [planView, setPlanView] = useState('list')
|
||||
@@ -662,6 +669,58 @@ function TrainingPlanningPage() {
|
||||
}
|
||||
}
|
||||
|
||||
const openModuleApplyModal = useCallback(async () => {
|
||||
setModuleApplyErr('')
|
||||
setModuleApplySectionIx(0)
|
||||
setModuleApplyOpen(true)
|
||||
try {
|
||||
const list = await api.listTrainingModules()
|
||||
const arr = Array.isArray(list) ? list : []
|
||||
setModuleApplyList(arr)
|
||||
setModuleApplyModuleId(arr.length ? String(arr[0].id) : '')
|
||||
} catch (e) {
|
||||
setModuleApplyErr(e.message || 'Module konnten nicht geladen werden')
|
||||
setModuleApplyList([])
|
||||
}
|
||||
}, [])
|
||||
|
||||
const handleApplyTrainingModuleConfirm = useCallback(async () => {
|
||||
if (!editingUnit?.id) return
|
||||
const mid = parseInt(moduleApplyModuleId, 10)
|
||||
if (!Number.isFinite(mid)) {
|
||||
alert('Bitte ein Trainingsmodul wählen.')
|
||||
return
|
||||
}
|
||||
let secIx = parseInt(moduleApplySectionIx, 10)
|
||||
if (!Number.isFinite(secIx)) secIx = 0
|
||||
if (!formData.sections?.length) {
|
||||
alert('Keine Abschnitte im Formular.')
|
||||
return
|
||||
}
|
||||
if (secIx < 0 || secIx >= formData.sections.length) secIx = 0
|
||||
|
||||
setModuleApplyBusy(true)
|
||||
setModuleApplyErr('')
|
||||
try {
|
||||
await api.applyTrainingModuleToTrainingUnit(editingUnit.id, {
|
||||
module_id: mid,
|
||||
section_order_index: secIx,
|
||||
})
|
||||
await handleEdit({ id: editingUnit.id })
|
||||
setModuleApplyOpen(false)
|
||||
} catch (e) {
|
||||
setModuleApplyErr(e.message || 'Übernehmen fehlgeschlagen')
|
||||
} finally {
|
||||
setModuleApplyBusy(false)
|
||||
}
|
||||
}, [
|
||||
editingUnit?.id,
|
||||
moduleApplyModuleId,
|
||||
moduleApplySectionIx,
|
||||
formData.sections?.length,
|
||||
handleEdit,
|
||||
])
|
||||
|
||||
const handleTakeLead = async (unit) => {
|
||||
if (!user?.id) return
|
||||
try {
|
||||
@@ -972,12 +1031,19 @@ function TrainingPlanningPage() {
|
||||
</p>
|
||||
|
||||
<div className="card" style={{ marginBottom: '1.25rem', padding: '12px 14px' }}>
|
||||
<p style={{ margin: 0, fontSize: '0.92rem', color: 'var(--text2)' }}>
|
||||
<p style={{ margin: '0 0 0.5rem', fontSize: '0.92rem', color: 'var(--text2)' }}>
|
||||
Mehrere Einheiten strukturieren auf einmal:{' '}
|
||||
<Link to="/planning/framework-programs" style={{ fontWeight: 600, color: 'var(--accent-dark)' }}>
|
||||
Trainingsrahmenprogramme
|
||||
</Link>{' '}
|
||||
(Ziele, Slots, Übungen als Vorlage).
|
||||
(Ziele, Sessions, Vorlagen‑Ablauf).
|
||||
</p>
|
||||
<p style={{ margin: 0, fontSize: '0.92rem', color: 'var(--text2)' }}>
|
||||
Wiederverwendbare Blöcke innerhalb einer Einheit:{' '}
|
||||
<Link to="/planning/training-modules" style={{ fontWeight: 600, color: 'var(--accent-dark)' }}>
|
||||
Trainingsmodule
|
||||
</Link>{' '}
|
||||
(übernahme als Kopie beim Bearbeiten einer Einheit).
|
||||
</p>
|
||||
</div>
|
||||
{!loading && groups.length === 0 && (
|
||||
@@ -1796,6 +1862,118 @@ function TrainingPlanningPage() {
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{moduleApplyOpen && (
|
||||
<div
|
||||
style={{
|
||||
position: 'fixed',
|
||||
top: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
background: 'rgba(0,0,0,0.5)',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
zIndex: 1010,
|
||||
padding: '1rem',
|
||||
overflowY: 'auto',
|
||||
}}
|
||||
role="presentation"
|
||||
onMouseDown={(ev) => ev.target === ev.currentTarget && !moduleApplyBusy && setModuleApplyOpen(false)}
|
||||
>
|
||||
<div
|
||||
className="card"
|
||||
style={{
|
||||
padding: 'clamp(14px, 3vw, 1.75rem)',
|
||||
maxWidth: 'min(480px, 100%)',
|
||||
width: '100%',
|
||||
maxHeight: '90vh',
|
||||
overflowY: 'auto',
|
||||
boxSizing: 'border-box',
|
||||
}}
|
||||
role="dialog"
|
||||
aria-labelledby="module-apply-title"
|
||||
>
|
||||
<h2 id="module-apply-title" style={{ marginBottom: '0.5rem', fontSize: '1.15rem' }}>
|
||||
Trainingsmodul übernehmen
|
||||
</h2>
|
||||
<p style={{ color: 'var(--text2)', fontSize: '0.9rem', marginBottom: '1rem', lineHeight: 1.5 }}>
|
||||
Der Inhalt wird <strong>kopiert</strong> und ans Ende des gewählten Abschnitts angehängt (Herkunft wird
|
||||
gespeichert). Anschließend kannst du ihn lokal bearbeiten.
|
||||
</p>
|
||||
|
||||
{moduleApplyErr ? (
|
||||
<p style={{ color: 'var(--danger)', fontSize: '0.9rem', marginBottom: '0.75rem' }}>{moduleApplyErr}</p>
|
||||
) : null}
|
||||
|
||||
<div className="form-row">
|
||||
<label className="form-label">Modul</label>
|
||||
<select
|
||||
className="form-input"
|
||||
value={moduleApplyModuleId}
|
||||
onChange={(e) => setModuleApplyModuleId(e.target.value)}
|
||||
disabled={moduleApplyBusy || !moduleApplyList.length}
|
||||
>
|
||||
{!moduleApplyList.length ? (
|
||||
<option value="">Keine Module verfügbar</option>
|
||||
) : null}
|
||||
{moduleApplyList.map((m) => (
|
||||
<option key={m.id} value={String(m.id)}>
|
||||
{(m.title || '').trim() || `Modul #${m.id}`}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="form-row">
|
||||
<label className="form-label">Ziel‑Abschnitt (Reihenfolge wie im Editor)</label>
|
||||
<select
|
||||
className="form-input"
|
||||
value={String(moduleApplySectionIx)}
|
||||
onChange={(e) => setModuleApplySectionIx(parseInt(e.target.value, 10))}
|
||||
disabled={moduleApplyBusy || !formData.sections?.length}
|
||||
>
|
||||
{(formData.sections || []).map((s, i) => (
|
||||
<option key={`sec-opt-${i}`} value={String(i)}>
|
||||
{(s.title || `Abschnitt ${i + 1}`).trim()}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
gap: '0.65rem',
|
||||
flexWrap: 'wrap',
|
||||
justifyContent: 'flex-end',
|
||||
marginTop: '1.25rem',
|
||||
}}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary"
|
||||
disabled={moduleApplyBusy}
|
||||
onClick={() => !moduleApplyBusy && setModuleApplyOpen(false)}
|
||||
>
|
||||
Abbrechen
|
||||
</button>
|
||||
<button type="button" className="btn btn-primary" disabled={moduleApplyBusy} onClick={handleApplyTrainingModuleConfirm}>
|
||||
{moduleApplyBusy ? 'Übernehmen …' : 'Übernehmen'}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<p style={{ margin: '1rem 0 0', fontSize: '0.8rem', color: 'var(--text3)', lineHeight: 1.45 }}>
|
||||
Neue Module kannst du unter{' '}
|
||||
<Link to="/planning/training-modules" style={{ fontWeight: 600, color: 'var(--accent-dark)' }}>
|
||||
Trainingsmodule
|
||||
</Link>{' '}
|
||||
anlegen.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{frameworkImportOpen && (
|
||||
<div
|
||||
style={{
|
||||
@@ -2291,9 +2469,21 @@ function TrainingPlanningPage() {
|
||||
<TrainingUnitSectionsEditor
|
||||
heading="Abschnitte & Übungen"
|
||||
headingAccessory={
|
||||
<button type="button" className="btn btn-secondary" onClick={handleSaveAsTemplate}>
|
||||
Vorlage aus Aufbau speichern
|
||||
</button>
|
||||
<>
|
||||
<button type="button" className="btn btn-secondary" onClick={handleSaveAsTemplate}>
|
||||
Vorlage aus Aufbau speichern
|
||||
</button>
|
||||
{editingUnit?.id ? (
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary"
|
||||
onClick={openModuleApplyModal}
|
||||
title="Übungen und Notizen aus einem Modul ans Ende eines Abschnitts kopieren"
|
||||
>
|
||||
Aus Modul übernehmen…
|
||||
</button>
|
||||
) : null}
|
||||
</>
|
||||
}
|
||||
sections={formData.sections}
|
||||
wideExerciseGrid
|
||||
|
||||
@@ -1327,6 +1327,40 @@ export async function deleteTrainingPlanTemplate(id) {
|
||||
return request(`/api/training-plan-templates/${id}`, { method: 'DELETE' })
|
||||
}
|
||||
|
||||
export async function listTrainingModules() {
|
||||
return request('/api/training-modules')
|
||||
}
|
||||
|
||||
export async function getTrainingModule(id) {
|
||||
return request(`/api/training-modules/${id}`)
|
||||
}
|
||||
|
||||
export async function createTrainingModule(data) {
|
||||
return request('/api/training-modules', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
}
|
||||
|
||||
export async function updateTrainingModule(id, data) {
|
||||
return request(`/api/training-modules/${id}`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
}
|
||||
|
||||
export async function deleteTrainingModule(id) {
|
||||
return request(`/api/training-modules/${id}`, { method: 'DELETE' })
|
||||
}
|
||||
|
||||
/** Kopiert Modul-Inhalte ans Ende eines Abschnitts (section_order_index 0-basiert). */
|
||||
export async function applyTrainingModuleToTrainingUnit(unitId, data) {
|
||||
return request(`/api/training-units/${unitId}/apply-training-module`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
}
|
||||
|
||||
export async function listTrainingFrameworkPrograms() {
|
||||
return request('/api/training-framework-programs')
|
||||
}
|
||||
@@ -1478,6 +1512,12 @@ export const api = {
|
||||
createTrainingPlanTemplate,
|
||||
updateTrainingPlanTemplate,
|
||||
deleteTrainingPlanTemplate,
|
||||
listTrainingModules,
|
||||
getTrainingModule,
|
||||
createTrainingModule,
|
||||
updateTrainingModule,
|
||||
deleteTrainingModule,
|
||||
applyTrainingModuleToTrainingUnit,
|
||||
listTrainingFrameworkPrograms,
|
||||
getTrainingFrameworkProgram,
|
||||
createTrainingFrameworkProgram,
|
||||
|
||||
Reference in new issue
Block a user