BUILD150 — кнопка ОНЛАЙН для расписания

This commit is contained in:
2026-09-18 19:54:14 +03:00
parent bda5235657
commit 1c00642791
4 changed files with 225 additions and 2 deletions

View File

@@ -45,6 +45,7 @@
settingsModal: null,
gamesAutoSyncAttempted: new Set(),
scheduleSyncBusy: false,
scheduleOnlineBusy: false,
gameOpenBusy: false,
gameOpenGeneration: 0,
gamePollTimer: null,
@@ -113,6 +114,9 @@
noGames: "На выбранную дату матчей нет",
noGamesLoaded: "Календарь матчей ещё не загружен",
updateGames: "Обновить матчи",
onlineRefresh: "ОНЛАЙН",
onlineRefreshing: "ОБНОВЛЯЕМ…",
onlineUpdated: "Расписание обновлено из JSON матчей",
discovering: "Ищем XML матчей…",
loadingGames: "Загружаем календарь…",
gamesLoaded: "Матчи загружены",
@@ -221,6 +225,9 @@
noGames: "No games on the selected date",
noGamesLoaded: "The game calendar has not been loaded yet",
updateGames: "Update games",
onlineRefresh: "ONLINE",
onlineRefreshing: "UPDATING…",
onlineUpdated: "Schedule updated from match JSON",
discovering: "Discovering games XML…",
loadingGames: "Loading schedule…",
gamesLoaded: "Games loaded",
@@ -1661,6 +1668,42 @@ function gameCard(game) {
`;
}
async function refreshScheduleOnline({ onDate = state.gameDate, language = state.language } = {}) {
if (!state.selectedId) {
throw new Error(state.language === "en" ? "Tournament is not selected" : "Турнир не выбран");
}
if (state.scheduleOnlineBusy) return null;
state.scheduleOnlineBusy = true;
const selectedDate = String(onDate || state.gameDate || localDateIso());
const selectedLanguage = language === "en" ? "en" : "ru";
try {
const result = await request(
`/api/hockey/tournaments/${encodeURIComponent(state.selectedId)}/games/online-sync`
+ `?on_date=${encodeURIComponent(selectedDate)}`
+ `&language=${encodeURIComponent(selectedLanguage)}`,
{ method: "POST", timeoutMs: 45000 }
);
// Re-read PostgreSQL only after every match JSON has been processed.
state.games = await request(gamesUrl());
applyGamesData();
renderGames();
await loadTeamSchedule({ force: true });
const changed = [];
if (Number(result.score_updated || 0)) changed.push(`${state.language === "en" ? "score" : "счёт"}: ${Number(result.score_updated || 0)}`);
if (Number(result.status_updated || 0)) changed.push(`${state.language === "en" ? "status" : "статус"}: ${Number(result.status_updated || 0)}`);
const changedLabel = changed.length ? ` · ${changed.join(", ")}` : "";
notify(`${t("onlineUpdated")} · ${Number(result.checked || 0) - Number(result.failed || 0)}/${Number(result.checked || 0)}${changedLabel}`);
return result;
} catch (error) {
notify(error.message, true);
throw error;
} finally {
state.scheduleOnlineBusy = false;
}
}
async function syncGames(forceDiscovery, { silentSuccess = false } = {}) {
if (!state.selectedId || state.scheduleSyncBusy) return;
state.scheduleSyncBusy = true;
@@ -2710,6 +2753,7 @@ document.addEventListener("visibilitychange", () => {
selectTournament: openTournament,
selectGame: openGame,
reloadGames: () => loadGames({ autoSync: false }),
refreshScheduleOnline,
refreshStandings: refreshTournamentStandings,
};