feat(series): next-step button per round and Race Day next session (1.44.0)

This commit is contained in:
larssand committed 2026-10-31 09:03:34 +01:00
1 parent dbda06d101
commit 71aa149a4d
12 files changed
+145 -10

No files matched your search

+21 -2
View File
@@ -9,7 +9,7 @@ import { recordTransponderSighting, buildWarmupCheck, createPrologue, getPrologu
import { findTransponderConflict, getDriverProfileId } from "./driver_profile_logic.js";
import { renderRaceDayView, refreshRaceDayWarmup, refreshRaceDayPrologueClock, updateRaceDayStartDisplay } from "./race_day_view.js";
import { beginSession as beginSessionControl, finishSession as finishSessionControl, pauseSession as pauseSessionControl, resumeSession as resumeSessionControl } from "./session_control.js";
import { normalizeSeries, buildSeriesStandings, getSeriesRoundStatus } from "./series_logic.js";
import { normalizeSeries, buildSeriesStandings, getSeriesRoundStatus, getSeriesRoundNextStep } from "./series_logic.js";
import { renderSeriesView } from "./series_view.js";
import { RACE_AUDIO_EVENT_DEFINITIONS, createRaceAudioEngine, normalizeRaceAudioSettings, isSilencedDuringRace } from "./race_audio.js";
@@ -616,6 +616,7 @@ const getSeriesRounds = (series) => state.events
classDrivers: state.drivers.filter((driver) => driver.classId === event.classId).sort(byDriverName),
participantIds: getEventDrivers(event).map((driver) => driver.id),
status: getSeriesRoundStatus(sessions),
nextStep: getSeriesRoundNextStep(sessions),
qualHeatCount: new Set(qualSessions.map((session) => String(session.name || "").split(" ").pop())).size,
finalCount: sessions.filter((session) => session.type === "final").length,
};
@@ -687,6 +688,12 @@ const generateSeriesRoundFinals = (eventId) => {
saveState();
return created;
};
// The row's run button: make the session the active one and go to Race Day, where only
// Start is left to press.
const runSeriesSession = (sessionId) => {
if (!selectOperationalSession(sessionId, { render: false })) return;
navigateToView("race_day");
};
const openSeriesRound = (eventId) => {
selectedEventEditId = eventId;
navigateToView("race_setup");
@@ -724,7 +731,7 @@ const exportSeriesPdf = async (series, tables) => {
)),
});
};
const renderSeries = () => renderSeriesView({ state, dom, t, escapeHtml, saveState, renderView, uid, getClassName, getSeriesStandings, createSeriesEvents, getRaceFormatPresets, exportSeriesPdf, printSeries, getSeriesRounds, deleteSeriesRaces, setSeriesRoundFormat, setSeriesRoundParticipants, copySeriesRoundParticipants, addDriverToSeriesRound, generateSeriesRoundQualifying, generateSeriesRoundFinals, openSeriesRound });
const renderSeries = () => renderSeriesView({ state, dom, t, escapeHtml, saveState, renderView, uid, getClassName, getSeriesStandings, createSeriesEvents, getRaceFormatPresets, exportSeriesPdf, printSeries, getSeriesRounds, deleteSeriesRaces, runSeriesSession, setSeriesRoundFormat, setSeriesRoundParticipants, copySeriesRoundParticipants, addDriverToSeriesRound, generateSeriesRoundQualifying, generateSeriesRoundFinals, openSeriesRound });
const renderArchive = () => renderResultsArchiveView({
state, dom, t, escapeHtml, formatLap, formatRaceClock, renderTable,
getClassName, getEventName, buildLeaderboard, getCompetitorPassings,
@@ -910,6 +917,7 @@ const TRANSLATIONS = {
"race_day.quick_race": "Skapa race",
"race_day.pick_session": "Session",
"race_day.show_all_sessions": "Visa alla sessioner",
"race_day.go_next": "Nästa: {name}",
"race_day.hidden_sessions": "({count} från andra dagar dolda)",
"race_day.reset_session_hint": "Nollställer sessionens varv och resultat, t.ex. vid omstart. Pausa först om heatet körs.",
"race_day.reset_session_confirm": "Nollställ alla varv och resultat i \"{name}\"?\n\nDet går inte att ångra.",
@@ -1017,6 +1025,11 @@ const TRANSLATIONS = {
"series.delete_races_confirm": "Ta också bort seriens {count} race från Race Setup, med heat och resultat?\n\nOK = ta bort racen\nAvbryt = behåll racen (t.ex. för resultatarkivet)",
"series.created_rounds": "{count} race skapade. De finns i listan nedan och under Race Setup.",
"series.created_none": "Inga nya race skapades: seriens klasser har redan race på de datumen.",
"series.run_seeding": "Seedningsträning",
"series.run_session": "Kör {name}",
"series.show_live": "Pågår: {name}",
"series.skip_seeding": "Hoppa över – generera kval",
"series.run_hint": "Väljer sessionen och öppnar Race Day – där trycker du Starta.",
"nav.race_setup": "Race Setup",
"nav.race_setup_sub": "Open Practice, klubbrace och endurance",
"nav.overlay": "Overlay",
@@ -2769,6 +2782,7 @@ const TRANSLATIONS = {
"race_day.quick_race": "Create race",
"race_day.pick_session": "Session",
"race_day.show_all_sessions": "Show all sessions",
"race_day.go_next": "Next: {name}",
"race_day.hidden_sessions": "({count} from other days hidden)",
"race_day.reset_session_hint": "Clears the session's laps and results, e.g. for a restart. Pause first if the heat is running.",
"race_day.reset_session_confirm": "Clear every lap and result in \"{name}\"?\n\nThis cannot be undone.",
@@ -2876,6 +2890,11 @@ const TRANSLATIONS = {
"series.delete_races_confirm": "Also delete the series' {count} races from Race Setup, with heats and results?\n\nOK = delete the races\nCancel = keep the races (e.g. for the results archive)",
"series.created_rounds": "{count} races created. They are listed below and under Race Setup.",
"series.created_none": "No new races were created: the series' classes already have races on those dates.",
"series.run_seeding": "Seeding practice",
"series.run_session": "Run {name}",
"series.show_live": "Running: {name}",
"series.skip_seeding": "Skip – generate qualifying",
"series.run_hint": "Selects the session and opens Race Day - press Start there.",
"nav.race_setup": "Race Setup",
"nav.race_setup_sub": "Open Practice, club races and endurance",
"nav.overlay": "Overlay",
+22
View File
@@ -752,6 +752,28 @@ export function generateQualifyingForRace(event, { buildPracticeStandings, getEv
// The order a race's sessions are run in: practice, then qualifying round by round (Q1 H1,
// Q1 H2, Q2 H1 ... - generation stores them heat by heat), then finals leg by leg with the
// lowest final first (C1, B1, A1, C2 ...). Anything else keeps the order it was created in.
export function orderSessionsForRunning(sessions = []) {
const key = (session, index) => {
if (["practice", "free_practice", "open_practice"].includes(session.type)) return [0, 0, 0, index];
if (session.type === "qualification") {
const parsed = parseQualifyingHeatName(session.name);
return parsed ? [1, parsed.round, parsed.heat, index] : [1, 0, 0, index];
}
if (session.type === "final") {
const match = String(session.name || "").match(/^([A-Z])\b.*?(\d+)\s*$/);
return match ? [2, Number(match[2]), -(match[1].charCodeAt(0)), index] : [2, 0, 0, index];
}
return [1, 0, 0, index];
};
return sessions
.map((session, index) => ({ session, key: key(session, index) }))
.sort((a, b) => a.key.reduce((diff, value, i) => diff || value - b.key[i], 0))
.map((item) => item.session);
}
// Generated qualifying sessions are named "Q<round> H<heat>" (see generateQualifyingForRace)
// with no separate round/heat fields of their own - shared here so every place that needs
// to know which round/heat a session belongs to parses the same way.
+2 -1
View File
@@ -1,3 +1,4 @@
import { orderSessionsForRunning } from "./event_race_logic.js";
import { describeDecoderClockSkew } from "./decoder_clock_check.js";
import { getLayoutLapWindowOverride } from "./track_layouts_logic.js";
function unique(values) {
@@ -42,7 +43,7 @@ export function buildRaceDayQueue(state) {
return { current: null, next: null, afterNext: null, upcoming: [] };
}
const eventSessions = sessions.filter((session) => session.eventId === current.eventId);
const eventSessions = orderSessionsForRunning(sessions.filter((session) => session.eventId === current.eventId));
const currentIndex = eventSessions.findIndex((session) => session.id === current.id);
const upcoming = eventSessions
.slice(Math.max(0, currentIndex + 1))
+1
View File
@@ -280,6 +280,7 @@ export function renderRaceDayView(deps) {
${sessionChoices.hidden || showAllSessions ? `<label class="race-day-show-all"><input type="checkbox" id="raceDayShowAllSessions" ${showAllSessions ? "checked" : ""} /> ${escapeHtml(t("race_day.show_all_sessions"))}${sessionChoices.hidden ? ` <span class="hint">${escapeHtml(t("race_day.hidden_sessions", { count: sessionChoices.hidden }))}</span>` : ""}</label>` : ""}
${session && !isSelected ? `<button id="raceDayActivate" class="btn" type="button">${t("race_day.activate")}</button>` : ""}
<div class="race-day-actions">
${session && ["finished", "stopped"].includes(session.status) && queue.next ? `<button id="raceDayNextSession" class="btn btn-go" type="button" data-race-day-select="${escapeHtml(queue.next.id)}">▶ ${escapeHtml(t("race_day.go_next", { name: queue.next.name }))}</button>` : ""}
${usesPrologue
? renderPrologueControls({ t, escapeHtml, getDefaultPrologueSec }, session, warmupForChecks, canStart)
: isLiveSession ? "" : `<button id="raceDayStart" class="btn btn-go" type="button" ${canStart ? "" : "disabled"}>${t(isPracticeSession ? "race_day.start_practice" : "timing.start")}</button>`}
+21
View File
@@ -1,3 +1,4 @@
import { orderSessionsForRunning } from "./event_race_logic.js";
// Series / cup: a set of races (events) scored together. Each event is one class, so a series
// with several classes gives one standings table per class. Pure functions - app.js feeds
// each event's day result (finishing order, from finals or else qualifying).
@@ -162,3 +163,23 @@ export function getSeriesRoundStatus(sessions = []) {
if (finished(quals)) return "qual_done";
return started(quals) ? "qual_running" : "qual_ready";
}
// The one thing to do next in a round, for the button on its row: run the seeding practice,
// make qualifying, run the next heat, make finals, run the next final. A session already
// running is shown first.
export function getSeriesRoundNextStep(sessions = []) {
const ordered = orderSessionsForRunning(sessions);
const live = ordered.find((session) => ["running", "paused"].includes(session.status));
if (live) return { kind: "live", session: live };
const ready = (type) => ordered.find((session) => session.type === type && session.status === "ready");
const has = (type) => ordered.some((session) => session.type === type);
if (!has("qualification")) {
const practice = ready("practice");
return practice ? { kind: "seeding", session: practice } : { kind: "make_qualifying" };
}
const heat = ready("qualification");
if (heat) return { kind: "qualifying", session: heat };
if (!has("final")) return { kind: "make_finals" };
const final = ready("final");
return final ? { kind: "final", session: final } : { kind: "done" };
}
+18 -4
View File
@@ -84,6 +84,21 @@ function renderRoundParticipants(round, { t, escapeHtml }) {
</div>`;
}
// One button for what comes next in the round: seeding practice, make qualifying, the next
// heat, make finals, the next final. "Run" selects the session and opens Race Day.
function renderNextStep(round, { t, escapeHtml }) {
const step = round.nextStep || {};
const noDrivers = round.participantIds.length ? "" : "disabled";
const run = (label, live = false) => `<button class="btn btn-go btn-mini" type="button" data-round-action="run" data-round-session="${escapeHtml(step.session.id)}" title="${escapeHtml(t("series.run_hint"))}" ${live ? "" : noDrivers}>${live ? "●" : "▶"} ${escapeHtml(label)}</button>`;
const makeQualifying = (label, primary) => `<button class="btn ${primary ? "btn-primary" : ""} btn-mini" type="button" data-round-action="qualifying" ${noDrivers}>${escapeHtml(label)}</button>`;
if (step.kind === "live") return run(t("series.show_live", { name: step.session.name }), true);
if (step.kind === "seeding") return run(t("series.run_seeding")) + makeQualifying(t("series.skip_seeding"), false);
if (step.kind === "make_qualifying") return makeQualifying(t("series.make_qualifying"), true);
if (step.kind === "qualifying" || step.kind === "final") return run(t("series.run_session", { name: step.session.name }));
if (step.kind === "make_finals") return `<button class="btn btn-primary btn-mini" type="button" data-round-action="finals">${t("series.make_finals")}</button>`;
return "";
}
function renderRoundsTable(rounds, { t, escapeHtml }) {
if (!rounds.length) return `<p class="hint">${t("series.no_rounds")}</p>`;
const number = (round, name, value, min) => `<input class="series-round-number" type="number" min="${min}" name="${name}" value="${value}" ${round.status === "not_started" ? "" : "disabled"} />`;
@@ -92,9 +107,7 @@ function renderRoundsTable(rounds, { t, escapeHtml }) {
<thead><tr><th>${t("series.col_date")}</th><th>${t("series.col_race")}</th><th>${t("series.col_drivers")}</th><th title="${escapeHtml(t("series.col_qual_hint"))}">${t("series.col_qual_short")}</th><th>${t("series.col_finals")}</th><th>${t("series.col_per_heat")}</th><th>${t("series.col_status")}</th><th></th></tr></thead>
<tbody>${rounds.map((round) => {
const config = round.event.raceConfig || {};
const action = round.status === "not_started"
? `<button class="btn btn-primary btn-mini" type="button" data-round-action="qualifying" ${round.participantIds.length ? "" : "disabled"}>${t("series.make_qualifying")}</button>`
: round.status === "qual_done" ? `<button class="btn btn-primary btn-mini" type="button" data-round-action="finals">${t("series.make_finals")}</button>` : "";
const action = renderNextStep(round, { t, escapeHtml });
return `
<tr data-round="${escapeHtml(round.event.id)}" class="${expandedRoundId === round.event.id ? "is-expanded" : ""}">
<td>${escapeHtml(round.event.date || t("series.no_date"))}</td>
@@ -143,7 +156,7 @@ function renderStandingsTable(table, { t, escapeHtml }) {
export function renderSeriesView(deps) {
const {
state, dom, t, escapeHtml, saveState, renderView, uid, getClassName, getSeriesStandings, createSeriesEvents, getRaceFormatPresets, exportSeriesPdf, printSeries,
getSeriesRounds, deleteSeriesRaces, setSeriesRoundFormat, setSeriesRoundParticipants, copySeriesRoundParticipants, addDriverToSeriesRound, generateSeriesRoundQualifying, generateSeriesRoundFinals, openSeriesRound,
getSeriesRounds, deleteSeriesRaces, runSeriesSession, setSeriesRoundFormat, setSeriesRoundParticipants, copySeriesRoundParticipants, addDriverToSeriesRound, generateSeriesRoundQualifying, generateSeriesRoundFinals, openSeriesRound,
} = deps;
const list = state.series || [];
if (!list.some((item) => item.id === selectedSeriesId)) selectedSeriesId = list[0]?.id || "";
@@ -292,6 +305,7 @@ export function renderSeriesView(deps) {
const action = button.dataset.roundAction;
if (action === "toggle") expandedRoundId = expandedRoundId === eventId ? "" : eventId;
if (action === "open") { openSeriesRound(eventId); return; }
if (action === "run") { runSeriesSession(button.dataset.roundSession); return; }
if (action === "qualifying" && !generateSeriesRoundQualifying(eventId)) window.alert(t("series.no_participants"));
if (action === "finals") generateSeriesRoundFinals(eventId);
if (action === "remove") {