feat(settings): one public address (domain / DynDNS) for all mobile profiles
Moves the public address from each driver's share panel to Settings -> System & backup, with Save and Detect public IP. The share panel shows the address in use and links to the setting; empty keeps using the local network address. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
42e53fd356
commit
533f59adf9
13 files changed
+121
-53
No files matched your search
+9
-45
@@ -3,6 +3,7 @@ import { getDriverProfileGroups, getDriverProfileReferences } from "./driver_pro
|
||||
import { normalizeTrackLayouts } from "./track_layouts_logic.js";
|
||||
import { renderTrackLayoutBar, bindTrackLayoutBar } from "./track_layout_bar.js";
|
||||
import { buildTrainingRaceSessions } from "./training_logic.js";
|
||||
import { normalizePublicBaseUrl } from "./public_url.js";
|
||||
|
||||
// Which track layout the pace/record/consistency numbers are for: "current" (default),
|
||||
// "all" (overall), "none" (laps from before any layout existed), or a layout id. Module
|
||||
@@ -149,6 +150,7 @@ export function renderTrainingView(deps) {
|
||||
getSelectedClassId,
|
||||
setSelectedClassId,
|
||||
isInitialLoadDone = () => true,
|
||||
openPublicAddressSettings = () => {},
|
||||
} = deps;
|
||||
|
||||
state.training = normalizeTrainingState(state.training);
|
||||
@@ -714,16 +716,11 @@ export function renderTrainingView(deps) {
|
||||
`).join("")}
|
||||
</fieldset>
|
||||
` : ""}
|
||||
<label class="training-share-url">
|
||||
<span>${escapeHtml(t("training.public_base_url"))}</span>
|
||||
<input id="trainingPublicBaseUrl" type="url" value="${escapeHtml(publicBaseUrl)}" placeholder="https://training.example.se" />
|
||||
<small>${escapeHtml(t("training.public_base_url_hint"))}</small>
|
||||
</label>
|
||||
<div class="actions">
|
||||
<button class="btn" id="trainingPublicBaseSave" type="button">${escapeHtml(t("training.save_public_url"))}</button>
|
||||
<button class="btn" id="trainingPublicAddressDetect" type="button">${escapeHtml(t("training.detect_public_ip"))}</button>
|
||||
</div>
|
||||
<p class="hint" id="trainingPublicAddressStatus"></p>
|
||||
<p class="training-public-address">
|
||||
<span>${escapeHtml(t("training.public_base_url"))}:</span>
|
||||
<strong>${escapeHtml(publicBaseUrl || t("training.public_address_local"))}</strong>
|
||||
<button class="btn btn-mini" id="trainingPublicAddressSettings" type="button">${escapeHtml(t("training.public_address_change"))}</button>
|
||||
</p>
|
||||
${profileShare ? `
|
||||
<label class="training-share-url">
|
||||
<span>${escapeHtml(t("training.public_profile_link"))}</span>
|
||||
@@ -1028,32 +1025,8 @@ export function renderTrainingView(deps) {
|
||||
});
|
||||
});
|
||||
|
||||
document.getElementById("trainingPublicBaseSave")?.addEventListener("click", async () => {
|
||||
const input = document.getElementById("trainingPublicBaseUrl");
|
||||
const normalized = normalizePublicBaseUrl(input?.value);
|
||||
if (input?.value && !normalized) {
|
||||
document.getElementById("trainingPublicAddressStatus").textContent = t("training.public_url_invalid");
|
||||
return;
|
||||
}
|
||||
state.settings.publicBaseUrl = normalized;
|
||||
saveState();
|
||||
await syncStateToBackend();
|
||||
renderView();
|
||||
});
|
||||
document.getElementById("trainingPublicAddressDetect")?.addEventListener("click", async () => {
|
||||
const status = document.getElementById("trainingPublicAddressStatus");
|
||||
if (status) status.textContent = t("training.detecting_public_ip");
|
||||
try {
|
||||
const response = await fetch("/api/network/public-address", { cache: "no-store" });
|
||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||
const payload = await response.json();
|
||||
const input = document.getElementById("trainingPublicBaseUrl");
|
||||
if (input) input.value = payload.suggestedBaseUrl || "";
|
||||
if (status) status.textContent = t("training.detected_public_ip", { address: payload.address || "-" });
|
||||
} catch {
|
||||
if (status) status.textContent = t("training.detect_public_ip_failed");
|
||||
}
|
||||
});
|
||||
// The public address is one setting for the whole club: it lives under Settings -> System.
|
||||
document.getElementById("trainingPublicAddressSettings")?.addEventListener("click", () => openPublicAddressSettings());
|
||||
document.getElementById("trainingPublicProfileEnable")?.addEventListener("click", async () => {
|
||||
replacePublicProfileShare(state, selectedProfileId, profileReferences);
|
||||
saveState();
|
||||
@@ -1360,15 +1333,6 @@ function formatTrainingHighlight(highlight, { t, formatLap }) {
|
||||
return t("training.highlight_today_laps", { laps: highlight.value });
|
||||
}
|
||||
|
||||
function normalizePublicBaseUrl(value) {
|
||||
try {
|
||||
const url = new URL(String(value || "").trim());
|
||||
return ["http:", "https:"].includes(url.protocol) ? url.origin : "";
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
function buildPublicProfileUrl(token, language, publicBaseUrl = "") {
|
||||
const url = new URL(`/public-training/${encodeURIComponent(token)}`, publicBaseUrl || window.location.origin);
|
||||
url.searchParams.set("lang", language === "en" ? "en" : "sv");
|
||||
|
||||
Reference in new issue
Block a user