add more stats to mobile and fix refresh stint
This commit is contained in:
1 parent
4068cc7c19
commit
285babcfcf
10 files changed
+370
-23
No files matched your search
+48
-2
@@ -64,6 +64,14 @@ const messages = {
|
||||
stintNumber: "Stint",
|
||||
duration: "Tid",
|
||||
noStints: "Inga stintar registrerade ännu.",
|
||||
paceBlocks: "Tempo per aktivt 30-minutersblock",
|
||||
paceBlocksHint: "Visar bara block där bilen har registrerat giltiga varv.",
|
||||
markerTitle: "Markera en biländring",
|
||||
markerHint: "Sparas för vald förare och klass vid aktuell tid.",
|
||||
markerType: "Typ", markerNote: "Beskrivning", markerSave: "Markera ändring nu",
|
||||
markerSetup: "Ny setup", markerTires: "Däck", markerSuspension: "Dämpare", markerCar: "Bil", markerNoteType: "Anteckning",
|
||||
markerSaved: "Biländringen är sparad.", markerError: "Kunde inte spara biländringen.",
|
||||
blockLaps: "{laps} varv", blockMarkers: "{count} ändring(ar)",
|
||||
stints: "Stints",
|
||||
bestThree: "Bästa 3 sammanhängande",
|
||||
bestFive: "Bästa 5 min",
|
||||
@@ -176,6 +184,14 @@ const messages = {
|
||||
stintNumber: "Stint",
|
||||
duration: "Duration",
|
||||
noStints: "No stints have been recorded yet.",
|
||||
paceBlocks: "Pace per active 30-minute block",
|
||||
paceBlocksHint: "Only blocks containing valid recorded laps are shown.",
|
||||
markerTitle: "Mark a car change",
|
||||
markerHint: "Saved for the selected driver and class at the current time.",
|
||||
markerType: "Type", markerNote: "Description", markerSave: "Mark change now",
|
||||
markerSetup: "New setup", markerTires: "Tires", markerSuspension: "Suspension", markerCar: "Car", markerNoteType: "Note",
|
||||
markerSaved: "The car change was saved.", markerError: "The car change could not be saved.",
|
||||
blockLaps: "{laps} laps", blockMarkers: "{count} change(s)",
|
||||
stints: "Stints",
|
||||
bestThree: "Best 3 consecutive",
|
||||
bestFive: "Best 5 min",
|
||||
@@ -332,6 +348,7 @@ function renderPaceChart(points) {
|
||||
return `<div class="profile-pace-chart"><svg viewBox="0 0 ${width} ${height}" role="img" aria-label="${escapeHtml(t("paceChart"))}"><polyline class="profile-pace-line" points="${path}" />${coordinates.map((item) => `<circle cx="${item.x.toFixed(1)}" cy="${item.y.toFixed(1)}" r="5"><title>${escapeHtml(item.point.dateKey)}: ${escapeHtml(formatLap(item.point.averageLapMs))}</title></circle>`).join("")}</svg><div class="profile-chart-labels"><span>${escapeHtml(values[0].dateKey)}</span><strong>${escapeHtml(formatLap(values.at(-1).averageLapMs))}</strong><span>${escapeHtml(values.at(-1).dateKey)}</span></div></div>`;
|
||||
}
|
||||
function renderProfile(data) {
|
||||
const openSections = new Set([...root.querySelectorAll("details[data-persist-open][open]")].map((element) => element.dataset.persistOpen));
|
||||
profileData = data;
|
||||
const { profile, branding } = data;
|
||||
const visibility = { progress: true, achievements: true, performance: true, goals: true, history: true, ...(data.visibility || {}) };
|
||||
@@ -404,6 +421,8 @@ function renderProfile(data) {
|
||||
</tr>
|
||||
`).join("")
|
||||
: `<tr><td colspan="4">-</td></tr>`;
|
||||
const paceBuckets = Array.isArray(stats.paceBuckets) ? stats.paceBuckets : [];
|
||||
const paceBucketMarkup = paceBuckets.length ? paceBuckets.map((bucket) => `<article><span>${escapeHtml(new Date(bucket.startTs).toLocaleString(language, { dateStyle: "short", timeStyle: "short" }))}</span><strong>${formatLap(bucket.paceMs)}</strong><small>${escapeHtml(t("blockLaps", { laps: bucket.lapCount }))} · PB ${formatLap(bucket.bestLapMs)}${bucket.markerCount ? " · " + escapeHtml(t("blockMarkers", { count: bucket.markerCount })) : ""}</small></article>`).join("") : `<p class="profile-empty">-</p>`;
|
||||
const stintRows = stats.stintSummaries.length ? stats.stintSummaries.slice(0, 6).map((stint) => `
|
||||
<tr><td>${stint.number}</td><td>${escapeHtml(new Date(stint.startedAt).toLocaleString(language, { dateStyle: "short", timeStyle: "short" }))}</td><td>${stint.lapCount}</td><td>${formatLap(stint.bestLapMs)}</td><td>${formatLap(stint.averageLapMs)}</td><td>${formatRaceResultTime(stint.durationMs)}</td></tr>
|
||||
`).join("") : `<tr><td colspan="6">${escapeHtml(t("noStints"))}</td></tr>`;
|
||||
@@ -510,8 +529,15 @@ function renderProfile(data) {
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<details class="profile-card profile-disclosure profile-performance ${visibility.performance ? "" : "is-hidden"}" style="margin-top:14px">
|
||||
<details class="profile-card profile-disclosure profile-performance ${visibility.performance ? "" : "is-hidden"}" data-persist-open="performance" ${openSections.has("performance") ? "open" : ""} style="margin-top:14px">
|
||||
<summary class="profile-card-head"><h2>${escapeHtml(t("performance"))}</h2><span>+</span></summary>
|
||||
<form id="publicTrainingMarkerForm" class="profile-marker-form">
|
||||
<div><h3>${escapeHtml(t("markerTitle"))}</h3><p>${escapeHtml(t("markerHint"))}</p></div>
|
||||
<label><span>${escapeHtml(t("markerType"))}</span><select name="type"><option value="setup">${escapeHtml(t("markerSetup"))}</option><option value="tires">${escapeHtml(t("markerTires"))}</option><option value="suspension">${escapeHtml(t("markerSuspension"))}</option><option value="car">${escapeHtml(t("markerCar"))}</option><option value="note">${escapeHtml(t("markerNoteType"))}</option></select></label>
|
||||
<label><span>${escapeHtml(t("markerNote"))}</span><input name="note" maxlength="160" /></label>
|
||||
<button class="profile-button profile-button-primary" type="submit">${escapeHtml(t("markerSave"))}</button>
|
||||
<small id="publicTrainingMarkerStatus"></small>
|
||||
</form>
|
||||
<div class="profile-performance-stats">
|
||||
<div><span>${escapeHtml(t("stints"))}</span><strong>${Number(stats.stintCount || 0)}</strong></div>
|
||||
<div><span>${escapeHtml(t("controlZone"))}</span><strong>${stats.controlZoneMaxMs ? `${formatLap(stats.controlZoneMinMs)} - ${formatLap(stats.controlZoneMaxMs)}` : "-"}</strong></div>
|
||||
@@ -526,6 +552,7 @@ function renderProfile(data) {
|
||||
<div><span>${escapeHtml(t("pitStops"))}</span><strong>${Number(channelStats.pitStopCount || 0)}</strong></div>
|
||||
<div><span>${escapeHtml(t("totalPit"))}</span><strong>${channelStats.pitStopCount ? formatRaceResultTime(channelStats.totalPitMs) : "-"}</strong></div>
|
||||
</div>
|
||||
<div class="profile-pace-blocks"><h3>${escapeHtml(t("paceBlocks"))}</h3><p>${escapeHtml(t("paceBlocksHint"))}</p><div>${paceBucketMarkup}</div></div>
|
||||
<div class="profile-stint-table-wrap">
|
||||
<h3>${escapeHtml(t("stintDetails"))}</h3>
|
||||
<div class="profile-history-wrap"><table class="profile-history"><thead><tr><th>${escapeHtml(t("stintNumber"))}</th><th>${escapeHtml(t("date"))}</th><th>${escapeHtml(t("laps"))}</th><th>${escapeHtml(t("best"))}</th><th>${escapeHtml(t("average"))}</th><th>${escapeHtml(t("duration"))}</th></tr></thead><tbody>${stintRows}</tbody></table></div>
|
||||
@@ -539,7 +566,7 @@ function renderProfile(data) {
|
||||
</section>
|
||||
` : ""}
|
||||
|
||||
<details class="profile-card profile-disclosure ${visibility.history ? "" : "is-hidden"}" style="margin-top:14px">
|
||||
<details class="profile-card profile-disclosure ${visibility.history ? "" : "is-hidden"}" data-persist-open="history" ${openSections.has("history") ? "open" : ""} style="margin-top:14px">
|
||||
<summary class="profile-card-head"><h2>${escapeHtml(t("history"))}</h2><span>+</span></summary>
|
||||
<div class="profile-history-wrap">
|
||||
<table class="profile-history">
|
||||
@@ -549,6 +576,25 @@ function renderProfile(data) {
|
||||
</div>
|
||||
</details>
|
||||
`;
|
||||
document.getElementById("publicTrainingMarkerForm")?.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
const form = event.currentTarget;
|
||||
const status = document.getElementById("publicTrainingMarkerStatus");
|
||||
const button = form.querySelector("button");
|
||||
if (button) button.disabled = true;
|
||||
try {
|
||||
const values = new FormData(form);
|
||||
const response = await fetch("/public-training/api/" + encodeURIComponent(shareToken) + "/markers", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ classId: selectedClassId, type: values.get("type"), note: values.get("note") }) });
|
||||
if (!response.ok) throw new Error("HTTP " + response.status);
|
||||
if (status) status.textContent = t("markerSaved");
|
||||
form.reset();
|
||||
await loadProfile();
|
||||
} catch {
|
||||
if (status) status.textContent = t("markerError");
|
||||
} finally {
|
||||
if (button) button.disabled = false;
|
||||
}
|
||||
});
|
||||
document.getElementById("profileClass")?.addEventListener("change", (event) => {
|
||||
selectedClassId = String(event.currentTarget.value || "");
|
||||
const nextUrl = new URL(window.location.href);
|
||||
|
||||
Reference in new issue
Block a user