feat(race): driver picker grouped by class with all/none per class, search and copy from an earlier race (1.89.33)
This commit is contained in:
1 parent
eac897c774
commit
cc286165df
17 files changed
+339
-102
No files matched your search
@@ -8,6 +8,11 @@ The application version is maintained in `package.json` and displayed in the adm
|
||||
|
||||
No changes recorded yet.
|
||||
|
||||
## 1.89.33
|
||||
|
||||
- **Driver picker grouped by class:** picking the drivers of a race (new-race wizard, Manage race and series rounds) groups them by class with **All** / **None** per class, a search box (name or transponder), **Show only selected** and **Same drivers as…** to copy an earlier race's field (the series' rounds first). **Select all** now takes only the race's own class or what the search shows - before, it ticked the whole club, so a Rookie race meant unticking everyone one by one.
|
||||
- **Fix:** "Copy from previous" in a series round dropped drivers from other classes (rookies from 2WD/4WD); it now keeps everyone from the previous round.
|
||||
|
||||
## 1.89.32
|
||||
|
||||
- **Lap chart in the results:** every qualifying heat and final in the race overview (Race Day and the results archive) has a fold-out 📈 lap chart - each driver's place after every lap, from the passings. It is in the print and PDF of a single heat, and with the finals in the full results PDF and print.
|
||||
|
||||
@@ -219,9 +219,9 @@ Menu **Series / cup** runs a championship over any number of rounds, with freely
|
||||
Rookies are not registered again: they race with the driver and transponder they already have in 2WD or 4WD, and 2WD and 4WD can be mixed.
|
||||
|
||||
1. **Classes:** create a class called Rookie, with no drivers of its own.
|
||||
2. **Single race:** in Race Setup, create the race with class Rookie and tick the rookies under Participants → **Drivers from other classes**.
|
||||
2. **Single race:** in Race Setup, create the race with class Rookie. The driver list is grouped by class (Rookie 2WD, Rookie 4WD, Junior 4WD ...): each class has **All** and **None**, the search box finds a driver by name or transponder, **Show only selected** checks the list, and **Same drivers as…** copies the field of an earlier race (the series' own rounds first). **Select all** takes only the race's own class (or what the search shows), never the whole club.
|
||||
3. **Series:** tick Rookie under the series' classes. For a series already running, paste the same dates again and press Create rounds: only the missing Rookie rounds are made.
|
||||
4. **Each round:** open the driver list on the Rookie row, then tick the rookies under **Drivers from other classes**. Copy from previous takes the same rookies next time.
|
||||
4. **Each round:** open the driver list on the Rookie row and tick the rookies class by class (same grouped list). Copy from previous takes the same rookies next time, from every class.
|
||||
|
||||
Rookie gets its own standings with the series' points table, count rule and club rule; points never mix with the driver's 2WD/4WD standings. Race format, open practice and lap time limits are not affected.
|
||||
|
||||
|
||||
+2
-2
@@ -232,9 +232,9 @@ Menyn **Serier / cup** kör ett mästerskap över valfritt antal deltävlingar,
|
||||
Rookies läggs inte upp igen: de kör med samma förare och transponder som de redan har i 2WD eller 4WD, och 2WD och 4WD kan blandas.
|
||||
|
||||
1. **Klasser:** skapa en klass som heter Rookie, utan egna förare.
|
||||
2. **Eget race:** i Race Setup, skapa racet med klass Rookie och bocka i rookies under Deltagare → **Förare från andra klasser**.
|
||||
2. **Eget race:** i Race Setup, skapa racet med klass Rookie. Förarlistan är grupperad per klass (Rookie 2WD, Rookie 4WD, Junior 4WD …): varje klass har **Alla** och **Ingen**, sökrutan hittar en förare på namn eller transponder, **Visa bara valda** kontrollerar listan och **Samma förare som…** kopierar startfältet från ett tidigare race (seriens egna deltävlingar först). **Markera alla** tar bara racets egen klass (eller det sökningen visar), aldrig hela klubben.
|
||||
3. **Serie:** bocka i Rookie bland seriens klasser. Är serien redan igång: klistra in samma datum igen och tryck Skapa deltävlingar, bara de saknade Rookie-deltävlingarna skapas.
|
||||
4. **Varje deltävling:** öppna förarlistan på Rookie-raden och bocka i rookies under **Förare från andra klasser**. Kopiera från förra tar samma rookies nästa gång.
|
||||
4. **Varje deltävling:** öppna förarlistan på Rookie-raden och bocka i rookies klass för klass (samma grupperade lista). Kopiera från förra tar samma rookies nästa gång, från alla klasser.
|
||||
|
||||
Rookie får en egen ställning med seriens poängtabell, räkneregel och klubbregel; poängen blandas aldrig med förarens 2WD/4WD-ställning. Racets format, open practice och varvtidsgränser påverkas inte.
|
||||
|
||||
|
||||
@@ -2981,3 +2981,5 @@ Tests: decoder_diagnostics.test.js covers bounds, isolation, snapshots and outco
|
||||
|
||||
|
||||
`lap_chart_logic.js` (pure) turns a heat's passings into a lap chart: `buildLapChart(entries)` gives each driver's place after every lap (order of crossing for that lap, among those who did it), `renderLapChartSvg()` draws it as a self-styled inline SVG (`currentColor` for axes, so it works in every theme and in print). `buildRaceOverview()` adds `heat.lapChart` for qualifying and finals when given `getCompetitorPassings`; the race overview panel shows it in a `<details>`, `renderRaceOverviewHeatsHtml()` prints it (single heat, or finals in the full results), and `buildHeatPdfSection()` sends it as `section.chart`, which `server.js` `normalizePdfLapChart()` checks and `server/pdf_render.js` `drawLapChart()` draws as vector lines.
|
||||
|
||||
`participant_picker.js` is the one driver picker for the new-race wizard (step 2), Manage race → Participants and a series round: `groupParticipantChoices()` groups drivers by class (the race's own class first, then classes with someone ticked), `renderParticipantPicker()` draws search, Only selected, Select all / Clear, per-class All / None and an optional "Same drivers as…" select (`participantCopySources()`: earlier races, the series' rounds first, no open practice); `bindParticipantPicker()` works in the DOM and calls the caller's `onChange(ids)` (search text, Only selected and folded classes are remembered per picker across re-renders). "Select all" never takes the folded classes, only the race's own class or the current search.
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "rc-racecore",
|
||||
"version": "1.89.32",
|
||||
"version": "1.89.33",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "rc-racecore",
|
||||
"version": "1.89.32",
|
||||
"version": "1.89.33",
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"better-sqlite3": "^12.11.1",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "rc-racecore",
|
||||
"version": "1.89.32",
|
||||
"version": "1.89.33",
|
||||
"private": true,
|
||||
"description": "RC RaceCore live timing and race control with AMMC ingest and SQLite persistence",
|
||||
"engines": {
|
||||
|
||||
+32
-2
@@ -16,6 +16,7 @@ import { renderRaceDayView, refreshRaceDayWarmup, refreshRaceDayPrologueClock, u
|
||||
import { assignMarshals, normalizeRaceDays, getRaceDay, upsertRaceDay, orderDaySessions, buildDaySchedule, getAutopilotAction, moveInDayOrder, pickBoardDate, getDueCall, withRaceSetupStart, eventScheduleFromDayRows } from "./day_schedule_logic.js";
|
||||
import { buildRaceOverview, buildRaceOverviewCsvRows, withQualifyingPlaces, qualifyingPlaces } from "./race_overview_logic.js";
|
||||
import { renderLapChartSvg } from "./lap_chart_logic.js";
|
||||
import { participantCopySources } from "./participant_picker.js";
|
||||
import { renderRaceOverviewPanel, bindRaceOverviewPanel } from "./race_overview_view.js";
|
||||
import { renderSpeakerPanel, bindSpeakerPanel } from "./speaker_panel_view.js";
|
||||
import { renderDaySchedulePanel, bindDaySchedulePanel, buildDaySchedulePrintHtml, renderDriverBoard, formatClockTime, renderDayCallBanner, bindDayCallBanner } from "./day_schedule_view.js";
|
||||
@@ -72,7 +73,13 @@ const renderRaceFormatContextCardView = (titleKey, hintKey) => renderRaceFormatC
|
||||
const renderManageStatusBadgeView = (status) => renderManageStatusBadge(status, { t });
|
||||
const renderRaceWizardStepsView = () => renderRaceWizardSteps({ t, raceWizardStep, escapeHtml });
|
||||
const renderRaceWizardContentView = (draft, classOptions, wizardDrivers, preset) =>
|
||||
renderRaceWizardContent(draft, classOptions, wizardDrivers, preset, { t, escapeHtml, raceWizardStep, getRaceFormatPresets, getClassName, getRaceWizardSessionPlan });
|
||||
renderRaceWizardContent(draft, classOptions, wizardDrivers, preset, {
|
||||
t, escapeHtml, raceWizardStep, getRaceFormatPresets, getClassName, getRaceWizardSessionPlan,
|
||||
// Every club driver, grouped by class: a Rookie / Junior race takes drivers from several classes.
|
||||
allDrivers: state.drivers.filter((driver) => !driver.guestEventId),
|
||||
classes: state.classes,
|
||||
copySources: participantCopySources(state.events, { getDriverIds: (event) => getEventDrivers(event).map((driver) => driver.id) }),
|
||||
});
|
||||
const renderRaceStandingsTableView = (rows, emptyLabel) => renderRaceStandingsTable(rows, emptyLabel, { t, renderTable, escapeHtml });
|
||||
|
||||
const normalizeRaceTeam = (team) => normalizeRaceTeamLogic(team, { uid });
|
||||
@@ -1093,7 +1100,9 @@ const copySeriesRoundParticipants = (series, eventId) => {
|
||||
const index = rounds.findIndex((round) => round.event.id === eventId);
|
||||
const previous = rounds.slice(0, Math.max(0, index)).reverse().find((round) => round.event.classId === rounds[index]?.event.classId);
|
||||
if (!previous) return false;
|
||||
setSeriesRoundParticipants(eventId, previous.participantIds.filter((id) => rounds[index].classDrivers.some((driver) => driver.id === id)));
|
||||
// Everyone from the previous round who is still in the club - a Rookie round's drivers come
|
||||
// from other classes, so this must not keep only the round's own class.
|
||||
setSeriesRoundParticipants(eventId, previous.participantIds.filter((id) => state.drivers.some((driver) => driver.id === id && !driver.guestEventId)));
|
||||
return true;
|
||||
};
|
||||
// A driver turning up on the day: registered in the round's class (and the series' club for a
|
||||
@@ -3272,6 +3281,16 @@ const TRANSLATIONS = {
|
||||
"race_overview.standings": "Ställning",
|
||||
"race_overview.heats_done": "{done} av {total} heat klara",
|
||||
"race_overview.no_results": "Inga resultat än.",
|
||||
"picker.search": "Sök förare eller transponder…",
|
||||
"picker.only_selected": "Visa bara valda",
|
||||
"picker.selected_count": "{count} valda",
|
||||
"picker.group_count": "{selected} av {total}",
|
||||
"picker.all": "Alla",
|
||||
"picker.none": "Ingen",
|
||||
"picker.all_hint": "Väljer alla i racets klass, eller alla som sökningen visar - aldrig hela klubben.",
|
||||
"picker.copy_from": "Samma förare som…",
|
||||
"picker.no_class": "Utan klass",
|
||||
"picker.primary_empty": "Inga förare registrerade i {name} - välj från klasserna nedan.",
|
||||
"lap_chart.title": "Varvdiagram",
|
||||
"lap_chart.hint": "Placering efter varje varv, räknat från passeringarna. Officiell placering står till höger.",
|
||||
"race_overview.not_run": "Inte körd än.",
|
||||
@@ -5625,6 +5644,16 @@ const TRANSLATIONS = {
|
||||
"race_overview.standings": "Standings",
|
||||
"race_overview.heats_done": "{done} of {total} heats done",
|
||||
"race_overview.no_results": "No results yet.",
|
||||
"picker.search": "Search driver or transponder…",
|
||||
"picker.only_selected": "Show only selected",
|
||||
"picker.selected_count": "{count} selected",
|
||||
"picker.group_count": "{selected} of {total}",
|
||||
"picker.all": "All",
|
||||
"picker.none": "None",
|
||||
"picker.all_hint": "Selects everyone in the race's class, or everyone the search shows - never the whole club.",
|
||||
"picker.copy_from": "Same drivers as…",
|
||||
"picker.no_class": "No class",
|
||||
"picker.primary_empty": "No drivers registered in {name} - pick from the classes below.",
|
||||
"lap_chart.title": "Lap chart",
|
||||
"lap_chart.hint": "Place after every lap, counted from the passings. Official finish place on the right.",
|
||||
"race_overview.not_run": "Not run yet.",
|
||||
@@ -8008,6 +8037,7 @@ function renderEventWorkspace(mode) {
|
||||
setRaceWizardStep: (value) => { raceWizardStep = value; },
|
||||
ensureRaceWizardDraft,
|
||||
getDriversForClass,
|
||||
getEventDrivers,
|
||||
getRaceWizardPreset,
|
||||
getSessionsForEvent,
|
||||
getClassName,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { bindParticipantPicker, participantCopySources } from "./participant_picker.js";
|
||||
import { openHouseOfRcEntryRefresh, openHouseOfRcResultsPost } from "./houseofrc_view.js";
|
||||
import { mountSponsorSetup } from "./sponsor_event_view.js";
|
||||
import { mountTeamRaceSetup } from "./team_race_setup_view.js";
|
||||
@@ -148,6 +149,9 @@ export function renderEventManagerView(context) {
|
||||
const otherClassChoices = event.mode === "race" && event.classId
|
||||
? clubDrivers.filter((driver) => !driver.guestEventId && !participantChoices.includes(driver)).sort((a, b) => String(a.name || "").localeCompare(String(b.name || "")))
|
||||
: [];
|
||||
// Copy the drivers of an earlier race (a cup round) in one go; the series' own rounds first.
|
||||
const seriesEventIds = (state.series || []).filter((series) => (series.eventIds || []).includes(event.id)).flatMap((series) => series.eventIds || []);
|
||||
const copySources = event.mode === "race" ? participantCopySources(state.events, { currentEventId: event.id, seriesEventIds, getDriverIds: (item) => getEventDrivers(item).map((driver) => driver.id) }) : [];
|
||||
const teamDriverPool = event.mode === "race" ? getTeamDriverPool(event) : { drivers: [], fallback: false };
|
||||
const raceTeams = event.mode === "race" ? getEventTeams(event) : [];
|
||||
if (selectedTeamEditId && !raceTeams.some((team) => team.id === selectedTeamEditId)) {
|
||||
@@ -210,6 +214,7 @@ export function renderEventManagerView(context) {
|
||||
raceDrivers,
|
||||
participantChoices,
|
||||
otherClassChoices,
|
||||
participantCopySources: copySources,
|
||||
teamDriverPool,
|
||||
showTeamsSection,
|
||||
parseQualifyingHeatName,
|
||||
@@ -605,8 +610,12 @@ export function renderEventManagerView(context) {
|
||||
refreshManager();
|
||||
};
|
||||
|
||||
document.querySelectorAll(".race-participant").forEach((node) => {
|
||||
node.addEventListener("change", persistRaceParticipants);
|
||||
bindParticipantPicker(document.getElementById("manage-setup-participants"), {
|
||||
onChange: persistRaceParticipants,
|
||||
getCopyIds: (sourceId) => {
|
||||
const source = state.events.find((item) => item.id === sourceId);
|
||||
return source ? getEventDrivers(source).map((driver) => driver.id) : [];
|
||||
},
|
||||
});
|
||||
|
||||
// Race made from House of RC: fetch late entries and withdrawals again.
|
||||
@@ -635,20 +644,6 @@ export function renderEventManagerView(context) {
|
||||
event, overview: getRaceOverview(event), state, t, escapeHtml, saveState,
|
||||
}));
|
||||
|
||||
document.getElementById("selectAllParticipants")?.addEventListener("click", () => {
|
||||
document.querySelectorAll(".race-participant").forEach((node) => {
|
||||
node.checked = true;
|
||||
});
|
||||
persistRaceParticipants();
|
||||
});
|
||||
|
||||
document.getElementById("clearParticipants")?.addEventListener("click", () => {
|
||||
document.querySelectorAll(".race-participant").forEach((node) => {
|
||||
node.checked = false;
|
||||
});
|
||||
persistRaceParticipants();
|
||||
});
|
||||
|
||||
if (showTeamsSection) {
|
||||
mountTeamRaceSetup(document.getElementById("manage-setup-teams"), {
|
||||
event, state, t, escapeHtml, uid, saveState, refresh: refreshManager, getSessionsForEvent, getEventTeams, getTeamDriverPool, normalizeSession, getStatusLabel,
|
||||
|
||||
+15
-18
@@ -1,3 +1,4 @@
|
||||
import { renderParticipantPicker } from "./participant_picker.js";
|
||||
import { renderHouseOfRcSendStatus } from "./houseofrc_view.js";
|
||||
import { PROLOGUE_OPTIONS_SEC, formatPrologueOption } from "./prologue_logic.js";
|
||||
import { groupSessionsBySteps } from "./race_list_logic.js";
|
||||
@@ -51,6 +52,7 @@ export function renderEventManagerMarkup(context) {
|
||||
raceDrivers,
|
||||
participantChoices = raceDrivers,
|
||||
otherClassChoices = [],
|
||||
participantCopySources = [],
|
||||
teamDriverPool,
|
||||
showTeamsSection,
|
||||
parseQualifyingHeatName,
|
||||
@@ -190,28 +192,23 @@ export function renderEventManagerMarkup(context) {
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="actions">
|
||||
<button id="selectAllParticipants" class="btn" type="button">${t("events.select_all_participants")}</button>
|
||||
<button id="clearParticipants" class="btn btn-danger" type="button">${t("events.clear_participants")}</button>
|
||||
${event.houseOfRc?.eventId ? `<button id="houseOfRcRefreshEntries" class="btn" type="button" title="${escapeHtml(t("houseofrc.refresh_hint", { name: event.houseOfRc.name || "" }))}">🔄 ${t("houseofrc.refresh_button")}</button>` : ""}
|
||||
${event.houseOfRc?.eventId ? `<button id="houseOfRcSendResults" class="btn" type="button" title="${escapeHtml(t("houseofrc.results_hint", { name: event.houseOfRc.name || "" }))}">📤 ${t("houseofrc.results_button")}</button>` : ""}
|
||||
${event.houseOfRc?.eventId ? `<label class="toggle hor-auto-send" title="${escapeHtml(t("houseofrc.auto_send_hint"))}"><input type="checkbox" id="houseOfRcAutoSend" ${event.houseOfRc.autoSend ? "checked" : ""} /><span>${t("houseofrc.auto_send")}</span></label> ${renderHouseOfRcSendStatus(event, { t, escapeHtml })}` : ""}
|
||||
</div>
|
||||
${(() => {
|
||||
const card = (driver) => {
|
||||
const checked = event.raceConfig.participantsConfigured
|
||||
? (event.raceConfig.driverIds || []).includes(driver.id)
|
||||
: driver.classId === event.classId;
|
||||
return `
|
||||
<label class="check-card">
|
||||
<input type="checkbox" class="race-participant" value="${driver.id}" ${checked ? "checked" : ""} />
|
||||
<span>${escapeHtml(driver.name)}${driver.transponder ? ` (${escapeHtml(driver.transponder)})` : ""}</span>
|
||||
</label>
|
||||
`;
|
||||
};
|
||||
return `<div class="check-grid mt-16">${participantChoices.map(card).join("")}</div>
|
||||
${otherClassChoices.length ? `<details class="mt-16" id="otherClassParticipants"><summary>${t("events.other_class_participants", { count: otherClassChoices.length })}</summary><div class="check-grid mt-16">${otherClassChoices.map(card).join("")}</div></details>` : ""}
|
||||
<p class="muted mt-16">${t("events.participants_sync_hint")}</p>`;
|
||||
})()}
|
||||
${renderParticipantPicker({
|
||||
pickerKey: `race:${event.id}`,
|
||||
drivers: [...participantChoices, ...otherClassChoices],
|
||||
classes: state.classes,
|
||||
selectedIds: raceDrivers.map((driver) => driver.id),
|
||||
primaryClassId: event.classId || "",
|
||||
inputAttrs: () => `class="race-participant"`,
|
||||
copySources: participantCopySources,
|
||||
allId: "selectAllParticipants",
|
||||
noneId: "clearParticipants",
|
||||
t, escapeHtml,
|
||||
})}
|
||||
<p class="muted mt-16">${t("events.participants_sync_hint")}</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { bindParticipantPicker } from "./participant_picker.js";
|
||||
import { openHouseOfRcEventImport } from "./houseofrc_view.js";
|
||||
import { renderEventWorkspaceMarkup } from "./event_views.js";
|
||||
|
||||
@@ -32,6 +33,7 @@ export function renderEventWorkspaceView(context) {
|
||||
setRaceWizardStep,
|
||||
ensureRaceWizardDraft,
|
||||
getDriversForClass,
|
||||
getEventDrivers,
|
||||
getRaceWizardPreset,
|
||||
getSessionsForEvent,
|
||||
getClassName,
|
||||
@@ -236,15 +238,12 @@ export function renderEventWorkspaceView(context) {
|
||||
toggleWizardPlanField("createQualifying", "qualifyingRounds");
|
||||
toggleWizardPlanField("createTeamRace", "teamRaceDurationMin");
|
||||
|
||||
document.getElementById("wizardSelectAllParticipants")?.addEventListener("click", () => {
|
||||
const draft = getRaceWizardDraft();
|
||||
draft.driverIds = getDriversForClass(draft.classId).map((driver) => driver.id);
|
||||
renderView();
|
||||
});
|
||||
|
||||
document.getElementById("wizardClearParticipants")?.addEventListener("click", () => {
|
||||
getRaceWizardDraft().driverIds = [];
|
||||
renderView();
|
||||
bindParticipantPicker(document.querySelector(".participant-picker")?.parentElement, {
|
||||
onChange: (ids) => { getRaceWizardDraft().driverIds = ids; },
|
||||
getCopyIds: (sourceId) => {
|
||||
const source = state.events.find((item) => item.id === sourceId);
|
||||
return source ? getEventDrivers(source).map((driver) => driver.id) : [];
|
||||
},
|
||||
});
|
||||
|
||||
document.getElementById("raceWizardHouseOfRc")?.addEventListener("click", () => openHouseOfRcEventImport({
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
// Picking the drivers of a race, grouped by class: a Rookie or Junior race mixes drivers from
|
||||
// several classes (Rookie 2WD, Rookie 4WD, Junior 4WD ...), so each class gets All / None, a
|
||||
// search box filters by name or transponder, and "Only selected" checks the list. Used by the
|
||||
// new-race wizard, Manage race and the series rounds; each caller saves through onChange.
|
||||
|
||||
// Remembered between re-renders (Manage race re-renders on every tick), per picker.
|
||||
const memory = new Map();
|
||||
const remembered = (key) => {
|
||||
if (!memory.has(key)) memory.set(key, { search: "", onlySelected: false, open: new Map() });
|
||||
return memory.get(key);
|
||||
};
|
||||
|
||||
// [{ key, name, primary, drivers, selected }]: the race's own class first, then classes with
|
||||
// someone ticked, then the rest by name; drivers by name. Classless drivers go last.
|
||||
export function groupParticipantChoices(drivers = [], classes = [], { primaryClassId = "", selectedIds = [], noClassLabel = "-" } = {}) {
|
||||
const selected = new Set(selectedIds);
|
||||
const names = new Map(classes.map((item) => [item.id, item.name]));
|
||||
const groups = new Map();
|
||||
if (primaryClassId) groups.set(primaryClassId, []);
|
||||
drivers.forEach((driver) => {
|
||||
const key = names.has(driver.classId) ? driver.classId : "";
|
||||
if (!groups.has(key)) groups.set(key, []);
|
||||
groups.get(key).push(driver);
|
||||
});
|
||||
const byName = (a, b) => String(a.name || "").localeCompare(String(b.name || ""), "sv");
|
||||
return [...groups.entries()]
|
||||
.map(([key, list]) => ({
|
||||
key,
|
||||
name: key ? names.get(key) : noClassLabel,
|
||||
primary: Boolean(primaryClassId) && key === primaryClassId,
|
||||
drivers: list.slice().sort(byName),
|
||||
selected: list.filter((driver) => selected.has(driver.id)).length,
|
||||
}))
|
||||
.sort((a, b) => Number(b.primary) - Number(a.primary) || Number(Boolean(b.selected)) - Number(Boolean(a.selected)) || Number(!a.key) - Number(!b.key) || String(a.name).localeCompare(String(b.name), "sv"));
|
||||
}
|
||||
|
||||
// copySources: [{ id, label }] - earlier races whose drivers can be copied in one go.
|
||||
// inputAttrs(driver) adds the caller's own attributes to each checkbox (class, data-*).
|
||||
export function renderParticipantPicker({ pickerKey, drivers, classes, selectedIds = [], primaryClassId = "", inputAttrs = () => "", copySources = [], allId = "", noneId = "", extraActions = "", t, escapeHtml }) {
|
||||
const mem = remembered(pickerKey);
|
||||
const groups = groupParticipantChoices(drivers, classes, { primaryClassId, selectedIds, noClassLabel: t("picker.no_class") });
|
||||
const selected = new Set(selectedIds);
|
||||
const isOpen = (group) => mem.open.has(group.key) ? mem.open.get(group.key) : group.primary || group.selected > 0 || !primaryClassId;
|
||||
return `
|
||||
<div class="participant-picker" data-picker="${escapeHtml(pickerKey)}">
|
||||
<div class="participant-picker-toolbar">
|
||||
<input type="search" data-picker-search value="${escapeHtml(mem.search)}" placeholder="${escapeHtml(t("picker.search"))}" aria-label="${escapeHtml(t("picker.search"))}" />
|
||||
<label class="participant-only-selected"><input type="checkbox" data-picker-only-selected ${mem.onlySelected ? "checked" : ""} /><span>${escapeHtml(t("picker.only_selected"))}</span></label>
|
||||
<strong data-picker-total>${escapeHtml(t("picker.selected_count", { count: selected.size }))}</strong>
|
||||
</div>
|
||||
<div class="actions participant-picker-actions">
|
||||
<button ${allId ? `id="${allId}"` : ""} class="btn" type="button" data-picker-all title="${escapeHtml(t("picker.all_hint"))}">${escapeHtml(t("events.select_all_participants"))}</button>
|
||||
<button ${noneId ? `id="${noneId}"` : ""} class="btn btn-danger" type="button" data-picker-none>${escapeHtml(t("events.clear_participants"))}</button>
|
||||
${copySources.length ? `<select data-picker-copy aria-label="${escapeHtml(t("picker.copy_from"))}"><option value="">📋 ${escapeHtml(t("picker.copy_from"))}</option>${copySources.map((source) => `<option value="${escapeHtml(source.id)}">${escapeHtml(source.label)}</option>`).join("")}</select>` : ""}
|
||||
${extraActions}
|
||||
</div>
|
||||
${groups.map((group) => `
|
||||
<details class="participant-group ${group.primary ? "is-primary" : ""}" data-picker-group="${escapeHtml(group.key)}" ${isOpen(group) ? "open" : ""}>
|
||||
<summary>
|
||||
<strong>${escapeHtml(group.name)}</strong>
|
||||
<small data-picker-group-count>${escapeHtml(t("picker.group_count", { selected: group.selected, total: group.drivers.length }))}</small>
|
||||
<span class="participant-group-actions">
|
||||
<button class="btn btn-mini" type="button" data-picker-group-all>${escapeHtml(t("picker.all"))}</button>
|
||||
<button class="btn btn-mini" type="button" data-picker-group-none>${escapeHtml(t("picker.none"))}</button>
|
||||
</span>
|
||||
</summary>
|
||||
${group.drivers.length ? `<div class="check-grid">${group.drivers.map((driver) => `
|
||||
<label class="check-card" data-picker-row data-search="${escapeHtml(`${driver.name || ""} ${driver.transponder || ""}`.toLowerCase())}">
|
||||
<input type="checkbox" ${inputAttrs(driver)} value="${escapeHtml(driver.id)}" data-picker-driver ${selected.has(driver.id) ? "checked" : ""} />
|
||||
<span>${escapeHtml(driver.name)}${driver.transponder ? ` (${escapeHtml(driver.transponder)})` : ""}</span>
|
||||
</label>`).join("")}</div>`
|
||||
: `<p class="hint">${escapeHtml(t("picker.primary_empty", { name: group.name }))}</p>`}
|
||||
</details>`).join("")}
|
||||
</div>`;
|
||||
}
|
||||
|
||||
// onChange(selectedIds) after every change; getCopyIds(sourceId) gives the drivers to copy.
|
||||
export function bindParticipantPicker(root, { onChange = () => {}, getCopyIds = () => [] } = {}) {
|
||||
const picker = root?.querySelector("[data-picker]");
|
||||
if (!picker) return;
|
||||
const mem = remembered(picker.dataset.picker);
|
||||
const boxes = () => [...picker.querySelectorAll("[data-picker-driver]")];
|
||||
const visible = (box) => !box.closest("[data-picker-row]").hidden;
|
||||
const searching = () => Boolean(mem.search) || mem.onlySelected;
|
||||
const groupOf = (box) => box.closest("[data-picker-group]");
|
||||
const refreshCounts = () => {
|
||||
picker.querySelectorAll("[data-picker-group]").forEach((group) => {
|
||||
const list = [...group.querySelectorAll("[data-picker-driver]")];
|
||||
const count = group.querySelector("[data-picker-group-count]");
|
||||
if (count) count.textContent = count.textContent.replace(/^\d+/, String(list.filter((box) => box.checked).length));
|
||||
});
|
||||
const total = picker.querySelector("[data-picker-total]");
|
||||
if (total) total.textContent = total.textContent.replace(/\d+/, String(boxes().filter((box) => box.checked).length));
|
||||
};
|
||||
const applyFilter = () => {
|
||||
const needle = mem.search.trim().toLowerCase();
|
||||
picker.querySelectorAll("[data-picker-group]").forEach((group) => {
|
||||
let shown = 0;
|
||||
group.querySelectorAll("[data-picker-row]").forEach((row) => {
|
||||
const box = row.querySelector("[data-picker-driver]");
|
||||
row.hidden = (needle && !row.dataset.search.includes(needle)) || (mem.onlySelected && !box.checked);
|
||||
if (!row.hidden) shown += 1;
|
||||
});
|
||||
const hasRows = group.querySelector("[data-picker-row]");
|
||||
group.hidden = searching() && (!hasRows || !shown);
|
||||
if (searching() && shown) group.open = true;
|
||||
});
|
||||
};
|
||||
const changed = () => {
|
||||
refreshCounts();
|
||||
onChange(boxes().filter((box) => box.checked).map((box) => box.value));
|
||||
};
|
||||
const setAll = (list, value) => {
|
||||
list.forEach((box) => { box.checked = value; });
|
||||
changed();
|
||||
};
|
||||
boxes().forEach((box) => box.addEventListener("change", changed));
|
||||
picker.querySelectorAll("[data-picker-group]").forEach((group) => {
|
||||
group.addEventListener("toggle", () => { if (!searching()) mem.open.set(group.dataset.pickerGroup, group.open); });
|
||||
const inGroup = () => [...group.querySelectorAll("[data-picker-driver]")].filter(visible);
|
||||
// The buttons sit in the summary: don't fold the class while clicking them.
|
||||
group.querySelector("[data-picker-group-all]")?.addEventListener("click", (event) => { event.preventDefault(); setAll(inGroup(), true); });
|
||||
group.querySelector("[data-picker-group-none]")?.addEventListener("click", (event) => { event.preventDefault(); setAll(inGroup(), false); });
|
||||
});
|
||||
// "Select all" = the race's own class, or what the search shows - never the whole club.
|
||||
picker.querySelector("[data-picker-all]")?.addEventListener("click", () => {
|
||||
// A race without a class has no own class: then everyone shown.
|
||||
const hasPrimary = Boolean(picker.querySelector(".participant-group.is-primary"));
|
||||
setAll(searching() || !hasPrimary ? boxes().filter(visible) : boxes().filter((box) => groupOf(box)?.classList.contains("is-primary")), true);
|
||||
});
|
||||
picker.querySelector("[data-picker-none]")?.addEventListener("click", () => setAll(boxes(), false));
|
||||
picker.querySelector("[data-picker-search]")?.addEventListener("input", (event) => { mem.search = event.target.value; applyFilter(); });
|
||||
picker.querySelector("[data-picker-only-selected]")?.addEventListener("change", (event) => { mem.onlySelected = event.target.checked; applyFilter(); });
|
||||
picker.querySelector("[data-picker-copy]")?.addEventListener("change", (event) => {
|
||||
const ids = new Set(getCopyIds(event.target.value) || []);
|
||||
if (!event.target.value) return;
|
||||
boxes().forEach((box) => { box.checked = ids.has(box.value); });
|
||||
event.target.value = "";
|
||||
changed();
|
||||
});
|
||||
applyFilter();
|
||||
}
|
||||
|
||||
// Earlier races to copy drivers from: newest first, ones in the same series on top.
|
||||
export function participantCopySources(events = [], { currentEventId = "", seriesEventIds = [], getDriverIds, limit = 12 } = {}) {
|
||||
const inSeries = new Set(seriesEventIds);
|
||||
return events
|
||||
.filter((event) => event.id !== currentEventId && event.mode === "race" && !event.raceConfig?.practiceOnly)
|
||||
.map((event) => ({ event, ids: getDriverIds(event) }))
|
||||
.filter(({ ids }) => ids.length)
|
||||
.sort((a, b) => Number(inSeries.has(b.event.id)) - Number(inSeries.has(a.event.id)) || String(b.event.date || "").localeCompare(String(a.event.date || "")))
|
||||
.slice(0, limit)
|
||||
.map(({ event, ids }) => ({ id: event.id, label: `${inSeries.has(event.id) ? "🏆 " : ""}${event.date || "-"} · ${event.name} (${ids.length})` }));
|
||||
}
|
||||
+14
-19
@@ -1,3 +1,4 @@
|
||||
import { renderParticipantPicker } from "./participant_picker.js";
|
||||
import { rowFlag } from "./country_flags.js";
|
||||
import { medal, qualCell } from "./medal.js";
|
||||
export function renderRaceFormatField(labelKey, hintKey, controlHtml, options = {}, { t }) {
|
||||
@@ -102,7 +103,7 @@ export function renderRaceWizardSteps({ t, raceWizardStep, escapeHtml }) {
|
||||
.join("");
|
||||
}
|
||||
|
||||
export function renderRaceWizardContent(draft, classOptions, wizardDrivers, preset, { t, escapeHtml, raceWizardStep, getRaceFormatPresets, getClassName, getRaceWizardSessionPlan }) {
|
||||
export function renderRaceWizardContent(draft, classOptions, wizardDrivers, preset, { t, escapeHtml, raceWizardStep, getRaceFormatPresets, getClassName, getRaceWizardSessionPlan, allDrivers = wizardDrivers, classes = [], copySources = [] }) {
|
||||
if (raceWizardStep === 1) {
|
||||
return `
|
||||
<form id="raceWizardStepForm" class="form-grid cols-4">
|
||||
@@ -118,24 +119,18 @@ export function renderRaceWizardContent(draft, classOptions, wizardDrivers, pres
|
||||
}
|
||||
if (raceWizardStep === 2) {
|
||||
return `
|
||||
<div class="actions">
|
||||
<button id="wizardSelectAllParticipants" class="btn" type="button">${t("events.select_all_participants")}</button>
|
||||
<button id="wizardClearParticipants" class="btn btn-danger" type="button">${t("events.clear_participants")}</button>
|
||||
</div>
|
||||
${wizardDrivers.length ? `
|
||||
<div class="check-grid mt-16">
|
||||
${wizardDrivers
|
||||
.map(
|
||||
(driver) => `
|
||||
<label class="check-card">
|
||||
<input type="checkbox" class="wizard-participant" value="${driver.id}" ${draft.driverIds.includes(driver.id) ? "checked" : ""} />
|
||||
<span>${escapeHtml(driver.name)}${driver.transponder ? ` (${escapeHtml(driver.transponder)})` : ""}</span>
|
||||
</label>
|
||||
`
|
||||
)
|
||||
.join("")}
|
||||
</div>
|
||||
` : `<p class="hint">${t("events.wizard_no_class_drivers")}</p>`}
|
||||
${allDrivers.length ? renderParticipantPicker({
|
||||
pickerKey: "wizard",
|
||||
drivers: allDrivers,
|
||||
classes,
|
||||
selectedIds: draft.driverIds,
|
||||
primaryClassId: draft.classId || "",
|
||||
inputAttrs: () => `class="wizard-participant"`,
|
||||
copySources,
|
||||
allId: "wizardSelectAllParticipants",
|
||||
noneId: "wizardClearParticipants",
|
||||
t, escapeHtml,
|
||||
}) : `<p class="hint">${t("events.wizard_no_class_drivers")}</p>`}
|
||||
`;
|
||||
}
|
||||
if (raceWizardStep === 3) {
|
||||
|
||||
+19
-24
@@ -1,3 +1,4 @@
|
||||
import { renderParticipantPicker, bindParticipantPicker } from "./participant_picker.js";
|
||||
import { medal } from "./medal.js";
|
||||
// "Series" page: create a series/cup, pick its classes and races (or create the races in one
|
||||
// go from a list of dates), set the points table and how many results count, and follow the
|
||||
@@ -92,22 +93,20 @@ function renderRoundResultEditor(round, { t, escapeHtml, state }) {
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function renderRoundParticipants(round, { t, escapeHtml }) {
|
||||
function renderRoundParticipants(round, { t, escapeHtml, classes = [] }) {
|
||||
return `
|
||||
<div class="series-round-participants" data-round-participants="${escapeHtml(round.event.id)}">
|
||||
<div class="series-classes-head"><span>${t("series.round_participants", { count: round.participantIds.length, total: round.classDrivers.length })}</span>
|
||||
<span class="actions-inline">
|
||||
<button class="btn btn-mini" type="button" data-round-action="all">${t("series.classes_all")}</button>
|
||||
<button class="btn btn-mini" type="button" data-round-action="none">${t("series.classes_none")}</button>
|
||||
<button class="btn btn-mini" type="button" data-round-action="copy">${t("series.copy_previous")}</button>
|
||||
</span></div>
|
||||
${round.classDrivers.length ? `<div class="series-class-list">${round.classDrivers.map((driver) => `
|
||||
<label class="series-class-row ${round.participantIds.includes(driver.id) ? "is-selected" : ""}"><input type="checkbox" data-round-driver="${escapeHtml(driver.id)}" ${round.participantIds.includes(driver.id) ? "checked" : ""} /><span>${escapeHtml(driver.name)}${driver.transponder ? ` <small>${escapeHtml(driver.transponder)}</small>` : ""}</span></label>`).join("")}</div>`
|
||||
: `<p class="hint">${t("series.no_class_drivers")}</p>`}
|
||||
${(round.otherDrivers || []).length ? `<details class="series-other-drivers" ${round.classDrivers.length ? "" : "open"}><summary>${t("events.other_class_participants", { count: round.otherDrivers.length })}</summary>
|
||||
<p class="hint">${t("series.other_class_hint")}</p>
|
||||
<div class="series-class-list">${round.otherDrivers.map((driver) => `
|
||||
<label class="series-class-row"><input type="checkbox" data-round-driver="${escapeHtml(driver.id)}" /><span>${escapeHtml(driver.name)} <small>${escapeHtml(driver.className || "")}${driver.transponder ? ` · ${escapeHtml(driver.transponder)}` : ""}</small></span></label>`).join("")}</div></details>` : ""}
|
||||
<div class="series-classes-head"><span>${t("series.round_participants", { count: round.participantIds.length, total: round.classDrivers.length })}</span></div>
|
||||
${renderParticipantPicker({
|
||||
pickerKey: `round:${round.event.id}`,
|
||||
drivers: [...round.classDrivers, ...(round.otherDrivers || [])],
|
||||
classes,
|
||||
selectedIds: round.participantIds,
|
||||
primaryClassId: round.event.classId || "",
|
||||
inputAttrs: (driver) => `data-round-driver="${escapeHtml(driver.id)}"`,
|
||||
extraActions: `<button class="btn" type="button" data-round-action="copy">${t("series.copy_previous")}</button>`,
|
||||
t, escapeHtml,
|
||||
})}
|
||||
<form class="series-add-driver" data-round-add-driver>
|
||||
<input name="name" required placeholder="${escapeHtml(t("series.new_driver_name"))}" />
|
||||
<input name="transponder" placeholder="${escapeHtml(t("drivers.transponder_placeholder"))}" inputmode="numeric" />
|
||||
@@ -158,7 +157,7 @@ function renderRoundsTable(rounds, { t, escapeHtml, state }) {
|
||||
<td><span class="pill series-status-${round.status}">${t(`series.status_${round.status}`)}</span>${round.manualResult ? `<br><span class="pill series-result-pill">${t("series.result_manual")}</span>` : ""}${round.qualHeatCount ? `<br><small>${t("series.heats_made", { heats: round.qualHeatCount })}</small>` : ""}</td>
|
||||
<td><div class="series-round-actions">${action}<button class="btn btn-mini" type="button" data-round-action="result" title="${escapeHtml(t("series.result_title"))}">✎ ${t("series.result_button")}</button><button class="btn btn-mini" type="button" data-round-action="open">${t("series.open_race")}</button><button class="btn btn-mini" type="button" data-round-action="remove" title="${escapeHtml(t("series.remove_round"))}">✕</button></div></td>
|
||||
</tr>
|
||||
${expandedRoundId === round.event.id ? `<tr class="series-round-detail"><td colspan="9">${renderRoundParticipants(round, { t, escapeHtml })}</td></tr>` : ""}
|
||||
${expandedRoundId === round.event.id ? `<tr class="series-round-detail"><td colspan="9">${renderRoundParticipants(round, { t, escapeHtml, classes: state?.classes || [] })}</td></tr>` : ""}
|
||||
${resultRoundId === round.event.id ? `<tr class="series-round-detail"><td colspan="9">${renderRoundResultEditor(round, { t, escapeHtml, state })}</td></tr>` : ""}`;
|
||||
}).join("")}</tbody>
|
||||
</table></div>`;
|
||||
@@ -397,16 +396,12 @@ export function renderSeriesView(deps) {
|
||||
const detail = dom.view.querySelector("[data-round-participants]");
|
||||
if (detail) {
|
||||
const eventId = detail.dataset.roundParticipants;
|
||||
const ticked = () => [...detail.querySelectorAll("[data-round-driver]:checked")].map((box) => box.dataset.roundDriver);
|
||||
detail.querySelectorAll("[data-round-driver]").forEach((box) => box.addEventListener("change", () => { setSeriesRoundParticipants(eventId, ticked()); renderView(); }));
|
||||
detail.querySelectorAll("[data-round-action]").forEach((button) => button.addEventListener("click", () => {
|
||||
const action = button.dataset.roundAction;
|
||||
// "All" means the class's own list, not the folded drivers from other classes.
|
||||
if (action === "all") setSeriesRoundParticipants(eventId, [...detail.querySelectorAll(".series-class-list:not(.series-other-drivers *) [data-round-driver]")].map((box) => box.dataset.roundDriver));
|
||||
if (action === "none") setSeriesRoundParticipants(eventId, []);
|
||||
if (action === "copy" && !copySeriesRoundParticipants(series, eventId)) window.alert(t("series.no_previous_round"));
|
||||
// Grouped by class with All / None per class (a Rookie round mixes classes).
|
||||
bindParticipantPicker(detail, { onChange: (ids) => { setSeriesRoundParticipants(eventId, ids); renderView(); } });
|
||||
detail.querySelector("[data-round-action=copy]")?.addEventListener("click", () => {
|
||||
if (!copySeriesRoundParticipants(series, eventId)) window.alert(t("series.no_previous_round"));
|
||||
renderView();
|
||||
}));
|
||||
});
|
||||
detail.querySelector("[data-round-add-driver]")?.addEventListener("submit", (event) => {
|
||||
event.preventDefault();
|
||||
const data = new FormData(event.currentTarget);
|
||||
|
||||
@@ -5102,3 +5102,17 @@ tr.is-selected td { background: color-mix(in srgb, var(--danger) 12%, transparen
|
||||
.lap-chart { display: block; width: 100%; max-width: 820px; height: auto; font-family: var(--overlay-font, inherit); }
|
||||
.print-lap-chart { margin-top: 10px; break-inside: avoid; }
|
||||
.print-lap-chart .lap-chart { max-width: 100%; color: #222; }
|
||||
|
||||
/* Driver picker grouped by class (participant_picker.js): Manage race, new-race wizard, series rounds. */
|
||||
.participant-picker-toolbar { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin-bottom: 10px; }
|
||||
.participant-picker-toolbar input[type="search"] { flex: 1 1 220px; max-width: 340px; }
|
||||
.participant-picker-actions select { width: auto; max-width: 320px; }
|
||||
.participant-group { border: 1px solid var(--line, rgba(127,127,127,.25)); border-radius: 10px; margin-top: 10px; padding: 0 12px; }
|
||||
.participant-group.is-primary { border-color: var(--accent, #3b82f6); }
|
||||
.participant-group > summary { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 10px 0; cursor: pointer; list-style: revert; }
|
||||
.participant-group > summary small { opacity: .75; }
|
||||
.participant-group-actions { margin-left: auto; display: inline-flex; gap: 6px; }
|
||||
.participant-group > .check-grid { padding-bottom: 12px; }
|
||||
.participant-group > .hint { margin: 0 0 12px; }
|
||||
.participant-only-selected { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; cursor: pointer; }
|
||||
.participant-only-selected input { width: auto; margin: 0; }
|
||||
@@ -18,14 +18,22 @@ export async function runSeriesRookieSmoke({ evaluate, navigate, savedState, wai
|
||||
await evaluate(`document.querySelector('[data-series-select="rk_series"]')?.click()`);
|
||||
await waitFor(async () => evaluate(`Boolean(document.querySelector('tr[data-round="rk_round"]'))`), "the Rookie round is listed");
|
||||
await evaluate(`document.querySelector('tr[data-round="rk_round"] [data-round-action="toggle"]').click()`);
|
||||
await waitFor(async () => evaluate(`Boolean(document.querySelector(".series-other-drivers[open]"))`), "drivers from other classes are offered (open, the class has none)");
|
||||
assert.match(await evaluate(`document.querySelector(".series-other-drivers").textContent`), /RK Ada[\s\S]*RK 2WD[\s\S]*RK Ben[\s\S]*RK 4WD/, "each with their own class");
|
||||
for (const id of ["rk_ada", "rk_ben"]) {
|
||||
await evaluate(`(() => { const box = document.querySelector('.series-other-drivers [data-round-driver="${id}"]'); box.checked = true; box.dispatchEvent(new Event("change")); })()`);
|
||||
await waitFor(async () => (await driverIds()).includes(id), `${id} ticked for the Rookie round`);
|
||||
}
|
||||
// Grouped by class: the Rookie class (empty) first, then each driver under their own class.
|
||||
await waitFor(async () => evaluate(`Boolean(document.querySelector('[data-round-participants] [data-picker-group="rk_rookie"].is-primary'))`), "the Rookie class is offered first (it has no drivers)");
|
||||
assert.match(await evaluate(`document.querySelector("[data-round-participants]").textContent`), /RK 2WD[\s\S]*RK Ada[\s\S]*RK 4WD[\s\S]*RK Ben/, "each driver under their own class");
|
||||
// "All" on one class, a single tick in the other.
|
||||
await evaluate(`document.querySelector('[data-round-participants] [data-picker-group="rk_2wd"] [data-picker-group-all]').click()`);
|
||||
await waitFor(async () => (await driverIds()).includes("rk_ada"), "All on RK 2WD ticks Ada for the Rookie round");
|
||||
await evaluate(`(() => { const box = document.querySelector('[data-round-participants] [data-round-driver="rk_ben"]'); box.checked = true; box.dispatchEvent(new Event("change")); })()`);
|
||||
await waitFor(async () => (await driverIds()).includes("rk_ben"), "Ben ticked for the Rookie round");
|
||||
const state = await savedState();
|
||||
assert.deepEqual(state.drivers.filter((driver) => /^RK (Ada|Ben)$/.test(driver.name)).map((driver) => driver.id).sort(), ["rk_ada", "rk_ben"], "no driver registered again");
|
||||
await waitFor(async () => evaluate(`Boolean(document.querySelector('.series-round-participants > .series-class-list [data-round-driver="rk_ben"]:checked'))`), "a ticked rookie moves to the round's own list");
|
||||
await waitFor(async () => evaluate(`Boolean(document.querySelector('[data-round-participants] [data-picker-group="rk_4wd"][open] [data-round-driver="rk_ben"]:checked'))`), "a class with a ticked rookie stays open");
|
||||
// Select all takes only the Rookie class itself (none), never the whole club.
|
||||
await evaluate(`document.querySelector('[data-round-participants] [data-picker-none]').click()`);
|
||||
await waitFor(async () => (await driverIds()).length === 0, "Clear empties the round");
|
||||
await evaluate(`document.querySelector('[data-round-participants] [data-picker-all]').click()`);
|
||||
await new Promise((resolve) => setTimeout(resolve, 600));
|
||||
assert.equal((await driverIds()).length, 0, "Select all on an empty Rookie class ticks nobody from the other classes");
|
||||
console.log("PASS a Rookie round in a series takes 2WD and 4WD drivers from their own classes without registering them again");
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { groupParticipantChoices, participantCopySources, renderParticipantPicker } from "../src/participant_picker.js";
|
||||
|
||||
const classes = [{ id: "r", name: "Rookie" }, { id: "b2", name: "Rookie 2WD" }, { id: "b4", name: "Rookie 4WD" }, { id: "j4", name: "Junior 4WD" }];
|
||||
const drivers = [
|
||||
{ id: "1", name: "Ola", classId: "b2" }, { id: "2", name: "Ada", classId: "b2" },
|
||||
{ id: "3", name: "Kim", classId: "b4" }, { id: "4", name: "Eli", classId: "j4" }, { id: "5", name: "Noa", classId: "" },
|
||||
];
|
||||
const escapeHtml = (v) => String(v).replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c]);
|
||||
const t = (key, params = {}) => key.replace(/\{(\w+)\}/g, (_, k) => params[k]) + Object.values(params).join(" ");
|
||||
|
||||
test("drivers are grouped by class: the race's own class first (even empty), then classes with someone ticked", () => {
|
||||
const groups = groupParticipantChoices(drivers, classes, { primaryClassId: "r", selectedIds: ["4"], noClassLabel: "No class" });
|
||||
assert.deepEqual(groups.map((g) => g.name), ["Rookie", "Junior 4WD", "Rookie 2WD", "Rookie 4WD", "No class"]);
|
||||
assert.equal(groups[0].primary, true);
|
||||
assert.equal(groups[0].drivers.length, 0);
|
||||
assert.deepEqual(groups.find((g) => g.key === "b2").drivers.map((d) => d.name), ["Ada", "Ola"]);
|
||||
assert.equal(groups.find((g) => g.key === "j4").selected, 1);
|
||||
});
|
||||
|
||||
test("the picker renders a checkbox per driver with the caller's attributes, checked as selected", () => {
|
||||
const html = renderParticipantPicker({ pickerKey: "x", drivers, classes, selectedIds: ["1"], primaryClassId: "b2", inputAttrs: () => 'class="race-participant"', t, escapeHtml });
|
||||
assert.equal((html.match(/class="race-participant"/g) || []).length, 5);
|
||||
assert.match(html, /class="race-participant" value="1" data-picker-driver checked/);
|
||||
assert.match(html, /data-picker-group="b2" open/, "own class open");
|
||||
assert.doesNotMatch(html, /data-picker-group="j4" open/, "other classes folded");
|
||||
});
|
||||
|
||||
test("copy sources: earlier races with drivers, the series' rounds first, then newest", () => {
|
||||
const events = [
|
||||
{ id: "a", mode: "race", name: "Club", date: "2026-10-01" },
|
||||
{ id: "b", mode: "race", name: "Cup 1", date: "2026-09-01" },
|
||||
{ id: "c", mode: "race", name: "Empty", date: "2026-11-01" },
|
||||
{ id: "d", mode: "track", name: "Practice", date: "2026-11-02" },
|
||||
{ id: "me", mode: "race", name: "Cup 2", date: "2026-11-10" },
|
||||
];
|
||||
const ids = { a: ["1"], b: ["1", "2"], c: [], d: ["3"], me: ["4"] };
|
||||
const sources = participantCopySources(events, { currentEventId: "me", seriesEventIds: ["b", "me"], getDriverIds: (e) => ids[e.id] });
|
||||
assert.deepEqual(sources.map((s) => s.id), ["b", "a"]);
|
||||
assert.equal(sources[0].label, "🏆 2026-09-01 · Cup 1 (2)");
|
||||
});
|
||||
@@ -10,6 +10,7 @@ import "./practice_rank.test.js";
|
||||
import "./team_race_logic.test.js";
|
||||
import "./race_overview.test.js";
|
||||
import "./lap_chart.test.js";
|
||||
import "./participant_picker.test.js";
|
||||
import "./leader_call_logic.test.js";
|
||||
import "./decoder_sim.test.js";
|
||||
import "./sponsor_event.test.js";
|
||||
|
||||
Reference in new issue
Block a user