feat(training-planning): enhance training module integration and UI
Deploy Development / deploy (push) Successful in 40s
Test Suite / pytest-backend (push) Successful in 39s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 11s
Test Suite / playwright-tests (push) Successful in 56s
Deploy Development / deploy (push) Successful in 40s
Test Suite / pytest-backend (push) Successful in 39s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 11s
Test Suite / playwright-tests (push) Successful in 56s
- Introduced a new function to handle optional source training module IDs, ensuring proper validation and integration. - Updated the backend to include source training module ID and title in section items, allowing for better tracking of module origins. - Enhanced the frontend to display module bands in the Training Unit Sections Editor, improving user experience by indicating the source of exercises and notes. - Added functionality to insert training modules at specified positions within sections, providing users with more control over their training plans. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
c1243651bb
commit
e41908af73
6 files changed
+385
-83
No files matched your search
@@ -15,6 +15,8 @@ export function exerciseRow() {
|
||||
actual_duration_min: '',
|
||||
notes: '',
|
||||
modifications: '',
|
||||
source_training_module_id: '',
|
||||
source_module_title: '',
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +71,14 @@ export async function hydrateExercisePlanningRow(exercise) {
|
||||
}
|
||||
|
||||
export function noteRow() {
|
||||
return { item_type: 'note', note_body: '' }
|
||||
return { item_type: 'note', note_body: '', source_training_module_id: '', source_module_title: '' }
|
||||
}
|
||||
|
||||
/** Zur Serialisierung in die Planungs-API (persistente Modul-Herkunft). */
|
||||
function parseOptionalSourceTrainingModuleIdForPayload(v) {
|
||||
if (v === null || v === undefined || v === '') return null
|
||||
const n = typeof v === 'number' ? v : parseInt(String(v).trim(), 10)
|
||||
return Number.isFinite(n) && n >= 1 ? n : null
|
||||
}
|
||||
|
||||
export function normalizeUnitToForm(fullUnit) {
|
||||
@@ -79,8 +88,24 @@ export function normalizeUnitToForm(fullUnit) {
|
||||
guidance_notes: sec.guidance_notes || '',
|
||||
items: (sec.items || []).map((it) => {
|
||||
if (it.item_type === 'note') {
|
||||
return { item_type: 'note', note_body: it.note_body || '' }
|
||||
const sm = parseOptionalSourceTrainingModuleIdForPayload(it.source_training_module_id)
|
||||
const rowNote = {
|
||||
item_type: 'note',
|
||||
note_body: it.note_body || '',
|
||||
source_training_module_id: '',
|
||||
source_module_title: '',
|
||||
}
|
||||
if (sm != null) {
|
||||
rowNote.source_training_module_id = sm
|
||||
rowNote.source_module_title = (
|
||||
it.source_module_title ||
|
||||
it.source_training_module_title ||
|
||||
''
|
||||
).trim()
|
||||
}
|
||||
return rowNote
|
||||
}
|
||||
const smEx = parseOptionalSourceTrainingModuleIdForPayload(it.source_training_module_id)
|
||||
return {
|
||||
item_type: 'exercise',
|
||||
exercise_id: it.exercise_id,
|
||||
@@ -97,6 +122,16 @@ export function normalizeUnitToForm(fullUnit) {
|
||||
: '',
|
||||
notes: it.notes ?? '',
|
||||
modifications: it.modifications ?? '',
|
||||
...(smEx != null
|
||||
? {
|
||||
source_training_module_id: smEx,
|
||||
source_module_title: (
|
||||
it.source_module_title ||
|
||||
it.source_training_module_title ||
|
||||
''
|
||||
).trim(),
|
||||
}
|
||||
: {}),
|
||||
}
|
||||
}),
|
||||
}))
|
||||
@@ -199,17 +234,21 @@ export function buildSectionsPayload(sections) {
|
||||
items: (sec.items || [])
|
||||
.map((it, ii) => {
|
||||
if (it.item_type === 'note') {
|
||||
return {
|
||||
const sm = parseOptionalSourceTrainingModuleIdForPayload(it.source_training_module_id)
|
||||
const row = {
|
||||
item_type: 'note',
|
||||
order_index: ii,
|
||||
note_body: it.note_body ?? '',
|
||||
}
|
||||
if (sm != null) row.source_training_module_id = sm
|
||||
return row
|
||||
}
|
||||
if (it.exercise_id === '' || it.exercise_id == null || Number.isNaN(Number(it.exercise_id))) {
|
||||
return null
|
||||
}
|
||||
const vid = it.exercise_variant_id
|
||||
return {
|
||||
const smEx = parseOptionalSourceTrainingModuleIdForPayload(it.source_training_module_id)
|
||||
const rowEx = {
|
||||
item_type: 'exercise',
|
||||
order_index: ii,
|
||||
exercise_id: parseInt(it.exercise_id, 10),
|
||||
@@ -220,11 +259,80 @@ export function buildSectionsPayload(sections) {
|
||||
notes: it.notes?.trim() ? it.notes.trim() : null,
|
||||
modifications: it.modifications?.trim() ? it.modifications.trim() : null,
|
||||
}
|
||||
if (smEx != null) rowEx.source_training_module_id = smEx
|
||||
return rowEx
|
||||
})
|
||||
.filter(Boolean),
|
||||
}))
|
||||
}
|
||||
|
||||
/** Fügt die Positionen eines Moduls in lokale Abschnitte ein (wie eine Übung, ohne Zwischenspeichern der Einheit). */
|
||||
export async function insertTrainingModuleIntoPlanningSections({
|
||||
sections,
|
||||
moduleDetail,
|
||||
sectionIndex,
|
||||
insertBeforeItemIndex,
|
||||
}) {
|
||||
const secIx = typeof sectionIndex === 'number' ? sectionIndex : parseInt(String(sectionIndex), 10)
|
||||
if (
|
||||
!Array.isArray(sections) ||
|
||||
!Number.isFinite(secIx) ||
|
||||
secIx < 0 ||
|
||||
secIx >= sections.length ||
|
||||
!moduleDetail ||
|
||||
typeof moduleDetail !== 'object'
|
||||
) {
|
||||
return sections
|
||||
}
|
||||
const prev = [...(sections[secIx].items || [])]
|
||||
let beforeIx
|
||||
if (insertBeforeItemIndex === null || insertBeforeItemIndex === undefined || insertBeforeItemIndex === 'end') {
|
||||
beforeIx = prev.length
|
||||
} else if (insertBeforeItemIndex === 'start') {
|
||||
beforeIx = 0
|
||||
} else {
|
||||
const n = typeof insertBeforeItemIndex === 'number' ? insertBeforeItemIndex : parseInt(String(insertBeforeItemIndex), 10)
|
||||
beforeIx = Number.isFinite(n) ? Math.min(Math.max(n, 0), prev.length) : prev.length
|
||||
}
|
||||
|
||||
const midRaw = moduleDetail.id
|
||||
const midNum = typeof midRaw === 'number' ? midRaw : parseInt(String(midRaw), 10)
|
||||
if (!Number.isFinite(midNum) || midNum < 1) return sections
|
||||
|
||||
const modTitle = (moduleDetail.title || '').trim() || `Modul #${midNum}`
|
||||
const modItems = [...(moduleDetail.items || [])].sort(
|
||||
(a, b) => (a.order_index ?? 0) - (b.order_index ?? 0)
|
||||
)
|
||||
|
||||
const appendRows = []
|
||||
for (const mi of modItems) {
|
||||
if (mi.item_type === 'note') {
|
||||
appendRows.push({
|
||||
item_type: 'note',
|
||||
note_body: mi.note_body || '',
|
||||
source_training_module_id: midNum,
|
||||
source_module_title: modTitle,
|
||||
})
|
||||
continue
|
||||
}
|
||||
if (!mi.exercise_id) continue
|
||||
const hydrated = await hydrateExercisePlanningRow({ id: mi.exercise_id })
|
||||
if (!hydrated) continue
|
||||
hydrated.source_training_module_id = midNum
|
||||
hydrated.source_module_title = modTitle
|
||||
if (mi.exercise_variant_id) hydrated.exercise_variant_id = String(mi.exercise_variant_id)
|
||||
hydrated.planned_duration_min =
|
||||
mi.planned_duration_min !== null && mi.planned_duration_min !== undefined
|
||||
? String(mi.planned_duration_min)
|
||||
: ''
|
||||
hydrated.notes = mi.notes ?? ''
|
||||
appendRows.push(hydrated)
|
||||
}
|
||||
|
||||
const mergedItems = [...prev.slice(0, beforeIx), ...appendRows, ...prev.slice(beforeIx)]
|
||||
return sections.map((sec, idx) => (idx === secIx ? { ...sec, items: mergedItems } : sec))
|
||||
}
|
||||
|
||||
export function sectionPlannedMinutes(sec) {
|
||||
return (sec.items || []).reduce((sum, it) => {
|
||||
if (it.item_type !== 'exercise') return sum
|
||||
|
||||
Reference in new issue
Block a user