feat(houseofrc): preview and send results to the event's entries, heats or final placings (1.83.0)
This commit is contained in:
1 parent
f4a62b92d2
commit
ebdc6104e6
17 files changed
+295
-15
No files matched your search
+60
-1
@@ -1,4 +1,4 @@
|
||||
import { planHouseOfRcDriverUpdates, applyHouseOfRcDriverUpdates, planHouseOfRcEntries, applyHouseOfRcEntries, matchHouseOfRcClass, rememberHouseOfRcClass, diffHouseOfRcEntries, applyHouseOfRcEntryChanges } from "./houseofrc_logic.js";
|
||||
import { planHouseOfRcDriverUpdates, applyHouseOfRcDriverUpdates, planHouseOfRcEntries, applyHouseOfRcEntries, matchHouseOfRcClass, rememberHouseOfRcClass, diffHouseOfRcEntries, applyHouseOfRcEntryChanges, buildHouseOfRcResults } 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).
|
||||
@@ -20,7 +20,11 @@ export function describeHouseOfRcError(t, code, body = {}) {
|
||||
timeout: "houseofrc.err_unreachable",
|
||||
unreachable: "houseofrc.err_unreachable",
|
||||
invalid_key: "houseofrc.err_invalid_key",
|
||||
not_your_event: "houseofrc.err_not_your_event",
|
||||
event_not_found: "houseofrc.err_event_not_found",
|
||||
invalid_event: "houseofrc.err_event_not_found",
|
||||
}[body.error];
|
||||
if (body.error === "rejected") return t("houseofrc.err_rejected", { message: [body.message, ...Object.values(body.errors || {}).flat()].filter(Boolean).join(" ") || "422" });
|
||||
return key ? t(key, { seconds: body.retryAfter || 60 }) : t("houseofrc.err_other", { status: body.status || code });
|
||||
}
|
||||
|
||||
@@ -346,3 +350,58 @@ export async function openHouseOfRcEntryRefresh({ event, state, t, escapeHtml, m
|
||||
onApply(selectedIds);
|
||||
});
|
||||
}
|
||||
|
||||
// Manage → "Send results to House of RC": a preview of what goes to each entry, then one
|
||||
// all-or-nothing write. "Heats" leaves out the final placings, so nobody is notified yet
|
||||
// and it can be sent after every heat; "Final results" adds them.
|
||||
export function openHouseOfRcResultsPost({ event, overview, state, t, escapeHtml, saveState }) {
|
||||
const { body, close } = openHorModal({ id: "houseOfRcResultsOverlay", title: t("houseofrc.results_title"), escapeHtml });
|
||||
const hasFinals = Boolean(overview?.phases?.find((phase) => phase.type === "final")?.standings?.length);
|
||||
let final = hasFinals && Boolean(overview?.finished);
|
||||
const render = () => {
|
||||
const { entries, rows, missing } = buildHouseOfRcResults(event, overview, { final, drivers: state.drivers });
|
||||
const where = [event.houseOfRc.name, event.houseOfRc.className].filter(Boolean).join(" – ");
|
||||
body.innerHTML = `
|
||||
<p><strong>${escapeHtml(where)}</strong>${event.houseOfRc.resultsSentAt ? ` <span class="hint">· ${escapeHtml(t("houseofrc.results_last", { time: new Date(event.houseOfRc.resultsSentAt).toLocaleString() }))}</span>` : ""}</p>
|
||||
<div class="hor-choice">
|
||||
<label><input type="radio" name="horResultsMode" value="heats" ${final ? "" : "checked"} /> ${escapeHtml(t("houseofrc.results_mode_heats"))}</label>
|
||||
<label><input type="radio" name="horResultsMode" value="final" ${final ? "checked" : ""} ${hasFinals ? "" : "disabled"} /> ${escapeHtml(t("houseofrc.results_mode_final"))}</label>
|
||||
</div>
|
||||
<p class="hint">${escapeHtml(t(final ? "houseofrc.results_final_hint" : "houseofrc.results_heats_hint"))}</p>
|
||||
<div class="table-wrap"><table class="hor-import-table">
|
||||
<thead><tr><th>${escapeHtml(t("houseofrc.results_col_driver"))}</th><th>${escapeHtml(t("houseofrc.results_col_qual"))}</th><th>${escapeHtml(t("houseofrc.results_col_final"))}</th><th>${escapeHtml(t("houseofrc.results_col_heats"))}</th><th>${escapeHtml(t("houseofrc.results_col_best"))}</th></tr></thead>
|
||||
<tbody>${rows.map((row) => `<tr data-hor-result-row>
|
||||
<td>${escapeHtml(row.name)}</td>
|
||||
<td>${row.qualification === 1 ? "TQ" : escapeHtml(String(row.qualification ?? "–"))}</td>
|
||||
<td>${row.ranking ? escapeHtml(`${row.ranking} (${row.main})`) : "–"}${row.lapsTime ? ` <span class="hint">${escapeHtml(row.lapsTime)}</span>` : ""}</td>
|
||||
<td>${row.heats}</td><td>${escapeHtml(row.bestLap || "–")}</td>
|
||||
</tr>`).join("")}</tbody></table></div>
|
||||
${missing.length ? `<p class="hint">⚠️ ${escapeHtml(t("houseofrc.results_missing", { names: missing.join(", ") }))}</p>` : ""}
|
||||
<p data-hor-result-status></p>
|
||||
<div class="actions mt-16">
|
||||
<button class="btn btn-primary" type="button" data-hor-send ${entries.length ? "" : "disabled"}>📤 ${escapeHtml(t("houseofrc.results_send", { count: entries.length }))}</button>
|
||||
<button class="btn" type="button" data-hor-close>${escapeHtml(t("houseofrc.results_close"))}</button>
|
||||
</div>`;
|
||||
body.querySelectorAll("[name=horResultsMode]").forEach((radio) => radio.addEventListener("change", () => { final = radio.value === "final"; render(); }));
|
||||
body.querySelector("[data-hor-send]").addEventListener("click", async (click) => {
|
||||
const button = click.currentTarget;
|
||||
const statusLine = body.querySelector("[data-hor-result-status]");
|
||||
button.disabled = true;
|
||||
statusLine.textContent = t("houseofrc.results_sending");
|
||||
const { status: code, body: data } = await postJson("/api/houseofrc/results", { eventId: event.houseOfRc.eventId, entries });
|
||||
if (code !== 200 || !data.ok) {
|
||||
statusLine.className = "error";
|
||||
statusLine.textContent = describeHouseOfRcError(t, code, data);
|
||||
button.disabled = false;
|
||||
return;
|
||||
}
|
||||
event.houseOfRc.resultsSentAt = new Date().toISOString();
|
||||
event.houseOfRc.resultsSentFinal = final;
|
||||
saveState();
|
||||
statusLine.className = "";
|
||||
statusLine.textContent = `✅ ${t("houseofrc.results_sent", { count: data.updated })}`;
|
||||
});
|
||||
};
|
||||
render();
|
||||
return { close };
|
||||
}
|
||||
Reference in new issue
Block a user