feat: enhance exercise editing permissions and media management
Deploy Development / deploy (push) Successful in 35s
Test Suite / pytest-backend (push) Successful in 24s
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 35s
Test Suite / pytest-backend (push) Successful in 24s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 7s
Test Suite / playwright-tests (push) Successful in 24s
- Updated exercise editing permissions to allow platform admins and users with planning rights in clubs to edit exercises, improving governance. - Refactored the `_assert_can_edit_exercise` function to utilize tenant context for permission checks. - Enhanced frontend media management with new features for saving media metadata and reordering media items, improving user experience. - Introduced state management for media fields in the ExerciseFormPage, allowing users to edit titles and contexts for media assets.
This commit is contained in:
1 parent
7284c577d7
commit
ece08ec1a1
2 files changed
+170
-24
No files matched your search
@@ -367,6 +367,19 @@ function ExerciseFormPage() {
|
||||
const [mediaContext, setMediaContext] = useState('ablauf')
|
||||
const [embedUrl, setEmbedUrl] = useState('')
|
||||
const [embedTitle, setEmbedTitle] = useState('')
|
||||
const [mediaFields, setMediaFields] = useState({})
|
||||
const [mediaSavingId, setMediaSavingId] = useState(null)
|
||||
|
||||
useEffect(() => {
|
||||
const next = {}
|
||||
for (const m of mediaList) {
|
||||
next[m.id] = {
|
||||
title: m.title || '',
|
||||
context: m.context || 'ablauf',
|
||||
}
|
||||
}
|
||||
setMediaFields(next)
|
||||
}, [mediaList])
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
@@ -599,6 +612,43 @@ function ExerciseFormPage() {
|
||||
}
|
||||
}
|
||||
|
||||
const moveMediaRow = async (idx, dir) => {
|
||||
if (!exerciseId) return
|
||||
const j = idx + dir
|
||||
if (j < 0 || j >= mediaList.length) return
|
||||
const next = [...mediaList]
|
||||
const tmp = next[idx]
|
||||
next[idx] = next[j]
|
||||
next[j] = tmp
|
||||
try {
|
||||
await api.reorderExerciseMedia(
|
||||
exerciseId,
|
||||
next.map((x) => x.id),
|
||||
)
|
||||
setMediaList(next)
|
||||
} catch (e) {
|
||||
alert(e.message || String(e))
|
||||
}
|
||||
}
|
||||
|
||||
const saveMediaMeta = async (mid) => {
|
||||
if (!exerciseId) return
|
||||
const fld = mediaFields[mid]
|
||||
if (!fld) return
|
||||
setMediaSavingId(mid)
|
||||
try {
|
||||
await api.updateExerciseMedia(exerciseId, mid, {
|
||||
title: fld.title.trim() || null,
|
||||
context: fld.context,
|
||||
})
|
||||
await refreshMedia()
|
||||
} catch (e) {
|
||||
alert(e.message || String(e))
|
||||
} finally {
|
||||
setMediaSavingId(null)
|
||||
}
|
||||
}
|
||||
|
||||
const refreshVariants = async () => {
|
||||
if (!exerciseId) return
|
||||
const ex = await api.getExercise(exerciseId)
|
||||
@@ -1230,18 +1280,95 @@ function ExerciseFormPage() {
|
||||
</div>
|
||||
</div>
|
||||
{mediaList.length > 0 && (
|
||||
<ul style={{ marginTop: '12px', paddingLeft: '1.2rem' }}>
|
||||
{mediaList.map((m) => (
|
||||
<li key={m.id} style={{ marginBottom: '6px' }}>
|
||||
{m.title || m.original_filename || m.media_type}{' '}
|
||||
{m.embed_platform ? `(${m.embed_platform})` : ''}
|
||||
<ul style={{ marginTop: '12px', paddingLeft: '0', listStyle: 'none' }}>
|
||||
{mediaList.map((m, idx) => (
|
||||
<li
|
||||
key={m.id}
|
||||
className="card"
|
||||
style={{
|
||||
marginBottom: '10px',
|
||||
padding: '10px 12px',
|
||||
border: '1px solid var(--border)',
|
||||
}}
|
||||
>
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '8px', alignItems: 'center' }}>
|
||||
<span style={{ fontSize: '12px', color: 'var(--text3)' }}>
|
||||
#{idx + 1} · {m.media_type}
|
||||
{m.embed_platform ? ` · ${m.embed_platform}` : ''}
|
||||
</span>
|
||||
{mediaList.length > 1 && (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary"
|
||||
style={{ fontSize: '11px', padding: '2px 8px' }}
|
||||
disabled={idx === 0}
|
||||
onClick={() => moveMediaRow(idx, -1)}
|
||||
title="Nach oben"
|
||||
>
|
||||
↑
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary"
|
||||
style={{ fontSize: '11px', padding: '2px 8px' }}
|
||||
disabled={idx >= mediaList.length - 1}
|
||||
onClick={() => moveMediaRow(idx, 1)}
|
||||
title="Nach unten"
|
||||
>
|
||||
↓
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<div className="form-row" style={{ marginTop: '8px', display: 'grid', gap: '8px' }}>
|
||||
<input
|
||||
type="text"
|
||||
className="form-input"
|
||||
placeholder="Titel"
|
||||
value={(mediaFields[m.id] || {}).title ?? ''}
|
||||
onChange={(e) =>
|
||||
setMediaFields((prev) => ({
|
||||
...prev,
|
||||
[m.id]: { ...(prev[m.id] || {}), title: e.target.value, context: (prev[m.id] || {}).context || 'ablauf' },
|
||||
}))
|
||||
}
|
||||
/>
|
||||
<select
|
||||
className="form-input"
|
||||
value={(mediaFields[m.id] || {}).context || 'ablauf'}
|
||||
onChange={(e) =>
|
||||
setMediaFields((prev) => ({
|
||||
...prev,
|
||||
[m.id]: {
|
||||
...(prev[m.id] || {}),
|
||||
title: (prev[m.id] || {}).title ?? '',
|
||||
context: e.target.value,
|
||||
},
|
||||
}))
|
||||
}
|
||||
>
|
||||
<option value="ablauf">Ablauf</option>
|
||||
<option value="detail">Detail</option>
|
||||
<option value="trainer_hint">Trainer-Hinweis</option>
|
||||
</select>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-primary"
|
||||
style={{ fontSize: '12px' }}
|
||||
disabled={mediaSavingId === m.id}
|
||||
onClick={() => saveMediaMeta(m.id)}
|
||||
>
|
||||
{mediaSavingId === m.id ? 'Speichern…' : 'Titel & Sektion speichern'}
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
className="btn"
|
||||
style={{
|
||||
marginLeft: '8px',
|
||||
marginTop: '8px',
|
||||
fontSize: '11px',
|
||||
padding: '2px 8px',
|
||||
padding: '4px 10px',
|
||||
background: 'var(--danger)',
|
||||
color: '#fff',
|
||||
border: 'none',
|
||||
|
||||
Reference in new issue
Block a user