feat(layouts): switch track layout mid-practice and view stats per layout
A club can run one Open Practice all season and re-lay the track now and then. Previously a session's layout was frozen at start and every training lap inherited it, so a season-long practice stayed on its first layout forever, and changing layout was hidden under Settings -> Appearance. - Each practice lap now counts toward the layout active when it was driven; a running practice session moves onto a new layout when one is added - "New layout" strip on Training stats, Race Day and the Dashboard, offered only around practice; a running race session blocks layout changes everywhere - "Stats for" selector (current / older layout / before layouts / all layouts) on Training stats and in the driver's mobile profile (?layout= on the public API) - A layout that has practice laps on it can no longer be deleted - Fix: the buildDriverTrainingStats wrapper in app.js dropped extra arguments Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
196437d25b
commit
627179b95a
22 files changed
+454
-44
No files matched your search
+47
-6
@@ -1,5 +1,39 @@
|
||||
import { sortValuesAttribute } from "./list_sorting.js";
|
||||
import { getDriverProfileGroups, getDriverProfileReferences } from "./driver_profile_logic.js";
|
||||
import { normalizeTrackLayouts } from "./track_layouts_logic.js";
|
||||
import { renderTrackLayoutBar, bindTrackLayoutBar } from "./track_layout_bar.js";
|
||||
|
||||
// Which track layout the pace/record/consistency numbers are for: "current" (default),
|
||||
// "all" (overall), "none" (laps from before any layout existed), or a layout id. Module
|
||||
// state like the tab selections, so it survives re-renders while the page is open.
|
||||
let selectedTrainingLayout = "current";
|
||||
|
||||
function trainingLayoutSelectMarkup(state, t, escapeHtml) {
|
||||
const layouts = normalizeTrackLayouts(state.trackLayouts);
|
||||
if (!layouts.length) return "";
|
||||
const known = new Set(["current", "all", "none", ...layouts.map((layout) => layout.id)]);
|
||||
if (!known.has(selectedTrainingLayout)) selectedTrainingLayout = "current";
|
||||
const hasUntaggedLaps = (state.training?.ledger || []).some((lap) => !lap.trackLayoutId);
|
||||
const option = (value, label) => `<option value="${escapeHtml(value)}" ${selectedTrainingLayout === value ? "selected" : ""}>${escapeHtml(label)}</option>`;
|
||||
return `
|
||||
<label class="training-driver-select">
|
||||
<span>${escapeHtml(t("layouts.stats_for"))}</span>
|
||||
<select id="training-layout">
|
||||
${option("current", t("layouts.option_current"))}
|
||||
${layouts.slice().reverse().map((layout) => option(layout.id, layout.label)).join("")}
|
||||
${hasUntaggedLaps ? option("none", t("layouts.option_none")) : ""}
|
||||
${option("all", t("layouts.option_all"))}
|
||||
</select>
|
||||
</label>`;
|
||||
}
|
||||
|
||||
function bindTrainingLayoutControls({ state, t, addTrackLayout, renderView }) {
|
||||
document.getElementById("training-layout")?.addEventListener("change", (event) => {
|
||||
selectedTrainingLayout = event.target.value;
|
||||
renderView();
|
||||
});
|
||||
bindTrackLayoutBar(document.getElementById("view"), { state, t, addTrackLayout, renderView });
|
||||
}
|
||||
|
||||
const EXERCISE_KIND_EMOJI = { timer: "⏱️", evenLaps: "🎯", stepTraining: "🪜" };
|
||||
|
||||
@@ -36,6 +70,7 @@ export function renderTrainingView(deps) {
|
||||
const goalsSharingWasOpen = goalsSharingElement ? goalsSharingElement.open : true;
|
||||
const exerciseHistoryWasOpen = Boolean(document.getElementById("trainingExerciseHistory")?.open);
|
||||
const {
|
||||
addTrackLayout,
|
||||
state,
|
||||
dom,
|
||||
t,
|
||||
@@ -97,7 +132,7 @@ export function renderTrainingView(deps) {
|
||||
}
|
||||
|
||||
if (!selectedProfileId || !selectedProfile) {
|
||||
renderTrainingOverview({ state, dom, t, escapeHtml, formatLap, uid, saveState, profiles, buildDriverTrainingStats, getNextTrainingMilestone, getClubTrainingGoalProgress, countExerciseSessions, setSelectedDriverId, setSelectedClassId, renderView });
|
||||
renderTrainingOverview({ addTrackLayout, state, dom, t, escapeHtml, formatLap, uid, saveState, profiles, buildDriverTrainingStats, getNextTrainingMilestone, getClubTrainingGoalProgress, countExerciseSessions, setSelectedDriverId, setSelectedClassId, renderView });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -109,7 +144,7 @@ export function renderTrainingView(deps) {
|
||||
const selectedDriver = selectedProfile.representative;
|
||||
const selectedClassDriver = selectedProfile.drivers.find((driver) => String(driver.classId || "") === selectedClassId) || selectedDriver;
|
||||
const profileReferences = getDriverProfileReferences(state, selectedProfileId);
|
||||
const stats = buildDriverTrainingStats(state, selectedProfileId, selectedClassId);
|
||||
const stats = buildDriverTrainingStats(state, selectedProfileId, selectedClassId, { layout: selectedTrainingLayout });
|
||||
const channelStats = buildDriverTimingChannelStats(state, selectedProfileId, selectedClassId);
|
||||
const activePractice = buildDriverActivePracticeStats(state, selectedProfileId, Date.now(), selectedClassId);
|
||||
const evenLapsConfig = (state.training.evenLaps || []).find((entry) => entry.driverId === selectedClassDriver.id && entry.classId === selectedClassId) || null;
|
||||
@@ -134,7 +169,7 @@ export function renderTrainingView(deps) {
|
||||
const highlights = buildTrainingHighlights({ ...stats, latestSplitGainMs: channelStats.latestSplitGainMs });
|
||||
const paceBuckets = buildTrainingPaceBuckets(state, selectedProfileId, selectedClassId, 30).slice(-24);
|
||||
const weekdayStats = buildTrainingWeekdayStats(state, selectedProfileId, selectedClassId);
|
||||
const stintAnalysis = buildTrainingStintAnalysis(state, selectedProfileId, selectedClassId);
|
||||
const stintAnalysis = buildTrainingStintAnalysis(state, selectedProfileId, selectedClassId, { layout: selectedTrainingLayout });
|
||||
const markerComparisons = buildTrainingMarkerComparisons(state, selectedProfileId, selectedClassId, 30).slice().reverse();
|
||||
const goals = state.training.goals.filter((goal) => (
|
||||
profileReferences.has(String(goal.driverId || ""))
|
||||
@@ -282,7 +317,7 @@ export function renderTrainingView(deps) {
|
||||
: t("training.trend_stable");
|
||||
const clubRows = profiles
|
||||
.filter((profile) => !selectedClassId || profile.classIds.includes(selectedClassId))
|
||||
.map((profile) => ({ profile, driver: profile.representative, stats: profile.id === selectedProfileId ? stats : buildDriverTrainingStats(state, profile.id, selectedClassId) }))
|
||||
.map((profile) => ({ profile, driver: profile.representative, stats: profile.id === selectedProfileId ? stats : buildDriverTrainingStats(state, profile.id, selectedClassId, { layout: selectedTrainingLayout }) }))
|
||||
.sort((left, right) => right.stats.lastLapAt - left.stats.lastLapAt || String(left.driver?.name || "").localeCompare(String(right.driver?.name || "")))
|
||||
.map((entry) => {
|
||||
const milestone = getNextTrainingMilestone(entry.stats);
|
||||
@@ -368,6 +403,8 @@ export function renderTrainingView(deps) {
|
||||
<span>${escapeHtml(t("training.class"))}</span>
|
||||
<select id="training-class">${classOptions}</select>
|
||||
</label>
|
||||
${trainingLayoutSelectMarkup(state, t, escapeHtml)}
|
||||
${renderTrackLayoutBar({ state, t, escapeHtml })}
|
||||
<div class="actions training-hero-actions">
|
||||
<button class="btn" id="trainingBackOverview" type="button">${escapeHtml(t("training.back_overview"))}</button>
|
||||
${profileShare ? `
|
||||
@@ -863,6 +900,7 @@ export function renderTrainingView(deps) {
|
||||
setSelectedClassId("");
|
||||
renderView();
|
||||
});
|
||||
bindTrainingLayoutControls({ state, t, addTrackLayout, renderView });
|
||||
document.getElementById("training-class")?.addEventListener("change", (event) => {
|
||||
setSelectedClassId(event.currentTarget.value);
|
||||
renderView();
|
||||
@@ -1022,7 +1060,7 @@ export function buildTrainingOverviewRows(state, profiles, buildDriverTrainingSt
|
||||
driver: profile.representative,
|
||||
classId,
|
||||
className: state.classes.find((item) => String(item.id || "") === String(classId || ""))?.name || classId || "-",
|
||||
stats: buildDriverTrainingStats(state, profile.id, classId),
|
||||
stats: buildDriverTrainingStats(state, profile.id, classId, { layout: selectedTrainingLayout }),
|
||||
}));
|
||||
}).sort((left, right) => (
|
||||
right.stats.lastLapAt - left.stats.lastLapAt
|
||||
@@ -1046,7 +1084,7 @@ export function buildTrainingProgressFeed(rows, limit = 6) {
|
||||
});
|
||||
}
|
||||
|
||||
function renderTrainingOverview({ state, dom, t, escapeHtml, formatLap, uid, saveState, profiles, buildDriverTrainingStats, getNextTrainingMilestone, getClubTrainingGoalProgress, countExerciseSessions, setSelectedDriverId, setSelectedClassId, renderView }) {
|
||||
function renderTrainingOverview({ addTrackLayout, state, dom, t, escapeHtml, formatLap, uid, saveState, profiles, buildDriverTrainingStats, getNextTrainingMilestone, getClubTrainingGoalProgress, countExerciseSessions, setSelectedDriverId, setSelectedClassId, renderView }) {
|
||||
const rows = buildTrainingOverviewRows(state, profiles, buildDriverTrainingStats);
|
||||
const progressFeed = buildTrainingProgressFeed(rows);
|
||||
const ledger = Array.isArray(state.training?.ledger) ? state.training.ledger : [];
|
||||
@@ -1130,6 +1168,8 @@ function renderTrainingOverview({ state, dom, t, escapeHtml, formatLap, uid, sav
|
||||
${driverOptions}
|
||||
</select>
|
||||
</label>
|
||||
${trainingLayoutSelectMarkup(state, t, escapeHtml)}
|
||||
${renderTrackLayoutBar({ state, t, escapeHtml })}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -1185,6 +1225,7 @@ function renderTrainingOverview({ state, dom, t, escapeHtml, formatLap, uid, sav
|
||||
</section>
|
||||
`;
|
||||
|
||||
bindTrainingLayoutControls({ state, t, addTrackLayout, renderView });
|
||||
document.getElementById("training-overview-driver")?.addEventListener("change", (event) => {
|
||||
if (!event.currentTarget.value) return;
|
||||
setSelectedDriverId(event.currentTarget.value);
|
||||
|
||||
Reference in new issue
Block a user