feat(houseofrc): re-fetch late entries and withdrawals, remember class mapping, offer brand differences (1.82.0)

This commit is contained in:
larssand committed 2026-11-08 19:04:27 +01:00
1 parent cdeb6b0402
commit f4a62b92d2
13 files changed
+240 -28

No files matched your search

+60 -5
View File
@@ -1,4 +1,4 @@
import { planHouseOfRcDriverUpdates, applyHouseOfRcDriverUpdates, planHouseOfRcEntries, applyHouseOfRcEntries, matchHouseOfRcClass } from "./houseofrc_logic.js";
import { planHouseOfRcDriverUpdates, applyHouseOfRcDriverUpdates, planHouseOfRcEntries, applyHouseOfRcEntries, matchHouseOfRcClass, rememberHouseOfRcClass, diffHouseOfRcEntries, applyHouseOfRcEntryChanges } from "./houseofrc_logic.js";
// Settings → System → House of RC: save the club's API key on the server and test it.
// The key is never read back; the server only tells whether one is set (and its last 4 chars).
@@ -235,9 +235,14 @@ export function openHouseOfRcEventImport({ state, t, escapeHtml, uid, saveState,
const NEW_CLASS = "__new__";
let horClassId = classes.find((item) => entries.some((entry) => entry.classId === item.id))?.id ?? classes[0]?.id;
let ourClassId = null;
let matchedHow = "";
const render = () => {
const horClass = classes.find((item) => item.id === horClassId);
if (ourClassId === null) ourClassId = matchHouseOfRcClass(state.classes, horClass?.name) || NEW_CLASS;
if (ourClassId === null) {
const match = matchHouseOfRcClass(state.classes, horClass?.name);
ourClassId = match.id || NEW_CLASS;
matchedHow = match.how;
}
const classEntries = entries.filter((entry) => entry.classId === horClassId);
const plan = ourClassId === NEW_CLASS ? planHouseOfRcEntries(classEntries, state.drivers, "") : planHouseOfRcEntries(classEntries, state.drivers, ourClassId);
const count = (id) => entries.filter((entry) => entry.classId === id).length;
@@ -252,6 +257,7 @@ export function openHouseOfRcEventImport({ state, t, escapeHtml, uid, saveState,
${state.classes.map((item) => `<option value="${escapeHtml(item.id)}" ${item.id === ourClassId ? "selected" : ""}>${escapeHtml(item.name)}</option>`).join("")}
<option value="${NEW_CLASS}" ${ourClassId === NEW_CLASS ? "selected" : ""}>➕ ${escapeHtml(t("houseofrc.entries_new_class", { name: horClass?.name || "" }))}</option>
</select>
${matchedHow ? `<small><span class="pill ${matchedHow === "guess" ? "pill-warn" : "pill-green"}" data-hor-class-how="${matchedHow}">${escapeHtml(t(`houseofrc.class_${matchedHow}`))}</span></small>` : ""}
</label>
</div>
${classEntries.length ? `
@@ -261,7 +267,9 @@ export function openHouseOfRcEventImport({ state, t, escapeHtml, uid, saveState,
<td><input type="checkbox" data-hor-entry="${index}" checked /></td>
<td>${escapeHtml(row.entry.name)}${row.entry.number != null ? ` <small>#${escapeHtml(String(row.entry.number))}</small>` : ""}</td>
<td>${escapeHtml(row.entry.club || "–")}</td>
<td>${escapeHtml(row.entry.car || "–")}</td>
<td>${row.brandDiffers
? `<label class="hor-choice" title="${escapeHtml(t("houseofrc.entries_brand_hint"))}"><input type="checkbox" data-hor-brand="${index}" ${row.brandDefault ? "checked" : ""} /> <span><s>${escapeHtml(row.currentBrand || "–")}</s> → <strong>${escapeHtml(row.entry.car)}</strong></span></label>`
: escapeHtml(row.entry.car || row.currentBrand || "–")}</td>
<td>${escapeHtml(row.transponder || "–")}</td>
<td><span class="pill ${row.status === "new" ? "pill-warn" : "pill-green"}">${escapeHtml(t(`houseofrc.entry_${row.status}`))}</span></td>
</tr>`).join("")}</tbody>
@@ -271,7 +279,7 @@ export function openHouseOfRcEventImport({ state, t, escapeHtml, uid, saveState,
: `<p class="mt-16">${escapeHtml(t("houseofrc.entries_empty"))}</p>${back}`}`;
bindBack();
body.querySelector("[data-hor-source-class]").addEventListener("change", (change) => { horClassId = Number(change.target.value); ourClassId = null; render(); });
body.querySelector("[data-hor-class]").addEventListener("change", (change) => { ourClassId = change.target.value; render(); });
body.querySelector("[data-hor-class]").addEventListener("change", (change) => { ourClassId = change.target.value; matchedHow = ""; render(); });
body.querySelector("[data-hor-all]")?.addEventListener("change", (change) => body.querySelectorAll("[data-hor-entry]").forEach((box) => { box.checked = change.target.checked; }));
body.querySelector("[data-hor-apply]")?.addEventListener("click", () => {
let classId = ourClassId;
@@ -280,7 +288,9 @@ export function openHouseOfRcEventImport({ state, t, escapeHtml, uid, saveState,
state.classes.push({ id: classId, name: horClass?.name || event.name });
}
const selected = new Set([...body.querySelectorAll("[data-hor-entry]:checked")].map((box) => Number(box.dataset.horEntry)));
const { driverIds, entryIds } = applyHouseOfRcEntries(state.drivers, plan, { classId, selected, makeDriver });
const brands = new Set([...body.querySelectorAll("[data-hor-brand]:checked")].map((box) => Number(box.dataset.horBrand)));
rememberHouseOfRcClass(state.classes, classId, horClass?.name || "");
const { driverIds, entryIds } = applyHouseOfRcEntries(state.drivers, plan, { classId, selected, makeDriver, brands });
saveState();
close();
onImported({ event, horClass, classId, driverIds, entryIds });
@@ -291,3 +301,48 @@ export function openHouseOfRcEventImport({ state, t, escapeHtml, uid, saveState,
showEvents();
}
// Manage → "Fetch entry changes": late entries to add, withdrawn drivers to take out (ticked).
// The caller applies the new participant list the same way as ticking participants by hand,
// so only heats that haven't run change.
export async function openHouseOfRcEntryRefresh({ event, state, t, escapeHtml, makeDriver, onApply }) {
const { overlay, body, close } = openHorModal({ id: "houseOfRcRefreshOverlay", title: t("houseofrc.refresh_title"), escapeHtml });
body.innerHTML = `<p class="hint">${escapeHtml(t("houseofrc.entries_loading"))}</p>`;
const { status: code, body: data } = await postJson("/api/houseofrc/entries", { eventId: String(event.houseOfRc.eventId) });
if (!overlay.isConnected) return;
if (code !== 200 || !data.ok) {
body.innerHTML = `<p class="error">${escapeHtml(describeHouseOfRcError(t, code, data))}</p>`;
return;
}
const diff = diffHouseOfRcEntries(event, data.entries, state.drivers);
const where = [event.houseOfRc.name, event.houseOfRc.className].filter(Boolean).join(" – ");
if (!diff.added.length && !diff.withdrawn.length) {
body.innerHTML = `<p><strong>${escapeHtml(where)}</strong></p><p>✅ ${escapeHtml(t("houseofrc.refresh_nothing"))}</p>`;
return;
}
body.innerHTML = `
<p><strong>${escapeHtml(where)}</strong></p>
${diff.added.length ? `<h4>➕ ${escapeHtml(t("houseofrc.refresh_added", { count: diff.added.length }))}</h4>
<div class="table-wrap"><table class="hor-import-table"><tbody>${diff.added.map((row, index) => `<tr>
<td><input type="checkbox" data-hor-add="${index}" checked /></td>
<td>${escapeHtml(row.entry.name)}</td><td>${escapeHtml(row.entry.club || "–")}</td><td>${escapeHtml(row.entry.car || "–")}</td><td>${escapeHtml(row.transponder || "–")}</td>
<td><span class="pill ${row.status === "new" ? "pill-warn" : "pill-green"}">${escapeHtml(t(`houseofrc.entry_${row.status}`))}</span></td>
</tr>`).join("")}</tbody></table></div>` : ""}
${diff.withdrawn.length ? `<h4 class="mt-16">➖ ${escapeHtml(t("houseofrc.refresh_withdrawn", { count: diff.withdrawn.length }))}</h4>
<div class="table-wrap"><table class="hor-import-table"><tbody>${diff.withdrawn.map((driver) => `<tr>
<td><input type="checkbox" data-hor-remove="${escapeHtml(driver.id)}" checked /></td>
<td>${escapeHtml(driver.name)}</td><td>${escapeHtml(driver.transponder || "–")}</td>
</tr>`).join("")}</tbody></table></div>` : ""}
<p class="hint">${escapeHtml(t("houseofrc.refresh_note"))}</p>
<div class="actions mt-16">
<button class="btn btn-primary" type="button" data-hor-apply>${escapeHtml(t("houseofrc.refresh_apply"))}</button>
<button class="btn" type="button" data-hor-close>${escapeHtml(t("common.cancel"))}</button>
</div>`;
body.querySelector("[data-hor-apply]").addEventListener("click", () => {
const addIndexes = new Set([...body.querySelectorAll("[data-hor-add]:checked")].map((box) => Number(box.dataset.horAdd)));
const removeIds = new Set([...body.querySelectorAll("[data-hor-remove]:checked")].map((box) => box.dataset.horRemove));
const selectedIds = applyHouseOfRcEntryChanges(event, state.drivers, diff, { addIndexes, removeIds, makeDriver });
close();
onApply(selectedIds);
});
}