feat: enhance exercise management with training types and rich text support
- Added support for training types in exercise creation and updates, allowing for better categorization of exercises. - Implemented a rich text editor for exercise descriptions, improving content formatting capabilities. - Updated the ExerciseDetailPage to display training types and enhanced the layout for better user experience. - Refactored ExerciseFormPage to accommodate new multi-association fields for training styles, types, and target groups. - Improved API payload handling to include training types and ensure proper data structure for exercise management. - Enhanced the ExercisesListPage with improved loading and filtering functionalities for better performance.
This commit is contained in:
1 parent
cb11e39201
commit
d8f439a3e5
8 files changed
+1198
-689
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { Link, useNavigate, useParams } from 'react-router-dom'
|
||||
import api from '../utils/api'
|
||||
import { sanitizeTrainerHtml } from '../utils/htmlUtils'
|
||||
|
||||
const API_BASE = (import.meta.env.VITE_API_URL || '').replace(/\/$/, '')
|
||||
|
||||
@@ -11,6 +12,17 @@ function resolveMediaUrl(filePath) {
|
||||
return `${API_BASE}${p}`
|
||||
}
|
||||
|
||||
function HtmlBlock({ html, className = '' }) {
|
||||
if (!html || !String(html).trim()) return null
|
||||
const safe = sanitizeTrainerHtml(html)
|
||||
return (
|
||||
<div
|
||||
className={`rich-text-content ${className}`}
|
||||
dangerouslySetInnerHTML={{ __html: safe }}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function MediaBlock({ media }) {
|
||||
if (media.embed_url) {
|
||||
return (
|
||||
@@ -47,6 +59,54 @@ function MediaBlock({ media }) {
|
||||
)
|
||||
}
|
||||
|
||||
function TagRow({ exercise }) {
|
||||
const tags = []
|
||||
;(exercise.focus_areas || []).forEach((f) => {
|
||||
tags.push({ key: `fa-${f.id}`, label: f.name, accent: !!f.is_primary })
|
||||
})
|
||||
;(exercise.training_styles || []).forEach((t) => {
|
||||
tags.push({ key: `ts-${t.id}`, label: t.name, accent: false })
|
||||
})
|
||||
;(exercise.training_types || []).forEach((t) => {
|
||||
tags.push({ key: `tt-${t.id}`, label: t.name, accent: false })
|
||||
})
|
||||
;(exercise.target_groups || []).forEach((g) => {
|
||||
tags.push({ key: `tg-${g.id}`, label: g.name, accent: !!g.is_primary })
|
||||
})
|
||||
;(exercise.age_groups || []).forEach((ag) => {
|
||||
tags.push({ key: `ag-${ag}`, label: ag, accent: false })
|
||||
})
|
||||
if (tags.length === 0) return null
|
||||
return (
|
||||
<div className="exercise-tag-row">
|
||||
{tags.map((t) => (
|
||||
<span key={t.key} className={`exercise-tag${t.accent ? ' exercise-tag--accent' : ''}`}>
|
||||
{t.label}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function metaParts(exercise) {
|
||||
const parts = []
|
||||
if (exercise.duration_min != null || exercise.duration_max != null) {
|
||||
const a = exercise.duration_min
|
||||
const b = exercise.duration_max
|
||||
if (a != null && b != null && a !== b) parts.push(`${a}–${b} Min.`)
|
||||
else if (a != null) parts.push(`ca. ${a} Min.`)
|
||||
else if (b != null) parts.push(`ca. ${b} Min.`)
|
||||
}
|
||||
if (exercise.group_size_min != null || exercise.group_size_max != null) {
|
||||
const a = exercise.group_size_min
|
||||
const b = exercise.group_size_max
|
||||
if (a != null && b != null && a !== b) parts.push(`Gruppe ${a}–${b}`)
|
||||
else if (a != null) parts.push(`Gruppe ab ${a}`)
|
||||
else if (b != null) parts.push(`Gruppe bis ${b}`)
|
||||
}
|
||||
return parts
|
||||
}
|
||||
|
||||
function ExerciseDetailPage() {
|
||||
const { id } = useParams()
|
||||
const navigate = useNavigate()
|
||||
@@ -86,7 +146,7 @@ function ExerciseDetailPage() {
|
||||
if (error) {
|
||||
const msg = error.message || String(error)
|
||||
return (
|
||||
<div style={{ padding: '2rem', maxWidth: '720px', margin: '0 auto' }}>
|
||||
<div style={{ padding: '1rem', maxWidth: '640px', margin: '0 auto' }}>
|
||||
<div className="card">
|
||||
<h2>Übung</h2>
|
||||
<p style={{ color: 'var(--danger)' }}>{msg}</p>
|
||||
@@ -100,147 +160,127 @@ function ExerciseDetailPage() {
|
||||
|
||||
if (!exercise) return null
|
||||
|
||||
const chips = (items, labelKey = 'name') =>
|
||||
(items || []).length ? (items || []).map((x) => x[labelKey]).join(', ') : '—'
|
||||
const meta = metaParts(exercise)
|
||||
|
||||
return (
|
||||
<div style={{ padding: '2rem' }}>
|
||||
<div style={{ maxWidth: '800px', margin: '0 auto' }}>
|
||||
<div style={{ marginBottom: '1rem' }}>
|
||||
<button type="button" className="btn btn-secondary" onClick={() => navigate('/exercises')}>
|
||||
← Übersicht
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="card" style={{ marginBottom: '1rem' }}>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
justifyContent: 'space-between',
|
||||
alignItems: 'flex-start',
|
||||
gap: '1rem',
|
||||
flexWrap: 'wrap',
|
||||
}}
|
||||
>
|
||||
<h1 style={{ margin: 0 }}>{exercise.title}</h1>
|
||||
<Link to={`/exercises/${exercise.id}/edit`} className="btn btn-primary">
|
||||
Bearbeiten
|
||||
</Link>
|
||||
</div>
|
||||
{exercise.summary && (
|
||||
<p style={{ color: 'var(--text2)', marginTop: '1rem' }}>{exercise.summary}</p>
|
||||
)}
|
||||
<div style={{ display: 'flex', gap: '0.5rem', flexWrap: 'wrap', marginTop: '1rem' }}>
|
||||
<span className="badge">{exercise.visibility}</span>
|
||||
<span className="badge">{exercise.status}</span>
|
||||
{exercise.club_name && <span className="badge">{exercise.club_name}</span>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<section className="card" style={{ marginBottom: '1rem' }}>
|
||||
<h2 style={{ marginTop: 0 }}>Zuordnung</h2>
|
||||
<p>
|
||||
<strong>Fokusbereiche:</strong> {chips(exercise.focus_areas)}
|
||||
</p>
|
||||
<p>
|
||||
<strong>Stilrichtungen:</strong> {chips(exercise.training_styles)}
|
||||
</p>
|
||||
<p>
|
||||
<strong>Zielgruppen:</strong> {chips(exercise.target_groups)}
|
||||
</p>
|
||||
<p>
|
||||
<strong>Altersgruppen:</strong>{' '}
|
||||
{(exercise.age_groups || []).length ? exercise.age_groups.join(', ') : '—'}
|
||||
</p>
|
||||
</section>
|
||||
|
||||
{exercise.goal && (
|
||||
<section className="card" style={{ marginBottom: '1rem' }}>
|
||||
<h2 style={{ marginTop: 0 }}>Ziel</h2>
|
||||
<p style={{ whiteSpace: 'pre-wrap' }}>{exercise.goal}</p>
|
||||
</section>
|
||||
)}
|
||||
|
||||
{exercise.execution && (
|
||||
<section className="card" style={{ marginBottom: '1rem' }}>
|
||||
<h2 style={{ marginTop: 0 }}>Durchführung</h2>
|
||||
<p style={{ whiteSpace: 'pre-wrap' }}>{exercise.execution}</p>
|
||||
</section>
|
||||
)}
|
||||
|
||||
{(exercise.preparation || exercise.trainer_notes) && (
|
||||
<section className="card" style={{ marginBottom: '1rem' }}>
|
||||
<h2 style={{ marginTop: 0 }}>Trainer</h2>
|
||||
{exercise.preparation && (
|
||||
<>
|
||||
<h3 style={{ fontSize: '1rem' }}>Vorbereitung</h3>
|
||||
<p style={{ whiteSpace: 'pre-wrap' }}>{exercise.preparation}</p>
|
||||
</>
|
||||
)}
|
||||
{exercise.trainer_notes && (
|
||||
<>
|
||||
<h3 style={{ fontSize: '1rem' }}>Hinweise</h3>
|
||||
<p style={{ whiteSpace: 'pre-wrap' }}>{exercise.trainer_notes}</p>
|
||||
</>
|
||||
)}
|
||||
</section>
|
||||
)}
|
||||
|
||||
{exercise.equipment && exercise.equipment.length > 0 && (
|
||||
<section className="card" style={{ marginBottom: '1rem' }}>
|
||||
<h2 style={{ marginTop: 0 }}>Material</h2>
|
||||
<ul>
|
||||
{exercise.equipment.map((x, i) => (
|
||||
<li key={i}>{x}</li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
)}
|
||||
|
||||
{(exercise.skills || []).length > 0 && (
|
||||
<section className="card" style={{ marginBottom: '1rem' }}>
|
||||
<h2 style={{ marginTop: 0 }}>Fähigkeiten</h2>
|
||||
<ul style={{ paddingLeft: '1.25rem' }}>
|
||||
{exercise.skills.map((s) => (
|
||||
<li key={s.id}>
|
||||
{s.skill_name}
|
||||
{s.skill_category ? ` (${s.skill_category})` : ''}
|
||||
{s.is_primary ? ' · primär' : ''}
|
||||
{s.intensity ? ` · ${s.intensity}` : ''}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
)}
|
||||
|
||||
{(exercise.variants || []).length > 0 && (
|
||||
<section className="card" style={{ marginBottom: '1rem' }}>
|
||||
<h2 style={{ marginTop: 0 }}>Varianten</h2>
|
||||
{exercise.variants.map((v) => (
|
||||
<div key={v.id} style={{ marginBottom: '1rem', paddingBottom: '1rem', borderBottom: '1px solid var(--border)' }}>
|
||||
<strong>{v.variant_name}</strong>
|
||||
{v.description && <p style={{ color: 'var(--text2)' }}>{v.description}</p>}
|
||||
{v.execution_changes && (
|
||||
<p style={{ whiteSpace: 'pre-wrap' }}>{v.execution_changes}</p>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</section>
|
||||
)}
|
||||
|
||||
{(exercise.media || []).length > 0 && (
|
||||
<section className="card">
|
||||
<h2 style={{ marginTop: 0 }}>Medien</h2>
|
||||
{exercise.media.map((m) => (
|
||||
<div key={m.id} style={{ marginBottom: '1.5rem' }}>
|
||||
<strong>{m.title || m.original_filename || m.media_type}</strong>
|
||||
{m.description && <p style={{ color: 'var(--text2)', fontSize: '0.9rem' }}>{m.description}</p>}
|
||||
<MediaBlock media={m} />
|
||||
</div>
|
||||
))}
|
||||
</section>
|
||||
)}
|
||||
<div className="exercise-detail-shell" style={{ padding: '12px 12px 24px' }}>
|
||||
<div style={{ marginBottom: '12px', display: 'flex', justifyContent: 'space-between', gap: '8px', flexWrap: 'wrap' }}>
|
||||
<button type="button" className="btn btn-secondary" onClick={() => navigate('/exercises')}>
|
||||
← Übersicht
|
||||
</button>
|
||||
<Link to={`/exercises/${exercise.id}/edit`} className="btn btn-primary">
|
||||
Bearbeiten
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<div className="card exercise-detail-section">
|
||||
<h1 style={{ margin: 0, fontSize: '1.35rem', lineHeight: 1.25 }}>{exercise.title}</h1>
|
||||
{exercise.summary && (
|
||||
<div style={{ marginTop: '10px', color: 'var(--text2)', fontSize: '15px' }}>
|
||||
<HtmlBlock html={exercise.summary} />
|
||||
</div>
|
||||
)}
|
||||
<TagRow exercise={exercise} />
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '6px', marginTop: '10px' }}>
|
||||
<span className="badge">{exercise.visibility}</span>
|
||||
<span className="badge">{exercise.status}</span>
|
||||
{exercise.club_name && <span className="badge">{exercise.club_name}</span>}
|
||||
</div>
|
||||
{meta.length > 0 && <p className="exercise-meta-line">{meta.join(' · ')}</p>}
|
||||
</div>
|
||||
|
||||
{exercise.goal && (
|
||||
<section className="card exercise-detail-section">
|
||||
<h2>Ziel</h2>
|
||||
<HtmlBlock html={exercise.goal} />
|
||||
</section>
|
||||
)}
|
||||
|
||||
{(exercise.equipment || []).length > 0 && (
|
||||
<section className="card exercise-detail-section">
|
||||
<h2>Material & Aufbau</h2>
|
||||
<ul style={{ paddingLeft: '1.2rem', margin: 0 }}>
|
||||
{exercise.equipment.map((x, i) => (
|
||||
<li key={i}>{x}</li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
)}
|
||||
|
||||
{exercise.preparation && (
|
||||
<section className="card exercise-detail-section">
|
||||
<h2>Vorbereitung</h2>
|
||||
<HtmlBlock html={exercise.preparation} />
|
||||
</section>
|
||||
)}
|
||||
|
||||
{exercise.execution && (
|
||||
<section className="card exercise-detail-section">
|
||||
<h2>Ablauf</h2>
|
||||
<HtmlBlock html={exercise.execution} />
|
||||
</section>
|
||||
)}
|
||||
|
||||
{(exercise.media || []).length > 0 && (
|
||||
<section className="card exercise-detail-section">
|
||||
<h2>Medien</h2>
|
||||
{exercise.media.map((m) => (
|
||||
<div key={m.id} style={{ marginBottom: '1.25rem' }}>
|
||||
<strong style={{ fontSize: '15px' }}>{m.title || m.original_filename || m.media_type}</strong>
|
||||
{m.description && <p style={{ color: 'var(--text2)', fontSize: '0.9rem' }}>{m.description}</p>}
|
||||
<MediaBlock media={m} />
|
||||
</div>
|
||||
))}
|
||||
</section>
|
||||
)}
|
||||
|
||||
{exercise.trainer_notes && (
|
||||
<section className="card exercise-detail-section">
|
||||
<h2>Hinweise für Trainer</h2>
|
||||
<HtmlBlock html={exercise.trainer_notes} />
|
||||
</section>
|
||||
)}
|
||||
|
||||
{(exercise.skills || []).length > 0 && (
|
||||
<section className="card exercise-detail-section">
|
||||
<h2>Fähigkeiten</h2>
|
||||
<div className="exercise-tag-row">
|
||||
{exercise.skills.map((s) => (
|
||||
<span key={s.id} className={`exercise-tag${s.is_primary ? ' exercise-tag--accent' : ''}`}>
|
||||
{s.skill_name}
|
||||
{s.intensity ? ` · ${s.intensity}` : ''}
|
||||
{s.required_level || s.target_level
|
||||
? ` (${[s.required_level, s.target_level].filter(Boolean).join(' → ')})`
|
||||
: ''}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
|
||||
{(exercise.variants || []).length > 0 && (
|
||||
<section className="card exercise-detail-section">
|
||||
<h2>Varianten</h2>
|
||||
{exercise.variants.map((v) => (
|
||||
<div
|
||||
key={v.id}
|
||||
style={{
|
||||
marginBottom: '1rem',
|
||||
paddingBottom: '1rem',
|
||||
borderBottom: '1px solid var(--border)',
|
||||
}}
|
||||
>
|
||||
<strong style={{ fontSize: '15px' }}>{v.variant_name}</strong>
|
||||
{v.description && <p style={{ color: 'var(--text2)', marginTop: '4px' }}>{v.description}</p>}
|
||||
{v.execution_changes && (
|
||||
<div style={{ marginTop: '8px' }}>
|
||||
<HtmlBlock html={v.execution_changes} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</section>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user