chore: update versioning and enhance training framework features
- Incremented APP_VERSION to 0.8.10 and DB_SCHEMA_VERSION to 20260505037. - Updated project status and domain model documentation to reflect recent changes. - Enhanced training framework program handling with new slot-blueprint structure. - Introduced API endpoint for creating training units from framework slots. - Improved documentation for training planning and governance concepts.
This commit is contained in:
1 parent
7e21b44604
commit
c4fbabd8f6
12 files changed
+940
-1070
No files matched your search
@@ -3,13 +3,19 @@ import { Link, useNavigate, useParams, useLocation } from 'react-router-dom'
|
||||
import api from '../utils/api'
|
||||
import ExercisePickerModal from '../components/ExercisePickerModal'
|
||||
import ExercisePeekModal from '../components/ExercisePeekModal'
|
||||
import TrainingUnitSectionsEditor from '../components/TrainingUnitSectionsEditor'
|
||||
import {
|
||||
defaultSection,
|
||||
normalizeUnitToForm,
|
||||
enrichSectionsWithVariants,
|
||||
buildSectionsPayload,
|
||||
} from '../utils/trainingUnitSectionsForm'
|
||||
|
||||
const DND_FW_SLOT = 'application/x-shinkan-framework-slot'
|
||||
|
||||
/** Unter dieser Breite: 2 Tabs (Stammdaten | Plan); darüber: alles untereinander */
|
||||
const FRAMEWORK_DESKTOP_MIN_PX = 900
|
||||
|
||||
const DND_FW_EX = 'application/x-shinkan-framework-exercise'
|
||||
const DND_FW_SLOT = 'application/x-shinkan-framework-slot'
|
||||
|
||||
function reorderArray(arr, from, to) {
|
||||
if (from === to || from < 0 || from >= arr.length) return [...arr]
|
||||
const next = [...arr]
|
||||
@@ -23,12 +29,21 @@ function emptyGoal() {
|
||||
return { title: '', notes: '' }
|
||||
}
|
||||
|
||||
function emptyExercise() {
|
||||
return { exercise_id: '', exercise_variant_id: '', exercise_title: '', variants: [] }
|
||||
}
|
||||
|
||||
function emptySlot() {
|
||||
return { title: '', notes: '', exercises: [] }
|
||||
return { title: '', notes: '', sections: [defaultSection('Ablauf')] }
|
||||
}
|
||||
|
||||
async function enrichFrameworkSlotSections(slots) {
|
||||
const out = []
|
||||
for (const s of slots || []) {
|
||||
const sec = normalizeUnitToForm({ sections: s.sections, exercises: s.exercises })
|
||||
out.push({
|
||||
...s,
|
||||
sections: await enrichSectionsWithVariants(sec),
|
||||
})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/** Native-Tooltip für Ziel-Chips (Hover); kurz halten für OS-Tooltip-Limits */
|
||||
@@ -81,52 +96,11 @@ function serverFrameworkToForm(fw) {
|
||||
slots: (fw.slots || []).map((s) => ({
|
||||
title: s.title || '',
|
||||
notes: s.notes || '',
|
||||
exercises: (s.exercises || []).map((ex) => ({
|
||||
exercise_id: ex.exercise_id,
|
||||
exercise_variant_id: ex.exercise_variant_id != null ? String(ex.exercise_variant_id) : '',
|
||||
exercise_title: ex.exercise_title || '',
|
||||
variants: [],
|
||||
})),
|
||||
sections: normalizeUnitToForm({ sections: s.sections, exercises: s.exercises }),
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
async function enrichSlotExercisesWithVariants(formSlots) {
|
||||
const ids = new Set()
|
||||
for (const s of formSlots || []) {
|
||||
for (const it of s.exercises || []) {
|
||||
if (it.exercise_id) ids.add(Number(it.exercise_id))
|
||||
}
|
||||
}
|
||||
const cache = new Map()
|
||||
await Promise.all(
|
||||
[...ids].map(async (id) => {
|
||||
try {
|
||||
const ex = await api.getExercise(id)
|
||||
cache.set(id, {
|
||||
title: ex.title || '',
|
||||
variants: Array.isArray(ex.variants) ? ex.variants : [],
|
||||
})
|
||||
} catch {
|
||||
cache.set(id, { title: '', variants: [] })
|
||||
}
|
||||
})
|
||||
)
|
||||
return (formSlots || []).map((s) => ({
|
||||
...s,
|
||||
exercises: (s.exercises || []).map((it) => {
|
||||
if (!it.exercise_id) return it
|
||||
const c = cache.get(Number(it.exercise_id))
|
||||
if (!c) return it
|
||||
return {
|
||||
...it,
|
||||
exercise_title: it.exercise_title || c.title,
|
||||
variants: it.variants?.length ? it.variants : c.variants,
|
||||
}
|
||||
}),
|
||||
}))
|
||||
}
|
||||
|
||||
function buildApiPayload(form) {
|
||||
const goals = (form.goals || [])
|
||||
.map((g, i) => ({
|
||||
@@ -140,23 +114,13 @@ function buildApiPayload(form) {
|
||||
}
|
||||
|
||||
const slots = (form.slots || []).map((s, si) => {
|
||||
const exercises = (s.exercises || [])
|
||||
.map((ex, j) => {
|
||||
if (!ex.exercise_id) return null
|
||||
const vid = ex.exercise_variant_id
|
||||
return {
|
||||
exercise_id: parseInt(ex.exercise_id, 10),
|
||||
exercise_variant_id:
|
||||
vid !== '' && vid != null && !Number.isNaN(Number(vid)) ? parseInt(vid, 10) : null,
|
||||
order_index: j,
|
||||
}
|
||||
})
|
||||
.filter(Boolean)
|
||||
const secList = s.sections && s.sections.length ? s.sections : [defaultSection('Ablauf')]
|
||||
const sectionsPayload = buildSectionsPayload(secList)
|
||||
return {
|
||||
sort_order: si,
|
||||
title: (s.title || '').trim() || null,
|
||||
notes: (s.notes || '').trim() || null,
|
||||
exercises,
|
||||
sections: sectionsPayload,
|
||||
}
|
||||
})
|
||||
|
||||
@@ -212,11 +176,10 @@ export default function TrainingFrameworkProgramEditPage() {
|
||||
const [styleDirections, setStyleDirections] = useState([])
|
||||
const [trainingTypesCatalog, setTrainingTypesCatalog] = useState([])
|
||||
const [targetGroupsCatalog, setTargetGroupsCatalog] = useState([])
|
||||
const [pickerSlotIdx, setPickerSlotIdx] = useState(null)
|
||||
const [sectionPickerCtx, setSectionPickerCtx] = useState(null)
|
||||
const [peekId, setPeekId] = useState(null)
|
||||
const [editingGoalIdx, setEditingGoalIdx] = useState(null)
|
||||
const [goalMenuGi, setGoalMenuGi] = useState(null)
|
||||
const [exerciseMenu, setExerciseMenu] = useState(null)
|
||||
/** Nur schmal: Stammdaten | Plan (Ziele übereinander, darunter Slots) — Desktop: alles sichtbar */
|
||||
const [frameworkTab, setFrameworkTab] = useState('meta')
|
||||
const [desktopLayout, setDesktopLayout] = useState(
|
||||
@@ -237,7 +200,6 @@ export default function TrainingFrameworkProgramEditPage() {
|
||||
const onPointerDown = (e) => {
|
||||
const t = e.target
|
||||
if (t.closest?.('.framework-popmenu-anchor')) return
|
||||
setExerciseMenu(null)
|
||||
setGoalMenuGi(null)
|
||||
}
|
||||
document.addEventListener('pointerdown', onPointerDown, true)
|
||||
@@ -289,7 +251,7 @@ export default function TrainingFrameworkProgramEditPage() {
|
||||
const fw = await api.getTrainingFrameworkProgram(fid)
|
||||
if (cancelled) return
|
||||
let next = serverFrameworkToForm(fw)
|
||||
next = { ...next, slots: await enrichSlotExercisesWithVariants(next.slots) }
|
||||
next = { ...next, slots: await enrichFrameworkSlotSections(next.slots) }
|
||||
setForm(next)
|
||||
} catch (e) {
|
||||
alert(e.message || 'Laden fehlgeschlagen')
|
||||
@@ -360,85 +322,6 @@ export default function TrainingFrameworkProgramEditPage() {
|
||||
}))
|
||||
}
|
||||
|
||||
const addExerciseToSlot = (sIdx) => {
|
||||
setForm((prev) => ({
|
||||
...prev,
|
||||
slots: prev.slots.map((s, i) =>
|
||||
i === sIdx ? { ...s, exercises: [...(s.exercises || []), emptyExercise()] } : s
|
||||
),
|
||||
}))
|
||||
}
|
||||
|
||||
const moveExercise = (sIdx, eIdx, dir) => {
|
||||
setForm((prev) => ({
|
||||
...prev,
|
||||
slots: prev.slots.map((s, i) => {
|
||||
if (i !== sIdx) return s
|
||||
const j = eIdx + dir
|
||||
const ex = [...(s.exercises || [])]
|
||||
if (j < 0 || j >= ex.length) return s
|
||||
;[ex[eIdx], ex[j]] = [ex[j], ex[eIdx]]
|
||||
return { ...s, exercises: ex }
|
||||
}),
|
||||
}))
|
||||
}
|
||||
|
||||
const removeExercise = (sIdx, eIdx) => {
|
||||
setForm((prev) => ({
|
||||
...prev,
|
||||
slots: prev.slots.map((s, i) => {
|
||||
if (i !== sIdx) return s
|
||||
return { ...s, exercises: (s.exercises || []).filter((_, ei) => ei !== eIdx) }
|
||||
}),
|
||||
}))
|
||||
}
|
||||
|
||||
const setExerciseChoice = async (sIdx, eIdx, exercise) => {
|
||||
const vid = ''
|
||||
let variants = Array.isArray(exercise.variants) ? exercise.variants : []
|
||||
let title = exercise.title || ''
|
||||
if (!variants.length) {
|
||||
try {
|
||||
const full = await api.getExercise(exercise.id)
|
||||
variants = Array.isArray(full.variants) ? full.variants : []
|
||||
title = full.title || title
|
||||
} catch {
|
||||
variants = []
|
||||
}
|
||||
}
|
||||
setForm((prev) => ({
|
||||
...prev,
|
||||
slots: prev.slots.map((s, i) => {
|
||||
if (i !== sIdx) return s
|
||||
const exRows = [...(s.exercises || [])]
|
||||
const row = exRows[eIdx] || emptyExercise()
|
||||
exRows[eIdx] = {
|
||||
...row,
|
||||
exercise_id: exercise.id,
|
||||
exercise_variant_id: vid,
|
||||
exercise_title: title,
|
||||
variants,
|
||||
}
|
||||
return { ...s, exercises: exRows }
|
||||
}),
|
||||
}))
|
||||
}
|
||||
|
||||
const exerciseField = (sIdx, eIdx, key, val) => {
|
||||
setForm((prev) => ({
|
||||
...prev,
|
||||
slots: prev.slots.map((s, i) => {
|
||||
if (i !== sIdx) return s
|
||||
return {
|
||||
...s,
|
||||
exercises: (s.exercises || []).map((ex, ei) =>
|
||||
ei === eIdx ? { ...ex, [key]: val } : ex
|
||||
),
|
||||
}
|
||||
}),
|
||||
}))
|
||||
}
|
||||
|
||||
const handleSave = async () => {
|
||||
if (!(form.title || '').trim()) {
|
||||
alert('Titel ist Pflichtfeld.')
|
||||
@@ -465,7 +348,7 @@ export default function TrainingFrameworkProgramEditPage() {
|
||||
await api.updateTrainingFrameworkProgram(fid, payload)
|
||||
const refreshed = await api.getTrainingFrameworkProgram(fid)
|
||||
let next = serverFrameworkToForm(refreshed)
|
||||
next = { ...next, slots: await enrichSlotExercisesWithVariants(next.slots) }
|
||||
next = { ...next, slots: await enrichFrameworkSlotSections(next.slots) }
|
||||
setForm(next)
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -487,44 +370,6 @@ export default function TrainingFrameworkProgramEditPage() {
|
||||
}
|
||||
}
|
||||
|
||||
const insertExerciseBefore = (fromS, fromE, toS, toE) => {
|
||||
setForm((prev) => {
|
||||
const slots = prev.slots.map((s) => ({ ...s, exercises: [...(s.exercises || [])] }))
|
||||
if (fromS < 0 || fromS >= slots.length || toS < 0 || toS >= slots.length) return prev
|
||||
const fromList = slots[fromS].exercises
|
||||
if (fromE < 0 || fromE >= fromList.length) return prev
|
||||
const [moved] = fromList.splice(fromE, 1)
|
||||
let insertAt = toE
|
||||
if (fromS === toS && fromE < toE) insertAt -= 1
|
||||
insertAt = Math.max(0, Math.min(insertAt, slots[toS].exercises.length))
|
||||
slots[toS].exercises.splice(insertAt, 0, moved)
|
||||
return { ...prev, slots }
|
||||
})
|
||||
}
|
||||
|
||||
const appendExerciseToSlot = (fromS, fromE, toS) => {
|
||||
setForm((prev) => {
|
||||
const slots = prev.slots.map((s) => ({ ...s, exercises: [...(s.exercises || [])] }))
|
||||
if (fromS < 0 || fromS >= slots.length || toS < 0 || toS >= slots.length) return prev
|
||||
const fromList = slots[fromS].exercises
|
||||
if (fromE < 0 || fromE >= fromList.length) return prev
|
||||
const [moved] = fromList.splice(fromE, 1)
|
||||
slots[toS].exercises.push(moved)
|
||||
return { ...prev, slots }
|
||||
})
|
||||
}
|
||||
|
||||
const onExerciseDragStart = (e, fromS, fromE) => {
|
||||
e.dataTransfer.effectAllowed = 'move'
|
||||
e.dataTransfer.setData(DND_FW_EX, JSON.stringify({ fromS, fromE }))
|
||||
setExerciseMenu(null)
|
||||
}
|
||||
|
||||
const onExerciseDragOver = (e) => {
|
||||
e.preventDefault()
|
||||
e.dataTransfer.dropEffect = 'move'
|
||||
}
|
||||
|
||||
const onSlotDragStart = (e, slotIdx) => {
|
||||
e.stopPropagation()
|
||||
e.dataTransfer.effectAllowed = 'move'
|
||||
@@ -539,17 +384,10 @@ export default function TrainingFrameworkProgramEditPage() {
|
||||
const onSlotColumnDrop = (e, targetSi) => {
|
||||
e.preventDefault()
|
||||
const slotRaw = e.dataTransfer.getData(DND_FW_SLOT)
|
||||
if (slotRaw) {
|
||||
const { slotIdx } = JSON.parse(slotRaw)
|
||||
if (slotIdx !== targetSi) {
|
||||
setForm((prev) => ({ ...prev, slots: reorderArray([...prev.slots], slotIdx, targetSi) }))
|
||||
}
|
||||
return
|
||||
}
|
||||
const exRaw = e.dataTransfer.getData(DND_FW_EX)
|
||||
if (exRaw) {
|
||||
const { fromS, fromE } = JSON.parse(exRaw)
|
||||
appendExerciseToSlot(fromS, fromE, targetSi)
|
||||
if (!slotRaw) return
|
||||
const { slotIdx } = JSON.parse(slotRaw)
|
||||
if (slotIdx !== targetSi) {
|
||||
setForm((prev) => ({ ...prev, slots: reorderArray([...prev.slots], slotIdx, targetSi) }))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -625,11 +463,9 @@ export default function TrainingFrameworkProgramEditPage() {
|
||||
<div className="card" style={{ marginBottom: '1rem', background: 'var(--surface2)', borderStyle: 'dashed' }}>
|
||||
<p style={{ fontSize: '0.88rem', color: 'var(--text2)', lineHeight: 1.55, margin: 0 }}>
|
||||
<strong style={{ color: 'var(--text1)' }}>Rahmenprogramm (Bibliothek):</strong> Wiederverwendbare Vorlage mit
|
||||
Zielen und Session‑Slots. <strong>Zuordnung zu einer Trainingsgruppe</strong> oder zu{' '}
|
||||
<strong>konkreten Einheiten</strong> erfolgt aus der <strong>Gruppen‑Planung</strong> (Übernahme mit Link /
|
||||
Lineage) — nicht mehr direkt an diesem Datensatz. Pro Slot ist derzeit eine Übungsliste (Stückliste) hinterlegt;
|
||||
die strukturierte Einheitenplanung (Abschnitte wie in der Trainingsplanung) folgt über{' '}
|
||||
<strong>CURR‑010</strong> (Vorlagen‑Modell pro Slot).
|
||||
Zielen und Session‑Slots. <strong>Zuordnung zu Gruppe oder Kalendertermin</strong> erfolgt aus der{' '}
|
||||
<strong>Gruppen‑Planung</strong> („Übernahme“). Pro Slot planst du den Ablauf wie bei einer Trainingsseinheit:{' '}
|
||||
<strong>Abschnitte</strong>, Übungen mit Varianten und Dauer, <strong>Zwischen‑Anmerkungen</strong>.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -987,7 +823,7 @@ export default function TrainingFrameworkProgramEditPage() {
|
||||
<div className="card framework-plan-slots" style={{ marginBottom: '1.5rem' }}>
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '8px', justifyContent: 'space-between', alignItems: 'center', marginBottom: '0.75rem' }}>
|
||||
<h3 className="card-title" style={{ marginBottom: 0 }}>
|
||||
Session‑Slots & Übungen
|
||||
Session‑Slots & Ablauf
|
||||
</h3>
|
||||
<button type="button" className="btn btn-secondary framework-ctrl framework-ctrl--xs" onClick={addSlot}>
|
||||
+ Slot
|
||||
@@ -996,16 +832,15 @@ export default function TrainingFrameworkProgramEditPage() {
|
||||
|
||||
{form.slots.length === 0 ? (
|
||||
<p style={{ color: 'var(--text2)', fontSize: '0.9rem' }}>
|
||||
Noch keine Slots — mit <strong>+ Slot</strong> legst du Spalten an (z. B. „Woche 1“) und ordnest Übungen
|
||||
zu. Bei mehreren Spalten erscheint eine horizontale Scroll-Leiste.
|
||||
Noch keine Slots — mit <strong>+ Slot</strong> legst du Spalten an (z. B. „Woche 1“). In jedem Slot
|
||||
strukturierst du wie in der Trainingsplanung: Abschnitte, Übungen, Anmerkungen.
|
||||
</p>
|
||||
) : (
|
||||
<p
|
||||
className="framework-slots-hint"
|
||||
style={{ fontSize: '0.8rem', color: 'var(--text3)', marginBottom: '10px', lineHeight: 1.45 }}
|
||||
>
|
||||
Sessions nebeneinander — nach rechts scrollen bzw. wischen. Reihenfolge mit Griff (⋮⋮ / ☰)
|
||||
per Drag & Drop möglich (Browser-abhängig bei Touch); zusätzlich Pfeile und Menüs nutzbar.
|
||||
Reihenfolge der Spalten per Griff (⋮⋮) ziehen; Inhalt eines Slots wie in der Planung bearbeiten.
|
||||
</p>
|
||||
)}
|
||||
|
||||
@@ -1079,190 +914,35 @@ export default function TrainingFrameworkProgramEditPage() {
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<div className="framework-slot-card__exercises">
|
||||
<div className="framework-slot-card__exercises-head">
|
||||
<span className="framework-slot-card__exercises-title">Übungen</span>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary framework-ctrl framework-ctrl--xs"
|
||||
onClick={() => addExerciseToSlot(si)}
|
||||
>
|
||||
+ Übung
|
||||
</button>
|
||||
</div>
|
||||
{(slot.exercises || []).length === 0 ? (
|
||||
<p className="framework-slot-card__empty-hint">
|
||||
Noch keine Übung — <strong>+ Übung</strong> oder Übung mit dem Griff ☰ hierher ziehen.
|
||||
</p>
|
||||
) : null}
|
||||
{(slot.exercises || []).map((ex, ei) => (
|
||||
<div
|
||||
key={ei}
|
||||
className="framework-ex-row"
|
||||
onDragOver={onExerciseDragOver}
|
||||
onDrop={(e) => {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
const raw = e.dataTransfer.getData(DND_FW_EX)
|
||||
if (!raw) return
|
||||
const { fromS, fromE } = JSON.parse(raw)
|
||||
if (fromS === si && fromE === ei) return
|
||||
insertExerciseBefore(fromS, fromE, si, ei)
|
||||
}}
|
||||
>
|
||||
<span
|
||||
className="framework-ex-row__grip"
|
||||
draggable
|
||||
onDragStart={(e) => {
|
||||
e.stopPropagation()
|
||||
onExerciseDragStart(e, si, ei)
|
||||
}}
|
||||
aria-hidden
|
||||
>
|
||||
☰
|
||||
</span>
|
||||
<div className="framework-ex-row__body">
|
||||
<div className="framework-ex-row__title-line">
|
||||
{ex.exercise_id ? (
|
||||
<strong className="framework-ex-row__title">
|
||||
{ex.exercise_title || `Übung #${ex.exercise_id}`}
|
||||
</strong>
|
||||
) : (
|
||||
<span className="framework-ex-row__title framework-ex-row__title--muted">
|
||||
Keine Übung gewählt
|
||||
</span>
|
||||
)}
|
||||
{ex.exercise_id ? (
|
||||
<span className="framework-ex-row__id">#{ex.exercise_id}</span>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="framework-ex-row__row2">
|
||||
{ex.exercise_id && (ex.variants || []).length > 0 ? (
|
||||
<select
|
||||
className="form-input framework-ex-row__variant-select"
|
||||
value={ex.exercise_variant_id}
|
||||
onChange={(e) => exerciseField(si, ei, 'exercise_variant_id', e.target.value)}
|
||||
>
|
||||
<option value="">Variante</option>
|
||||
{(ex.variants || []).map((v) => (
|
||||
<option key={v.id} value={String(v.id)}>
|
||||
{v.variant_name || v.name || `V ${v.id}`}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
) : (
|
||||
<span className="framework-ex-row__variant-spacer" aria-hidden />
|
||||
)}
|
||||
<div className="framework-popmenu-anchor framework-ex-row__menu-anchor">
|
||||
<button
|
||||
type="button"
|
||||
className="framework-ex-row__kebab"
|
||||
aria-label="Übung-Aktionen"
|
||||
aria-haspopup="menu"
|
||||
aria-expanded={
|
||||
exerciseMenu?.slotIdx === si && exerciseMenu?.exIdx === ei ? 'true' : 'false'
|
||||
<div className="framework-slot-card__plan-editor" style={{ marginTop: '0.65rem', minHeight: '120px' }}>
|
||||
<TrainingUnitSectionsEditor
|
||||
heading={`Ablauf · Session ${si + 1}`}
|
||||
sections={slot.sections}
|
||||
showExecutionExtras={false}
|
||||
onSectionsChange={(updater) => {
|
||||
setForm((prev) => ({
|
||||
...prev,
|
||||
slots: prev.slots.map((sl, ii) =>
|
||||
ii !== si
|
||||
? sl
|
||||
: {
|
||||
...sl,
|
||||
sections: updater(
|
||||
sl.sections && sl.sections.length ? sl.sections : [defaultSection('Ablauf')]
|
||||
),
|
||||
}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
setExerciseMenu((prev) =>
|
||||
prev?.slotIdx === si && prev?.exIdx === ei
|
||||
? null
|
||||
: { slotIdx: si, exIdx: ei }
|
||||
)
|
||||
}}
|
||||
>
|
||||
⋮
|
||||
</button>
|
||||
{exerciseMenu?.slotIdx === si && exerciseMenu?.exIdx === ei ? (
|
||||
<ul className="framework-popmenu framework-popmenu--align-end" role="menu">
|
||||
<li>
|
||||
<button
|
||||
type="button"
|
||||
role="menuitem"
|
||||
className="framework-popmenu__item"
|
||||
onClick={() => {
|
||||
setPickerSlotIdx({ slotIdx: si, exerciseIdx: ei })
|
||||
setExerciseMenu(null)
|
||||
}}
|
||||
>
|
||||
Übung wählen…
|
||||
</button>
|
||||
</li>
|
||||
{ex.exercise_id ? (
|
||||
<li>
|
||||
<button
|
||||
type="button"
|
||||
role="menuitem"
|
||||
className="framework-popmenu__item"
|
||||
onClick={() => {
|
||||
setPeekId(Number(ex.exercise_id))
|
||||
setExerciseMenu(null)
|
||||
}}
|
||||
>
|
||||
Vorschau
|
||||
</button>
|
||||
</li>
|
||||
) : null}
|
||||
<li>
|
||||
<button
|
||||
type="button"
|
||||
role="menuitem"
|
||||
className="framework-popmenu__item"
|
||||
onClick={() => {
|
||||
moveExercise(si, ei, -1)
|
||||
setExerciseMenu(null)
|
||||
}}
|
||||
>
|
||||
Nach oben in diesem Slot
|
||||
</button>
|
||||
</li>
|
||||
<li>
|
||||
<button
|
||||
type="button"
|
||||
role="menuitem"
|
||||
className="framework-popmenu__item"
|
||||
onClick={() => {
|
||||
moveExercise(si, ei, 1)
|
||||
setExerciseMenu(null)
|
||||
}}
|
||||
>
|
||||
Nach unten in diesem Slot
|
||||
</button>
|
||||
</li>
|
||||
<li>
|
||||
<button
|
||||
type="button"
|
||||
role="menuitem"
|
||||
className="framework-popmenu__item framework-popmenu__item--danger"
|
||||
onClick={() => {
|
||||
removeExercise(si, ei)
|
||||
setExerciseMenu(null)
|
||||
}}
|
||||
>
|
||||
Entfernen
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
<div
|
||||
className="framework-slot-card__append-drop"
|
||||
onDragOver={onExerciseDragOver}
|
||||
onDrop={(e) => {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
const raw = e.dataTransfer.getData(DND_FW_EX)
|
||||
if (!raw) return
|
||||
const { fromS, fromE } = JSON.parse(raw)
|
||||
appendExerciseToSlot(fromS, fromE, si)
|
||||
),
|
||||
}))
|
||||
}}
|
||||
>
|
||||
Ans Ende ziehen
|
||||
</div>
|
||||
onRequestExercisePick={({ sectionIndex, itemIndex }) =>
|
||||
setSectionPickerCtx({
|
||||
slotIdx: si,
|
||||
sectionIndex,
|
||||
itemIndex,
|
||||
})
|
||||
}
|
||||
onPeekExercise={(id) => setPeekId(id)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
@@ -1288,12 +968,54 @@ export default function TrainingFrameworkProgramEditPage() {
|
||||
</div>
|
||||
|
||||
<ExercisePickerModal
|
||||
open={pickerSlotIdx != null}
|
||||
onClose={() => setPickerSlotIdx(null)}
|
||||
onSelectExercise={(exercise) => {
|
||||
if (!pickerSlotIdx) return
|
||||
setExerciseChoice(pickerSlotIdx.slotIdx, pickerSlotIdx.exerciseIdx, exercise)
|
||||
setPickerSlotIdx(null)
|
||||
open={sectionPickerCtx != null}
|
||||
onClose={() => setSectionPickerCtx(null)}
|
||||
onSelectExercise={async (exercise) => {
|
||||
if (!sectionPickerCtx) return
|
||||
const { slotIdx, sectionIndex: sIdx, itemIndex: iIdx } = sectionPickerCtx
|
||||
let variants = Array.isArray(exercise.variants) ? exercise.variants : []
|
||||
let title = exercise.title || ''
|
||||
if (!variants.length) {
|
||||
try {
|
||||
const full = await api.getExercise(exercise.id)
|
||||
variants = Array.isArray(full.variants) ? full.variants : []
|
||||
title = full.title || title
|
||||
} catch {
|
||||
variants = []
|
||||
}
|
||||
}
|
||||
setForm((prev) => ({
|
||||
...prev,
|
||||
slots: prev.slots.map((sl, ii) =>
|
||||
ii !== slotIdx
|
||||
? sl
|
||||
: {
|
||||
...sl,
|
||||
sections: (sl.sections && sl.sections.length ? sl.sections : [defaultSection('Ablauf')]).map(
|
||||
(sec, si) =>
|
||||
si !== sIdx
|
||||
? sec
|
||||
: {
|
||||
...sec,
|
||||
items: (sec.items || []).map((row, ji) =>
|
||||
ji !== iIdx
|
||||
? row
|
||||
: row.item_type !== 'exercise'
|
||||
? row
|
||||
: {
|
||||
...row,
|
||||
exercise_id: exercise.id,
|
||||
exercise_variant_id: '',
|
||||
exercise_title: title,
|
||||
variants,
|
||||
}
|
||||
),
|
||||
}
|
||||
),
|
||||
}
|
||||
),
|
||||
}))
|
||||
setSectionPickerCtx(null)
|
||||
}}
|
||||
/>
|
||||
|
||||
|
||||
Reference in new issue
Block a user