feat(race-setup): list sessions in running order and move them with up/down (1.49.0)

This commit is contained in:
larssand committed 2026-11-01 20:13:15 +01:00
1 parent e199f3aa1a
commit bb0fa7ede4
14 files changed
+104 -14

No files matched your search

+7 -3
View File
@@ -641,7 +641,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),
nextStep: getSeriesRoundNextStep(sessions, event.sessionOrder),
qualHeatCount: new Set(qualSessions.map((session) => String(session.name || "").split(" ").pop())).size,
finalCount: sessions.filter((session) => session.type === "final").length,
calculatedResult: getEventDayResult(event),
@@ -1658,6 +1658,8 @@ const TRANSLATIONS = {
"events.stagger_gap_sec": "Stagger-gap (sek)",
"events.session_settings": "Sessioninställningar",
"events.edit_session": "Inställningar",
"events.move_session_up": "Kör tidigare (flytta upp i körordningen)",
"events.move_session_down": "Kör senare (flytta ned i körordningen)",
"events.start_mode_mass": "Mass-start",
"events.start_mode_position": "Positionsstart",
"events.start_mode_staggered": "Staggered / individuell start",
@@ -2612,7 +2614,7 @@ const TRANSLATIONS = {
"guide.race_day_title": "Race Day och säker start",
"guide.card_race_day_blurb": "Förkontroll, startlista, heat-kö, automatisk backup och fokuserad racedrift.",
"guide.race_day_1": "1. Skapa race och sessioner i Race Setup. Öppna sedan Race Day från gruppen Start.",
"guide.race_day_2": "2. Välj aktuellt heat. Listan visar dagens race (Visa alla sessioner visar resten). Pågår, Nästa och Därefter följer körordningen: träning, kval omgång för omgång, finaler från lägsta. ▶ Nästa väljer nästa heat när ett är klart.",
"guide.race_day_2": "2. Välj aktuellt heat. Listan visar dagens race (Visa alla sessioner visar resten). Pågår, Nästa och Därefter följer körordningen: träning, kval omgång för omgång, finaler från lägsta. ▶ Nästa väljer nästa heat när ett är klart. Ett heat som tagits bort och skapats om hamnar på rätt plats, och ▲▼ på sessionerna i Race Setup ändrar ordningen för hand.",
"guide.race_day_3": "3. Förkontrollen visar blockerare först, sedan varningar och godkända kontroller. Knapparna vid problemen öppnar relevant meny; min/max kan rättas direkt i Race Day. Förkontrollen blockerar start när Main decoder är offline, deltagare eller transpondrar saknas, transpondrar är dubbla, varvfönstret är ogiltigt eller en positionsgrid är ofullständig.",
"guide.race_day_4": "4. Gula kontroller är varningar. Valfria split-/depådecoders, backend och ljud visas tydligt men ändrar inte vanlig varvräkning.",
"guide.race_day_5": "5. Vid start synkas state till backend och en konsistent SQLite-backup skapas i data/backups innan den befintliga audio- och starttonssekvensen körs. De 30 senaste sparas.",
@@ -3553,6 +3555,8 @@ const TRANSLATIONS = {
"events.stagger_gap_sec": "Stagger gap (sec)",
"events.session_settings": "Session settings",
"events.edit_session": "Settings",
"events.move_session_up": "Run earlier (move up in the running order)",
"events.move_session_down": "Run later (move down in the running order)",
"events.start_mode_mass": "Mass start",
"events.start_mode_position": "Position start",
"events.start_mode_staggered": "Staggered / individual start",
@@ -4507,7 +4511,7 @@ const TRANSLATIONS = {
"guide.race_day_title": "Race Day and safe start",
"guide.card_race_day_blurb": "Preflight, start list, heat queue, automatic backup, and focused race operation.",
"guide.race_day_1": "1. Create the race and sessions in Race Setup, then open Race Day from the Start group.",
"guide.race_day_2": "2. Select the current heat. The list shows today's races (Show all sessions shows the rest). Running, Next and After next follow the running order: practice, qualifying round by round, finals from the lowest. ▶ Next selects the next heat when one is done.",
"guide.race_day_2": "2. Select the current heat. The list shows today's races (Show all sessions shows the rest). Running, Next and After next follow the running order: practice, qualifying round by round, finals from the lowest. ▶ Next selects the next heat when one is done. A heat deleted and made again lands in its right place, and ▲▼ on the sessions in Race Setup change the order by hand.",
"guide.race_day_3": "3. Preflight lists blockers first, then warnings and passed checks. Buttons beside issues open the relevant menu; min/max can be corrected directly in Race Day. Preflight blocks start when the Main decoder is offline, participants or transponders are missing, transponders are duplicated, the lap window is invalid, or a position grid is incomplete.",
"guide.race_day_4": "4. Yellow checks are warnings. Optional split/pit decoders, backend, and audio are visible but do not change normal lap counting.",
"guide.race_day_5": "5. Starting synchronizes state to the backend and creates a consistent SQLite backup in data/backups before the existing audio and start-tone sequence runs. The latest 30 are retained.",
+9 -1
View File
@@ -1,3 +1,4 @@
import { orderSessionsForRunning, moveSessionInRunningOrder } from "./event_race_logic.js";
let activeManageTab = "setup";
// Maps a data-target anchor id (used by the step-card overview and the race-summary
// warning links) to the tab it now lives inside, so jumping to it also switches tabs
@@ -117,7 +118,8 @@ export function renderEventManagerView(context) {
}
ensureRaceParticipantsConfigured(event);
const sessions = getSessionsForEvent(eventId);
// Listed in running order; ▲▼ change it (stored on the event as sessionOrder).
const sessions = orderSessionsForRunning(getSessionsForEvent(eventId), event.sessionOrder);
const eventManageArea = document.getElementById("eventManageArea");
if (!eventManageArea) {
return;
@@ -358,6 +360,12 @@ export function renderEventManagerView(context) {
renderView();
});
document.querySelectorAll(`[data-session-move="${s.id}"]`).forEach((button) => button.addEventListener("click", () => {
event.sessionOrder = moveSessionInRunningOrder(sessions, event.sessionOrder, s.id, Number(button.dataset.step));
saveState();
refreshManager();
}));
document.getElementById(`session-delete-${s.id}`)?.addEventListener("click", () => {
state.sessions = state.sessions.filter((x) => x.id !== s.id);
delete state.resultsBySession[s.id];
+3 -1
View File
@@ -166,7 +166,7 @@ export function renderEventManagerMarkup(context) {
<div class="mt-16">
${renderTable(
[t("table.session"), t("table.type"), t("table.duration"), t("table.start_mode"), t("table.seeding"), t("table.status"), t(event.mode === "track" ? "events.assignments" : "events.participants"), t("events.actions")],
sessions.map((s) => {
sessions.map((s, sessionIndex) => {
const assignCount =
event.mode === "track"
? (s.assignments || []).length
@@ -183,6 +183,8 @@ export function renderEventManagerMarkup(context) {
<td>${escapeHtml(getStatusLabel(s.status))}</td>
<td>${assignCount || (event.mode === "track" ? t("events.na") : "-")}</td>
<td class="actions-inline">
<button class="btn btn-mini" type="button" data-session-move="${escapeHtml(s.id)}" data-step="-1" title="${escapeHtml(t("events.move_session_up"))}" ${sessionIndex ? "" : "disabled"}>▲</button>
<button class="btn btn-mini" type="button" data-session-move="${escapeHtml(s.id)}" data-step="1" title="${escapeHtml(t("events.move_session_down"))}" ${sessionIndex < sessions.length - 1 ? "" : "disabled"}>▼</button>
<button id="session-edit-${s.id}" class="btn">${t("events.edit_session")}</button>
<button id="session-active-${s.id}" class="btn">${t("events.set_active")}</button>
${
+24 -1
View File
@@ -768,7 +768,30 @@ 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 = []) {
// manualOrder (event.sessionOrder, set with ▲▼ in Race Setup) overrides it for the sessions it
// lists; a session made later keeps its own place, e.g. a recreated Q1 H2 after Q1 H1.
export function orderSessionsForRunning(sessions = [], manualOrder = []) {
const auto = orderSessionsAutomatically(sessions);
const byId = new Map(auto.map((session) => [session.id, session]));
const listed = [...new Set(manualOrder || [])].filter((id) => byId.has(id)).map((id) => byId.get(id));
if (!listed.length) return auto;
const listedIds = new Set(listed.map((session) => session.id));
let next = 0;
return auto.map((session) => (listedIds.has(session.id) ? listed[next++] : session));
}
// Moves one session a step up (-1) or down (+1) in the running order; returns the new manual
// order (every session id) to store on the event.
export function moveSessionInRunningOrder(sessions, manualOrder, sessionId, step) {
const ids = orderSessionsForRunning(sessions, manualOrder).map((session) => session.id);
const index = ids.indexOf(sessionId);
const other = index + step;
if (index < 0 || other < 0 || other >= ids.length) return ids;
[ids[index], ids[other]] = [ids[other], ids[index]];
return ids;
}
function orderSessionsAutomatically(sessions = []) {
const key = (session, index) => {
if (["practice", "free_practice", "open_practice"].includes(session.type)) return [0, 0, 0, index];
if (session.type === "qualification") {
+2 -1
View File
@@ -43,7 +43,8 @@ export function buildRaceDayQueue(state) {
return { current: null, next: null, afterNext: null, upcoming: [] };
}
const eventSessions = orderSessionsForRunning(sessions.filter((session) => session.eventId === current.eventId));
const event = (state.events || []).find((item) => item.id === current.eventId);
const eventSessions = orderSessionsForRunning(sessions.filter((session) => session.eventId === current.eventId), event?.sessionOrder);
const currentIndex = eventSessions.findIndex((session) => session.id === current.id);
const upcoming = eventSessions
.slice(Math.max(0, currentIndex + 1))
+3
View File
@@ -2,6 +2,7 @@ import { isPracticeSessionType } from "./track_layouts_logic.js";
import { renderTrackLayoutBar, bindTrackLayoutBar } from "./track_layout_bar.js";
import { PROLOGUE_OPTIONS_SEC, formatPrologueOption } from "./prologue_logic.js";
import { estimateFinish } from "./timing_logic.js";
import { orderSessionsForRunning } from "./event_race_logic.js";
export function getRaceDayCheckAction(item, session) {
if (item.level === "ok") return null;
if (["backend", "decoder", "split_decoder", "pit_decoders", "audio"].includes(item.id)) {
@@ -90,6 +91,8 @@ export function buildRaceDaySessionGroups({ sessions, events, selectedId = "", s
if (!groups.has(session.eventId)) groups.set(session.eventId, { event: eventById.get(session.eventId) || null, sessions: [] });
groups.get(session.eventId).sessions.push(session);
});
// Each race's sessions in running order (practice, Q1 H1, Q1 H2 ..., finals).
groups.forEach((group) => { group.sessions = orderSessionsForRunning(group.sessions, group.event?.sessionOrder); });
const list = [...groups.values()].sort((a, b) =>
Number(b.sessions.some(isLive)) - Number(a.sessions.some(isLive))
|| String(b.event?.date || "").localeCompare(String(a.event?.date || "")));
+2 -2
View File
@@ -192,8 +192,8 @@ export function getSeriesRoundStatus(sessions = []) {
// 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);
export function getSeriesRoundNextStep(sessions = [], manualOrder = []) {
const ordered = orderSessionsForRunning(sessions, manualOrder);
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");