feat(series): correct a round's result by hand (1.48.0)
This commit is contained in:
1 parent
6142bceca9
commit
e199f3aa1a
11 files changed
+178
-14
No files matched your search
+68
-5
@@ -63,6 +63,33 @@ function renderSeriesForm(series, { t, escapeHtml, state }) {
|
||||
}
|
||||
|
||||
let expandedRoundId = "";
|
||||
// The round whose result is being set by hand, and the order being edited (driver ids).
|
||||
let resultRoundId = "";
|
||||
let resultDraft = [];
|
||||
|
||||
function renderRoundResultEditor(round, { t, escapeHtml, state }) {
|
||||
const name = (driverId) => state.drivers.find((driver) => driver.id === driverId)?.name
|
||||
|| round.calculatedResult.find((row) => row.driverId === driverId)?.driverName || driverId;
|
||||
const others = round.classDrivers.filter((driver) => !resultDraft.includes(driver.id));
|
||||
return `
|
||||
<div class="series-round-result" data-round-result="${escapeHtml(round.event.id)}">
|
||||
<strong>${t("series.result_title")}</strong>
|
||||
<p class="hint">${t("series.result_hint")}</p>
|
||||
<ol class="series-result-list">${resultDraft.map((driverId, index) => `
|
||||
<li data-result-driver="${escapeHtml(driverId)}"><span class="series-result-place">${index + 1}</span><span>${escapeHtml(name(driverId))}</span>
|
||||
<span class="actions-inline">
|
||||
<button class="btn btn-mini" type="button" data-result-move="up" ${index ? "" : "disabled"} aria-label="${escapeHtml(t("series.result_up"))}">▲</button>
|
||||
<button class="btn btn-mini" type="button" data-result-move="down" ${index < resultDraft.length - 1 ? "" : "disabled"} aria-label="${escapeHtml(t("series.result_down"))}">▼</button>
|
||||
<button class="btn btn-mini" type="button" data-result-move="remove" aria-label="${escapeHtml(t("series.result_remove"))}">✕</button>
|
||||
</span></li>`).join("")}</ol>
|
||||
${others.length ? `<label class="series-result-add"><span>${t("series.result_add")}</span><select data-result-add><option value=""></option>${others.map((driver) => `<option value="${escapeHtml(driver.id)}">${escapeHtml(driver.name)}</option>`).join("")}</select></label>` : ""}
|
||||
<div class="actions-inline">
|
||||
<button class="btn btn-primary btn-mini" type="button" data-result-action="save" ${resultDraft.length ? "" : "disabled"}>${t("series.result_save")}</button>
|
||||
${round.manualResult ? `<button class="btn btn-mini" type="button" data-result-action="clear">${t("series.result_clear")}</button>` : ""}
|
||||
<button class="btn btn-mini" type="button" data-result-action="cancel">${t("common.cancel")}</button>
|
||||
</div>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function renderRoundParticipants(round, { t, escapeHtml }) {
|
||||
return `
|
||||
@@ -105,7 +132,7 @@ function renderNextStep(round, { t, escapeHtml }) {
|
||||
return "";
|
||||
}
|
||||
|
||||
function renderRoundsTable(rounds, { t, escapeHtml }) {
|
||||
function renderRoundsTable(rounds, { t, escapeHtml, state }) {
|
||||
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"} />`;
|
||||
return `
|
||||
@@ -123,10 +150,11 @@ function renderRoundsTable(rounds, { t, escapeHtml }) {
|
||||
<td>${number(round, "finalLegs", config.finalLegs || 1, 1)}</td>
|
||||
<td>${number(round, "carsPerHeat", config.carsPerHeat || 8, 2)}</td>
|
||||
<td>${number(round, "seedGroupSize", config.seedGroupSize || 0, 0)}</td>
|
||||
<td><span class="pill series-status-${round.status}">${t(`series.status_${round.status}`)}</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="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>
|
||||
<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 })}</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>`;
|
||||
}
|
||||
@@ -200,7 +228,7 @@ export function renderSeriesView(deps) {
|
||||
<div class="series-create-actions"><button class="btn btn-primary" type="submit" ${series.classIds.length ? "" : "disabled"}>${t("series.create_events")}</button></div>
|
||||
</form>
|
||||
${series.classIds.length ? "" : `<p class="hint">${t("series.pick_classes_first")}</p>`}
|
||||
<div class="mt-16">${renderRoundsTable(rounds, { t, escapeHtml })}</div>
|
||||
<div class="mt-16">${renderRoundsTable(rounds, { t, escapeHtml, state })}</div>
|
||||
${renderAddExistingRace(series, rounds, { t, escapeHtml, state, getClassName })}
|
||||
</div>
|
||||
</section>
|
||||
@@ -313,6 +341,13 @@ export function renderSeriesView(deps) {
|
||||
row.querySelectorAll("[data-round-action]").forEach((button) => button.addEventListener("click", () => {
|
||||
const action = button.dataset.roundAction;
|
||||
if (action === "toggle") expandedRoundId = expandedRoundId === eventId ? "" : eventId;
|
||||
if (action === "result") {
|
||||
// Starts from the hand-set order, else the calculated one, else the entry list.
|
||||
const round = rounds.find((item) => item.event.id === eventId);
|
||||
resultRoundId = resultRoundId === eventId ? "" : eventId;
|
||||
resultDraft = [...(round?.manualResult || round?.calculatedResult.map((row) => row.driverId) || [])];
|
||||
if (!resultDraft.length) resultDraft = [...(round?.participantIds || [])];
|
||||
}
|
||||
if (action === "open") { openSeriesRound(eventId); return; }
|
||||
if (action === "run") { runSeriesSession(button.dataset.roundSession); return; }
|
||||
if (action === "seeding") { runSeriesSeeding(eventId); return; }
|
||||
@@ -326,6 +361,34 @@ export function renderSeriesView(deps) {
|
||||
renderView();
|
||||
}));
|
||||
});
|
||||
const resultEditor = dom.view.querySelector("[data-round-result]");
|
||||
if (resultEditor) {
|
||||
const eventId = resultEditor.dataset.roundResult;
|
||||
resultEditor.querySelectorAll("[data-result-move]").forEach((button) => button.addEventListener("click", () => {
|
||||
const index = resultDraft.indexOf(button.closest("[data-result-driver]").dataset.resultDriver);
|
||||
const move = button.dataset.resultMove;
|
||||
if (move === "remove") resultDraft.splice(index, 1);
|
||||
const other = move === "up" ? index - 1 : move === "down" ? index + 1 : -1;
|
||||
if (other >= 0 && other < resultDraft.length) [resultDraft[index], resultDraft[other]] = [resultDraft[other], resultDraft[index]];
|
||||
renderView();
|
||||
}));
|
||||
resultEditor.querySelector("[data-result-add]")?.addEventListener("change", (event) => {
|
||||
if (event.target.value) resultDraft.push(event.target.value);
|
||||
renderView();
|
||||
});
|
||||
resultEditor.querySelectorAll("[data-result-action]").forEach((button) => button.addEventListener("click", () => {
|
||||
const action = button.dataset.resultAction;
|
||||
if (action === "save") series.manualResults = { ...(series.manualResults || {}), [eventId]: [...resultDraft] };
|
||||
if (action === "clear") {
|
||||
if (!window.confirm(t("series.result_clear_confirm"))) return;
|
||||
const { [eventId]: _removed, ...rest } = series.manualResults || {};
|
||||
series.manualResults = rest;
|
||||
}
|
||||
if (action !== "cancel") saveState();
|
||||
resultRoundId = "";
|
||||
renderView();
|
||||
}));
|
||||
}
|
||||
const detail = dom.view.querySelector("[data-round-participants]");
|
||||
if (detail) {
|
||||
const eventId = detail.dataset.roundParticipants;
|
||||
|
||||
Reference in new issue
Block a user