feat(exercises): implement inline media support in exercise content
Deploy Development / deploy (push) Successful in 37s
Test Suite / pytest-backend (push) Successful in 25s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 7s
Test Suite / playwright-tests (push) Successful in 24s
Deploy Development / deploy (push) Successful in 37s
Test Suite / pytest-backend (push) Successful in 25s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 7s
Test Suite / playwright-tests (push) Successful in 24s
- Added functionality for inline media references in exercise text using `{{exerciseMedia:id}}` syntax, which normalizes to a canonical `<span>` element.
- Updated the frontend to utilize `ExerciseRichTextBlock` for rendering exercise content, allowing for embedded media display.
- Enhanced the Rich Text Editor to support inserting inline media placeholders.
- Version bump to 0.8.60 to reflect these changes in media handling and exercise content management.
This commit is contained in:
1 parent
f745e5d082
commit
cc51b0f08f
17 files changed
+655
-149
No files matched your search
@@ -1,57 +1,10 @@
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { Link, useNavigate, useParams } from 'react-router-dom'
|
||||
import api from '../utils/api'
|
||||
import { resolveExerciseMediaFileUrl } from '../utils/exerciseMediaUrl'
|
||||
import { sanitizeTrainerHtml } from '../utils/htmlUtils'
|
||||
import ExerciseRichTextBlock from '../components/ExerciseRichTextBlock'
|
||||
import ExerciseMediaEmbed from '../components/ExerciseMediaEmbed'
|
||||
import { formatSkillLevelSlug } from '../constants/skillLevels'
|
||||
|
||||
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, exerciseId }) {
|
||||
if (media.embed_url) {
|
||||
return (
|
||||
<div style={{ marginTop: '0.5rem' }}>
|
||||
<a href={media.embed_url} target="_blank" rel="noreferrer">
|
||||
{media.embed_url}
|
||||
</a>
|
||||
{media.embed_platform && (
|
||||
<span style={{ color: 'var(--text2)', marginLeft: '0.5rem', fontSize: '0.8rem' }}>
|
||||
({media.embed_platform})
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
const src = resolveExerciseMediaFileUrl(exerciseId, media)
|
||||
if (!src) return null
|
||||
if (media.media_type === 'image' || (media.mime_type && media.mime_type.startsWith('image/'))) {
|
||||
return (
|
||||
<img
|
||||
src={src}
|
||||
alt={media.title || media.original_filename || ''}
|
||||
style={{ maxWidth: '100%', borderRadius: '8px', marginTop: '0.5rem' }}
|
||||
/>
|
||||
)
|
||||
}
|
||||
if (media.media_type === 'video' || (media.mime_type && media.mime_type.startsWith('video/'))) {
|
||||
return <video src={src} controls style={{ width: '100%', marginTop: '0.5rem', borderRadius: '8px' }} />
|
||||
}
|
||||
return (
|
||||
<a href={src} target="_blank" rel="noreferrer" style={{ display: 'inline-block', marginTop: '0.5rem' }}>
|
||||
{media.title || media.original_filename || 'Datei öffnen'}
|
||||
</a>
|
||||
)
|
||||
}
|
||||
|
||||
function TagRow({ exercise }) {
|
||||
const tags = []
|
||||
;(exercise.focus_areas || []).forEach((f) => {
|
||||
@@ -171,7 +124,7 @@ function ExerciseDetailPage() {
|
||||
<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} />
|
||||
<ExerciseRichTextBlock html={exercise.summary} exerciseId={exercise.id} media={exercise.media} />
|
||||
</div>
|
||||
)}
|
||||
<TagRow exercise={exercise} />
|
||||
@@ -186,7 +139,7 @@ function ExerciseDetailPage() {
|
||||
{exercise.goal && (
|
||||
<section className="card exercise-detail-section">
|
||||
<h2>Ziel</h2>
|
||||
<HtmlBlock html={exercise.goal} />
|
||||
<ExerciseRichTextBlock html={exercise.goal} exerciseId={exercise.id} media={exercise.media} />
|
||||
</section>
|
||||
)}
|
||||
|
||||
@@ -204,14 +157,14 @@ function ExerciseDetailPage() {
|
||||
{exercise.preparation && (
|
||||
<section className="card exercise-detail-section">
|
||||
<h2>Vorbereitung</h2>
|
||||
<HtmlBlock html={exercise.preparation} />
|
||||
<ExerciseRichTextBlock html={exercise.preparation} exerciseId={exercise.id} media={exercise.media} />
|
||||
</section>
|
||||
)}
|
||||
|
||||
{exercise.execution && (
|
||||
<section className="card exercise-detail-section">
|
||||
<h2>Ablauf</h2>
|
||||
<HtmlBlock html={exercise.execution} />
|
||||
<ExerciseRichTextBlock html={exercise.execution} exerciseId={exercise.id} media={exercise.media} />
|
||||
</section>
|
||||
)}
|
||||
|
||||
@@ -227,7 +180,7 @@ function ExerciseDetailPage() {
|
||||
</p>
|
||||
)}
|
||||
{m.description && <p style={{ color: 'var(--text2)', fontSize: '0.9rem' }}>{m.description}</p>}
|
||||
<MediaBlock media={m} exerciseId={exercise.id} />
|
||||
<ExerciseMediaEmbed media={m} exerciseId={exercise.id} />
|
||||
</div>
|
||||
))}
|
||||
</section>
|
||||
@@ -236,7 +189,7 @@ function ExerciseDetailPage() {
|
||||
{exercise.trainer_notes && (
|
||||
<section className="card exercise-detail-section">
|
||||
<h2>Hinweise für Trainer</h2>
|
||||
<HtmlBlock html={exercise.trainer_notes} />
|
||||
<ExerciseRichTextBlock html={exercise.trainer_notes} exerciseId={exercise.id} media={exercise.media} />
|
||||
</section>
|
||||
)}
|
||||
|
||||
@@ -307,7 +260,11 @@ function ExerciseDetailPage() {
|
||||
{v.description && <p style={{ color: 'var(--text2)', marginTop: '4px' }}>{v.description}</p>}
|
||||
{v.execution_changes && (
|
||||
<div style={{ marginTop: '8px' }}>
|
||||
<HtmlBlock html={v.execution_changes} />
|
||||
<ExerciseRichTextBlock
|
||||
html={v.execution_changes}
|
||||
exerciseId={exercise.id}
|
||||
media={exercise.media}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -169,7 +169,7 @@ function buildVariantPayloadFromRow(row) {
|
||||
}
|
||||
|
||||
/** Gemeinsame Felder für „Variante bearbeiten“ und „Neue Variante“. */
|
||||
function ExerciseVariantFields({ row, onPatch, prerequisiteOthers, rteMinHeight = '110px' }) {
|
||||
function ExerciseVariantFields({ row, onPatch, prerequisiteOthers, rteMinHeight = '110px', exerciseMediaInsertSlots }) {
|
||||
return (
|
||||
<>
|
||||
<div className="form-row">
|
||||
@@ -198,6 +198,7 @@ function ExerciseVariantFields({ row, onPatch, prerequisiteOthers, rteMinHeight
|
||||
onChange={(html) => onPatch({ execution_changes: html })}
|
||||
placeholder="Was unterscheidet diese Variante? (Listen über Symbolleiste)"
|
||||
minHeight={rteMinHeight}
|
||||
insertExerciseMediaSlots={exerciseMediaInsertSlots}
|
||||
/>
|
||||
</div>
|
||||
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '10px' }}>
|
||||
@@ -459,6 +460,16 @@ function ExerciseFormPage() {
|
||||
const [archiveError, setArchiveError] = useState(null)
|
||||
const [mediaPreview, setMediaPreview] = useState(null)
|
||||
|
||||
const exerciseMediaInsertSlots = useMemo(() => {
|
||||
if (!isEdit) return []
|
||||
return (mediaList || [])
|
||||
.filter((m) => m?.id != null)
|
||||
.map((m) => ({
|
||||
id: m.id,
|
||||
label: (m.title && String(m.title).trim()) || m.original_filename || `Medium #${m.id}`,
|
||||
}))
|
||||
}, [isEdit, mediaList])
|
||||
|
||||
useEffect(() => {
|
||||
const next = {}
|
||||
for (const m of mediaList) {
|
||||
@@ -1040,6 +1051,7 @@ function ExerciseFormPage() {
|
||||
onChange={(html) => updateFormField('summary', html)}
|
||||
placeholder="Kurzbeschreibung (optional)"
|
||||
minHeight="80px"
|
||||
insertExerciseMediaSlots={exerciseMediaInsertSlots}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -1050,6 +1062,7 @@ function ExerciseFormPage() {
|
||||
onChange={(html) => updateFormField('goal', html)}
|
||||
placeholder="Trainingsziel"
|
||||
minHeight="120px"
|
||||
insertExerciseMediaSlots={exerciseMediaInsertSlots}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -1060,6 +1073,7 @@ function ExerciseFormPage() {
|
||||
onChange={(html) => updateFormField('execution', html)}
|
||||
placeholder="Ablauf Schritt für Schritt"
|
||||
minHeight="180px"
|
||||
insertExerciseMediaSlots={exerciseMediaInsertSlots}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -1070,6 +1084,7 @@ function ExerciseFormPage() {
|
||||
onChange={(html) => updateFormField('preparation', html)}
|
||||
placeholder="Matten, Raum, …"
|
||||
minHeight="100px"
|
||||
insertExerciseMediaSlots={exerciseMediaInsertSlots}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -1080,6 +1095,7 @@ function ExerciseFormPage() {
|
||||
onChange={(html) => updateFormField('trainer_notes', html)}
|
||||
placeholder="Sicherheit, Varianten-Hinweise, …"
|
||||
minHeight="100px"
|
||||
insertExerciseMediaSlots={exerciseMediaInsertSlots}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -1374,6 +1390,7 @@ function ExerciseFormPage() {
|
||||
onPatch={(patch) => setVariantDraft((d) => ({ ...d, ...patch }))}
|
||||
prerequisiteOthers={variants}
|
||||
rteMinHeight="110px"
|
||||
exerciseMediaInsertSlots={exerciseMediaInsertSlots}
|
||||
/>
|
||||
<button type="submit" className="btn btn-primary" style={{ marginTop: '10px' }} disabled={variantBusy}>
|
||||
{variantBusy ? 'Anlegen…' : 'Variante anlegen'}
|
||||
@@ -1440,6 +1457,7 @@ function ExerciseFormPage() {
|
||||
onPatch={(patch) => updateVariantField(selectedVariantForEdit.id, patch)}
|
||||
prerequisiteOthers={variants.filter((o) => o.id !== selectedVariantForEdit.id)}
|
||||
rteMinHeight="110px"
|
||||
exerciseMediaInsertSlots={exerciseMediaInsertSlots}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -19,6 +19,7 @@ import MultiSelectCombo from '../components/MultiSelectCombo'
|
||||
import ExerciseFocusRulePicker from '../components/ExerciseFocusRulePicker'
|
||||
import CatalogRulePicker from '../components/CatalogRulePicker'
|
||||
import ExerciseProgressionGraphPanel from '../components/ExerciseProgressionGraphPanel'
|
||||
import ExerciseRichTextBlock from '../components/ExerciseRichTextBlock'
|
||||
import PageSectionNav from '../components/PageSectionNav'
|
||||
import {
|
||||
INITIAL_EXERCISE_LIST_FILTERS,
|
||||
@@ -27,7 +28,7 @@ import {
|
||||
splitMnCatalogRules,
|
||||
splitScalarCatalogRules,
|
||||
} from '../constants/exerciseListFilters'
|
||||
import { sanitizeExerciseRichText, coerceApiNameList } from '../utils/sanitizeHtml'
|
||||
import { coerceApiNameList } from '../utils/sanitizeHtml'
|
||||
import { canUserRequestExerciseDelete } from '../utils/exercisePermissions'
|
||||
|
||||
const PAGE_SIZE = 100
|
||||
@@ -1380,9 +1381,6 @@ function ExercisesListPage() {
|
||||
const focusNames = exerciseFocusNames(exercise)
|
||||
const styleNames = coerceApiNameList(exercise.style_direction_names)
|
||||
const typeNames = coerceApiNameList(exercise.training_type_names)
|
||||
const summaryHtml = exercise.summary
|
||||
? sanitizeExerciseRichText(exercise.summary)
|
||||
: ''
|
||||
return (
|
||||
<div key={exercise.id} className={exerciseCardClassName(exercise, user?.id)}>
|
||||
<div className="exercise-card-layout exercise-card-layout--grow">
|
||||
@@ -1410,11 +1408,14 @@ function ExercisesListPage() {
|
||||
<span key={`tt:${name}`} className="exercise-tag exercise-tag--training">{name}</span>
|
||||
))}
|
||||
</div>
|
||||
{summaryHtml ? (
|
||||
<div
|
||||
className="exercise-card-summary exercise-card-summary--rich"
|
||||
dangerouslySetInnerHTML={{ __html: summaryHtml }}
|
||||
/>
|
||||
{exercise.summary && String(exercise.summary).trim() ? (
|
||||
<div className="exercise-card-summary exercise-card-summary--rich">
|
||||
<ExerciseRichTextBlock
|
||||
html={exercise.summary}
|
||||
exerciseId={exercise.id}
|
||||
media={exercise.media || []}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user