feat(training-planning): enhance planning method profile handling and UI updates
Deploy Development / deploy (push) Successful in 38s
Test Suite / pytest-backend (push) Successful in 35s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 11s
Test Suite / playwright-tests (push) Successful in 59s
Deploy Development / deploy (push) Successful in 38s
Test Suite / pytest-backend (push) Successful in 35s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 11s
Test Suite / playwright-tests (push) Successful in 59s
- Integrated PsycopgJson for improved handling of planning method profiles in the backend. - Updated CombinationPlanBracket to display primary load labels for better clarity in the UI. - Enhanced TrainingUnitSectionsEditor and utility functions to ensure proper serialization of planning profiles, preventing potential errors during API interactions. - Improved CSS for combo plan brackets to enhance visual alignment and presentation. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
d3ddc52118
commit
3898e8bc2c
8 files changed
+146
-24
No files matched your search
@@ -322,6 +322,27 @@ export function summarizeSlotProfileBrief(r) {
|
||||
return bits.join(' · ')
|
||||
}
|
||||
|
||||
/**
|
||||
* Kompakte Stations-Belastung für die Plan-Klammer (links): Sekunden oder Wdh., nicht Slot-ID.
|
||||
*/
|
||||
export function stationPrimaryLoadLabel(slotRow) {
|
||||
if (!slotRow || typeof slotRow !== 'object') return null
|
||||
const adv = slotRow.advance_mode || 'timed'
|
||||
if (adv === 'timed') {
|
||||
if (slotRow.load_sec != null) return `${slotRow.load_sec}s`
|
||||
return null
|
||||
}
|
||||
if (adv === 'rep') {
|
||||
if (slotRow.consecutive_reps != null) return `${slotRow.consecutive_reps}×`
|
||||
return null
|
||||
}
|
||||
if (adv === 'manual') {
|
||||
if (slotRow.consecutive_reps != null) return `~${slotRow.consecutive_reps}×`
|
||||
return null
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
function globalTimingHintsForArchetype(arch, mp) {
|
||||
if (!mp || typeof mp !== 'object' || Array.isArray(mp)) return []
|
||||
const bits = []
|
||||
|
||||
@@ -1,5 +1,28 @@
|
||||
/** Effektives Ablaufprofil für Kombination im Coach/in der Planung */
|
||||
|
||||
/** Top-Level: null/undefined aus Planungs-Snapshot löschen keine Katalog-Felder (API liefert oft JSON-null). */
|
||||
function omitNullUndefinedTop(planObj) {
|
||||
const out = {}
|
||||
for (const [k, v] of Object.entries(planObj)) {
|
||||
if (v === null || v === undefined) continue
|
||||
out[k] = v
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/** Je Slot-Zeile: null/undefined aus Planung überschreiben keine Katalog-Werte (z. B. consecutive_reps). */
|
||||
function mergeSlotProfileFields(prev, patch) {
|
||||
const base = prev && typeof prev === 'object' ? { ...prev } : {}
|
||||
if (!patch || typeof patch !== 'object') return base
|
||||
for (const [k, v] of Object.entries(patch)) {
|
||||
if (v === null || v === undefined) continue
|
||||
base[k] = v
|
||||
}
|
||||
const ix = Number(base.slot_index)
|
||||
if (Number.isFinite(ix)) base.slot_index = ix
|
||||
return base
|
||||
}
|
||||
|
||||
/**
|
||||
* Vereinigt slot_profiles_v1 aus Katalog und Planungs-Overlay (je slot_index).
|
||||
* @param {unknown} catArr
|
||||
@@ -20,7 +43,7 @@ function mergeSlotProfilesV1(catArr, planArr) {
|
||||
const ix = Number(r.slot_index)
|
||||
if (!Number.isFinite(ix)) continue
|
||||
const prev = byIx.get(ix) || {}
|
||||
byIx.set(ix, { ...prev, ...r })
|
||||
byIx.set(ix, mergeSlotProfileFields(prev, r))
|
||||
}
|
||||
return [...byIx.entries()].sort((a, b) => a[0] - b[0]).map(([, row]) => row)
|
||||
}
|
||||
@@ -34,20 +57,30 @@ export function effectiveComboMethodProfile(catalogDict, planningSnapshot) {
|
||||
const cat =
|
||||
catalogDict && typeof catalogDict === 'object' && !Array.isArray(catalogDict) ? { ...catalogDict } : {}
|
||||
|
||||
if (
|
||||
planningSnapshot === null ||
|
||||
planningSnapshot === undefined ||
|
||||
typeof planningSnapshot !== 'object' ||
|
||||
Array.isArray(planningSnapshot)
|
||||
) {
|
||||
if (planningSnapshot === null || planningSnapshot === undefined) {
|
||||
return { ...cat }
|
||||
}
|
||||
|
||||
const plan = planningSnapshot
|
||||
const merged = { ...cat, ...plan }
|
||||
if (typeof planningSnapshot === 'string') {
|
||||
const t = planningSnapshot.trim()
|
||||
if (!t || t === 'null') return { ...cat }
|
||||
try {
|
||||
const p = JSON.parse(t)
|
||||
return effectiveComboMethodProfile(catalogDict, p)
|
||||
} catch {
|
||||
return { ...cat }
|
||||
}
|
||||
}
|
||||
|
||||
if (Object.prototype.hasOwnProperty.call(plan, 'slot_profiles_v1')) {
|
||||
merged.slot_profiles_v1 = mergeSlotProfilesV1(cat.slot_profiles_v1, plan.slot_profiles_v1)
|
||||
if (typeof planningSnapshot !== 'object' || Array.isArray(planningSnapshot)) {
|
||||
return { ...cat }
|
||||
}
|
||||
|
||||
const planRaw = planningSnapshot
|
||||
const merged = { ...cat, ...omitNullUndefinedTop(planRaw) }
|
||||
|
||||
if (Object.prototype.hasOwnProperty.call(planRaw, 'slot_profiles_v1')) {
|
||||
merged.slot_profiles_v1 = mergeSlotProfilesV1(cat.slot_profiles_v1, planRaw.slot_profiles_v1)
|
||||
}
|
||||
|
||||
return merged
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
* Hilfen für Trainingsplan-Ansicht, Coach-Modus und API-Payload für PUT /training-units/:id.
|
||||
*/
|
||||
|
||||
import { cloneJsonSerializablePlanningProfile } from './trainingUnitSectionsForm'
|
||||
export function sortedSections(unit) {
|
||||
const raw = unit?.sections
|
||||
if (!Array.isArray(raw)) return []
|
||||
@@ -95,7 +96,10 @@ export function sectionsToPutPayload(unit, durationOverridesByItemId = {}) {
|
||||
if (isCombo) {
|
||||
const pmp = it.planning_method_profile
|
||||
if (pmp != null && typeof pmp === 'object' && !Array.isArray(pmp)) {
|
||||
row.planning_method_profile = { ...pmp }
|
||||
const cleaned = cloneJsonSerializablePlanningProfile(pmp)
|
||||
if (cleaned && Object.keys(cleaned).length > 0) {
|
||||
row.planning_method_profile = cleaned
|
||||
}
|
||||
}
|
||||
}
|
||||
return row
|
||||
|
||||
@@ -10,13 +10,34 @@ function normalizeCatalogMethodProfile(cp) {
|
||||
return {}
|
||||
}
|
||||
|
||||
/** NULL = Planung folgt Katalogprofil der Übung */
|
||||
/** NULL = Planung folgt Katalogprofil der Übung (Reihenfolge beibehalten: zuerst String-JSON auflösen). */
|
||||
function normalizePlanningMethodProfile(pm) {
|
||||
if (pm == null) return null
|
||||
if (typeof pm === 'string') {
|
||||
const t = pm.trim()
|
||||
if (!t || t === 'null') return null
|
||||
try {
|
||||
const p = JSON.parse(t)
|
||||
if (p && typeof p === 'object' && !Array.isArray(p)) return { ...p }
|
||||
return null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
if (typeof pm === 'object' && !Array.isArray(pm)) return { ...pm }
|
||||
return null
|
||||
}
|
||||
|
||||
/** Reines JSON für PUT /training-units (vermeidet nicht serialisierbare Werte → 500). */
|
||||
export function cloneJsonSerializablePlanningProfile(obj) {
|
||||
if (obj == null || typeof obj !== 'object' || Array.isArray(obj)) return null
|
||||
try {
|
||||
return JSON.parse(JSON.stringify(obj))
|
||||
} catch {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
export function exerciseRow() {
|
||||
return {
|
||||
item_type: 'exercise',
|
||||
@@ -414,7 +435,10 @@ export function buildSectionsPayload(sections) {
|
||||
if (isCombo) {
|
||||
const pmp = it.planning_method_profile
|
||||
if (pmp != null && typeof pmp === 'object' && !Array.isArray(pmp)) {
|
||||
rowEx.planning_method_profile = { ...pmp }
|
||||
const cleaned = cloneJsonSerializablePlanningProfile(pmp)
|
||||
if (cleaned && Object.keys(cleaned).length > 0) {
|
||||
rowEx.planning_method_profile = cleaned
|
||||
}
|
||||
}
|
||||
}
|
||||
if (smEx != null) rowEx.source_training_module_id = smEx
|
||||
|
||||
Reference in new issue
Block a user