Refactor TrainingCoachPage and TrainingUnitRunPage to enhance coach branching functionality
Deploy Development / deploy (push) Successful in 39s
Test Suite / pytest-backend (push) Successful in 37s
Test Suite / lint-backend (push) Successful in 1s
Test Suite / build-frontend (push) Successful in 12s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m8s
Deploy Development / deploy (push) Successful in 39s
Test Suite / pytest-backend (push) Successful in 37s
Test Suite / lint-backend (push) Successful in 1s
Test Suite / build-frontend (push) Successful in 12s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m8s
- Updated TrainingCoachPage to implement branching logic for coach steps, allowing for improved navigation through training phases. - Enhanced session storage handling to manage branch picks and streamline state management during training sessions. - Modified TrainingUnitRunPage to update links for coaching views, reflecting the new branching structure and improving user experience. - Introduced new utility functions in trainingPlanUtils for managing coach branch picks and timeline navigation, optimizing data handling across components.
This commit is contained in:
1 parent
4cf7133bce
commit
352237bbb9
3 files changed
+459
-82
No files matched your search
@@ -208,16 +208,141 @@ function coachContextLabelForSection(sec, sectionsList) {
|
||||
return `Parallel · ${pt} · ${st}`
|
||||
}
|
||||
|
||||
/** Flache Reihenfolge für Coach-Timeline.
|
||||
* @param {object|null} coachFocus `{ phaseOrder, streamOrder }` = nur dieser Stream in dieser parallelen Phase; andere Split-Phasen weiterhin voll (alle Streams verschränkt). Null = Gesamtplan.*/
|
||||
export function flattenPlanTimeline(unit, coachFocus = null) {
|
||||
export const COACH_ENTRY_BRANCH_GATE = 'branch_gate'
|
||||
|
||||
/** Normalisierte Stream-Wahl pro paralleler Phase (Phase-Index → Stream-Order). */
|
||||
export function normalizeCoachBranchPicks(raw) {
|
||||
const out = {}
|
||||
if (!raw || typeof raw !== 'object') return out
|
||||
for (const [k, v] of Object.entries(raw)) {
|
||||
const pk = parseInt(String(k), 10)
|
||||
const sv = typeof v === 'number' ? v : parseInt(String(v), 10)
|
||||
if (Number.isFinite(pk) && Number.isFinite(sv)) out[pk] = sv
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/**
|
||||
* URL-/Dropdown-Fokus `coachFocus` in Pick-Map mergen (fest gewählter Stream für eine Phase).
|
||||
* @param {object} branchPicks Roh-Picks (z. B. aus Session)
|
||||
* @param {{ phaseOrder: number, streamOrder: number }|null} coachFocusUrl z. B. ?po=&so=
|
||||
*/
|
||||
export function mergeCoachBranchPicksWithUrlFocus(branchPicks, coachFocusUrl) {
|
||||
const m = normalizeCoachBranchPicks(branchPicks)
|
||||
if (
|
||||
coachFocusUrl != null &&
|
||||
Number.isFinite(coachFocusUrl.phaseOrder) &&
|
||||
Number.isFinite(coachFocusUrl.streamOrder)
|
||||
) {
|
||||
m[coachFocusUrl.phaseOrder] = coachFocusUrl.streamOrder
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
/** Kurzstring für SessionStorage-Schlüssel (Sortierung stabil). */
|
||||
export function coachBranchPicksStepStorageSuffix(mergedPicks) {
|
||||
const keys = Object.keys(mergedPicks)
|
||||
.map((k) => parseInt(String(k), 10))
|
||||
.filter((n) => Number.isFinite(n))
|
||||
.sort((a, b) => a - b)
|
||||
if (!keys.length) return 'full'
|
||||
return keys.map((k) => `p${k}-s${mergedPicks[k]}`).join('_')
|
||||
}
|
||||
|
||||
export function coachBranchPicksStorageKey(unitId) {
|
||||
return `sj_coach_branches_${unitId}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Index zum Springen: Co-Trainer-Link atBranch+preferSo — Gate falls noch offen, sonst erste Kachel im Stream.
|
||||
*/
|
||||
export function findCoachTimelineJumpIndexForPhase(timeline, phaseOrder, preferStreamOrder = null) {
|
||||
const po = Number(phaseOrder)
|
||||
if (!Number.isFinite(po) || !Array.isArray(timeline)) return -1
|
||||
const hint = preferStreamOrder != null && Number.isFinite(Number(preferStreamOrder)) ? Number(preferStreamOrder) : null
|
||||
if (hint != null) {
|
||||
const ixStream = timeline.findIndex(
|
||||
(e) =>
|
||||
e.entryKind !== COACH_ENTRY_BRANCH_GATE &&
|
||||
e.runMeta?.kind === 'parallel' &&
|
||||
e.runMeta.phaseOrderIndex === po &&
|
||||
e.runMeta.streamOrder === hint
|
||||
)
|
||||
if (ixStream >= 0) return ixStream
|
||||
}
|
||||
const ixGate = timeline.findIndex(
|
||||
(e) => e.entryKind === COACH_ENTRY_BRANCH_GATE && e.branchMeta?.phaseOrderIndex === po
|
||||
)
|
||||
return ixGate
|
||||
}
|
||||
|
||||
/** Gruppiert die flache Coach-Timeline für den Trainingsrahmen (Überschriften + Einträge). */
|
||||
export function coachOutlineGroupsFromTimeline(timeline) {
|
||||
const groups = []
|
||||
for (let ix = 0; ix < timeline.length; ix++) {
|
||||
const ent = timeline[ix]
|
||||
let mergeKey = `ix-${ix}`
|
||||
let heading = 'Ablauf'
|
||||
let sub = ''
|
||||
if (ent.entryKind === COACH_ENTRY_BRANCH_GATE) {
|
||||
const po = ent.branchMeta?.phaseOrderIndex ?? 0
|
||||
mergeKey = `gate-${po}`
|
||||
heading = 'Split · Gruppe wählen'
|
||||
const pt = ent.branchMeta?.phaseTitle
|
||||
sub =
|
||||
pt != null && String(pt).trim()
|
||||
? String(pt).trim()
|
||||
: `Parallele Phase ${po}`
|
||||
} else {
|
||||
const rm = ent.runMeta
|
||||
if (rm?.kind === 'whole_group') {
|
||||
mergeKey = `wg-${rm.phaseOrderIndex}`
|
||||
const pl = ent.sec?.planLoc
|
||||
const ptt = pl?.phaseTitle
|
||||
heading = 'Ganzgruppe'
|
||||
sub = ptt != null && String(ptt).trim() ? String(ptt).trim() : ''
|
||||
} else if (rm?.kind === 'parallel' && rm.streamOrder != null) {
|
||||
mergeKey = `par-${rm.phaseOrderIndex}-s${rm.streamOrder}`
|
||||
const pl = ent.sec?.planLoc
|
||||
const ptt = pl?.phaseTitle
|
||||
const stt = pl?.streamTitle
|
||||
const ptl = ptt != null && String(ptt).trim() ? String(ptt).trim() : `Phase ${rm.phaseOrderIndex}`
|
||||
const stl = stt != null && String(stt).trim() ? String(stt).trim() : `Gruppe ${rm.streamOrder + 1}`
|
||||
heading = `Parallel · ${ptl}`
|
||||
sub = stl
|
||||
} else if (rm?.kind === 'legacy') {
|
||||
mergeKey = 'legacy'
|
||||
heading = 'Ablauf'
|
||||
sub = ''
|
||||
} else {
|
||||
mergeKey = `misc-${ix}`
|
||||
}
|
||||
}
|
||||
const prev = groups[groups.length - 1]
|
||||
if (!prev || prev.mergeKey !== mergeKey) {
|
||||
groups.push({ mergeKey, heading, sub, entries: [{ ix, ent }] })
|
||||
} else {
|
||||
prev.entries.push({ ix, ent })
|
||||
}
|
||||
}
|
||||
return groups
|
||||
}
|
||||
|
||||
/**
|
||||
* Flache Coach-Reihenfolge. Pro paralleler Phase ohne Eintrag in branchPicks: ein sichtbarer branch_gate,
|
||||
* damit keine verschränkten Split-Übungen, bis eine Gruppe gewählt wurde.
|
||||
* @param {object} unit
|
||||
* @param {object} branchPicks z. B. { 0: 1 } = Phase 0 → Stream 1
|
||||
*/
|
||||
export function flattenPlanTimeline(unit, branchPicks = {}) {
|
||||
const sections = sectionsWithPlanLocForDisplay(unit)
|
||||
const model = buildPlanRunViewModelFromSections(sections)
|
||||
if (model.mode === 'empty') return []
|
||||
|
||||
const picks = normalizeCoachBranchPicks(branchPicks)
|
||||
const list = []
|
||||
|
||||
const pushSectionItems = (sec, coachCtx) => {
|
||||
const pushSectionItems = (sec, coachCtx, runMeta) => {
|
||||
const si = Math.max(0, sections.indexOf(sec))
|
||||
const secOrder = sec.order_index ?? si
|
||||
sortedItems(sec).forEach((item, ii) => {
|
||||
@@ -229,28 +354,53 @@ export function flattenPlanTimeline(unit, coachFocus = null) {
|
||||
sec,
|
||||
item,
|
||||
coachContext: coachCtx,
|
||||
runMeta: runMeta || null,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const f = coachFocus
|
||||
for (const run of model.runs) {
|
||||
if (run.kind === 'legacy' || run.kind === 'whole_group') {
|
||||
if (run.kind === 'legacy') {
|
||||
const meta = { kind: 'legacy', phaseOrderIndex: 0, streamOrder: null }
|
||||
for (const sec of run.globalOrderSections) {
|
||||
pushSectionItems(sec, coachContextLabelForSection(sec, sections))
|
||||
pushSectionItems(sec, coachContextLabelForSection(sec, sections), meta)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if (run.kind === 'whole_group') {
|
||||
const meta = { kind: 'whole_group', phaseOrderIndex: run.phaseOrderIndex, streamOrder: null }
|
||||
for (const sec of run.globalOrderSections) {
|
||||
pushSectionItems(sec, coachContextLabelForSection(sec, sections), meta)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if (run.kind === 'parallel') {
|
||||
if (f == null || run.phaseOrderIndex !== f.phaseOrder) {
|
||||
for (const sec of run.globalOrderSections) {
|
||||
pushSectionItems(sec, coachContextLabelForSection(sec, sections))
|
||||
}
|
||||
const po = run.phaseOrderIndex
|
||||
const chosen = picks[po]
|
||||
const hasPick = chosen !== undefined && chosen !== null && Number.isFinite(Number(chosen))
|
||||
if (!hasPick) {
|
||||
list.push({
|
||||
entryKind: COACH_ENTRY_BRANCH_GATE,
|
||||
si: -1,
|
||||
ii: -1,
|
||||
secOrder: -1,
|
||||
flatIndex: list.length,
|
||||
sec: null,
|
||||
item: null,
|
||||
coachContext: '',
|
||||
branchMeta: {
|
||||
phaseOrderIndex: po,
|
||||
phaseTitle: run.phaseTitle,
|
||||
streams: run.streams || [],
|
||||
},
|
||||
runMeta: { kind: 'parallel', phaseOrderIndex: po, streamOrder: null },
|
||||
})
|
||||
} else {
|
||||
const st = run.streams?.find((x) => x.streamOrder === f.streamOrder)
|
||||
const st = run.streams?.find((x) => x.streamOrder === Number(chosen))
|
||||
const meta = { kind: 'parallel', phaseOrderIndex: po, streamOrder: Number(chosen) }
|
||||
if (st?.sections?.length) {
|
||||
for (const sec of st.sections) {
|
||||
pushSectionItems(sec, coachContextLabelForSection(sec, sections))
|
||||
pushSectionItems(sec, coachContextLabelForSection(sec, sections), meta)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -305,7 +455,15 @@ export function durationOverridesMapFromDeltas(unit, deltas) {
|
||||
return out
|
||||
}
|
||||
|
||||
export function summarizeTimelineEntry({ item }) {
|
||||
export function summarizeTimelineEntry(ent) {
|
||||
if (!ent) return ''
|
||||
if (ent.entryKind === COACH_ENTRY_BRANCH_GATE) {
|
||||
const t = ent.branchMeta?.phaseTitle != null && String(ent.branchMeta.phaseTitle).trim()
|
||||
? String(ent.branchMeta.phaseTitle).trim()
|
||||
: ''
|
||||
return t ? `Split wählen · ${t}` : 'Split · Gruppe wählen'
|
||||
}
|
||||
const { item } = ent
|
||||
if (!item) return ''
|
||||
if (item.item_type === 'note') {
|
||||
const t = String(item.note_body || '').trim()
|
||||
|
||||
Reference in new issue
Block a user