better UI

This commit is contained in:
Radek Davidek 2025-11-02 13:19:21 +01:00
parent 843e2bf749
commit 21cb991f9a

View File

@ -1,52 +1,89 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="cs">
<head> <head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CZ.Basketball - zápasy</title> <title>CZ.Basketball - zápasy</title>
<link rel="icon" type="image/png" href="https://cz.basketball/img/logo-icon.png"> <link rel="icon" type="image/png" href="https://cz.basketball/img/logo-icon.png">
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
<style> <style>
body { body {
font-family: 'Roboto', Arial, sans-serif; font-family: 'Roboto', Arial, sans-serif;
background: #f4f7f9; background: #f4f7f9;
color: #333; color: #333;
margin: 20px; margin: 10px 16px;
} }
h1 { color: #2c3e50; } h1 {
label { margin-right: 8px; font-weight: 500; } color: #2c3e50;
input, select, button { font-size: 1.6rem;
padding: 6px 10px; text-align: center;
margin-right: 10px; margin-bottom: 20px;
}
.controls {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 10px;
margin-bottom: 10px; margin-bottom: 10px;
justify-content: center;
}
label { font-weight: 500; }
input, select {
padding: 8px 10px;
border: 1px solid #ccc; border: 1px solid #ccc;
border-radius: 4px; border-radius: 6px;
font-size: 14px; font-size: 15px;
min-width: 140px;
} }
button { button {
background-color: #3498db; background-color: #3498db;
color: white; color: white;
border: none;
border-radius: 6px;
padding: 8px 12px;
font-size: 15px;
cursor: pointer; cursor: pointer;
transition: background 0.3s; transition: background 0.3s;
} }
button:hover { background-color: #2980b9; } button:hover { background-color: #2980b9; }
.radio-group {
text-align: center;
margin: 8px 0 16px 0;
}
.radio-group label {
margin-right: 12px;
font-size: 15px;
}
#loading, #error {
text-align: center;
margin: 10px 0;
font-weight: 500;
}
#loading { color: #3498db; }
#error { color: red; }
.table-container {
overflow-x: auto;
background: white;
border-radius: 8px;
box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}
table { table {
border-collapse: collapse; border-collapse: collapse;
width: 100%; width: 100%;
background-color: white; min-width: 700px;
border-radius: 6px;
overflow: hidden;
box-shadow: 0 2px 6px rgba(0,0,0,0.1);
} }
th, td { th, td {
border-bottom: 1px solid #eee; border-bottom: 1px solid #eee;
padding: 10px; padding: 10px;
text-align: left; text-align: left;
font-size: 14px;
} }
th { th {
background-color: #3498db; background-color: #3498db;
color: white; color: white;
font-weight: 500; font-weight: 500;
position: sticky;
top: 0;
} }
tr.highlight { tr.highlight {
background-color: #ffeb3b !important; background-color: #ffeb3b !important;
@ -58,19 +95,37 @@
tr:nth-child(even) { background-color: #f9f9f9; } tr:nth-child(even) { background-color: #f9f9f9; }
a { color: #2980b9; text-decoration: none; } a { color: #2980b9; text-decoration: none; }
a:hover { text-decoration: underline; } a:hover { text-decoration: underline; }
@media (max-width: 600px) {
h1 { font-size: 1.3rem; margin-bottom: 12px; }
.controls { flex-direction: column; align-items: stretch; }
input, select { width: 100%; font-size: 16px; }
.radio-group label { display: block; margin: 4px 0; }
th, td { padding: 8px; font-size: 13px; }
}
</style> </style>
</head> </head>
<body> <body>
<h1>CZ.Basketball - zápasy</h1> <h1>CZ.Basketball zápasy</h1>
<label for="date">Vyber datum:</label> <div class="controls">
<label for="date">Datum:</label>
<input type="date" id="date" onchange="loadMatches()"/> <input type="date" id="date" onchange="loadMatches()"/>
<label for="league">Liga:</label>
<label for="league">Vyber ligu:</label>
<select id="league" onchange="filterMatches()"> <select id="league" onchange="filterMatches()">
<option value="">Všechny ligy</option> <option value="">Všechny ligy</option>
</select> </select>
</div>
<div class="radio-group">
<label><input type="radio" name="tvfilter" value="tv" checked>TV stream</label>
<label><input type="radio" name="tvfilter" value="live">Live Score</label>
<label><input type="radio" name="tvfilter" value="all">Všechny zápasy</label>
</div>
<div id="loading" style="display:none;">🔄 Načítám zápasy...</div>
<div id="error" style="display:none;">❌ Nepodařilo se načíst data.</div>
<div class="table-container">
<table id="matches"> <table id="matches">
<thead> <thead>
<tr> <tr>
@ -85,61 +140,81 @@
</thead> </thead>
<tbody></tbody> <tbody></tbody>
</table> </table>
</div>
<script> <script>
// --- Nastavit kalendář na aktuální den při načtení stránky --- let allMatchesGlobal = [];
window.addEventListener('DOMContentLoaded', () => { window.addEventListener('DOMContentLoaded', () => {
const today = new Date(); const today = new Date();
const yyyy = today.getFullYear(); const yyyy = today.getFullYear();
const mm = String(today.getMonth() + 1).padStart(2, '0'); const mm = String(today.getMonth() + 1).padStart(2, '0');
const dd = String(today.getDate()).padStart(2, '0'); const dd = String(today.getDate()).padStart(2, '0');
document.getElementById('date').value = `${yyyy}-${mm}-${dd}`; document.getElementById('date').value = `${yyyy}-${mm}-${dd}`;
loadMatches();
loadMatches(); // načíst zápasy pro dnešní datum
}); });
// --- Načíst zápasy z API ---
async function loadMatches() { async function loadMatches() {
const loadingEl = document.getElementById('loading');
const errorEl = document.getElementById('error');
loadingEl.style.display = 'block';
errorEl.style.display = 'none';
const dateInput = document.getElementById('date').value; const dateInput = document.getElementById('date').value;
let url = '/api/matches'; let url = '/api/matches';
if (dateInput) url += '?date=' + encodeURIComponent(dateInput); if (dateInput) url += '?date=' + encodeURIComponent(dateInput);
try {
const res = await fetch(url); const res = await fetch(url);
if (!res.ok) throw new Error('HTTP error');
const data = await res.json(); const data = await res.json();
const select = document.getElementById('league'); allMatchesGlobal = [];
if (!data || !data.leagues) throw new Error('No data');
data.leagues.forEach(league => {
league.matches.forEach(match => {
allMatchesGlobal.push({ league: league.name, match });
});
});
renderMatches(allMatchesGlobal);
} catch (err) {
errorEl.style.display = 'block';
console.error(err);
} finally {
loadingEl.style.display = 'none';
}
}
function renderMatches(matches) {
const tbody = document.querySelector('#matches tbody'); const tbody = document.querySelector('#matches tbody');
const select = document.getElementById('league');
tbody.innerHTML = ''; tbody.innerHTML = '';
select.innerHTML = '<option value="">Všechny ligy</option>'; select.innerHTML = '<option value="">Všechny ligy</option>';
if (!data || !data.leagues) return; const tvFilter = document.querySelector('input[name="tvfilter"]:checked').value;
const filteredMatches = matches.filter(m => {
const hasTV = m.match.links.tvcom && m.match.links.tvcom.url;
const hasLive = m.match.links.live && m.match.links.live.url;
if(tvFilter === 'tv') return !!hasTV;
if(tvFilter === 'live') return !!hasLive;
return true;
});
const leagues = [...new Set(filteredMatches.map(m => m.league))];
leagues.forEach(name => {
const opt = document.createElement('option');
opt.value = name;
opt.textContent = name;
select.appendChild(opt);
});
const now = new Date();
let closestTimeDiff = Infinity; let closestTimeDiff = Infinity;
let closestRow = null; let closestRow = null;
const now = new Date();
const allMatches = []; filteredMatches.sort((a, b) => {
data.leagues.forEach(league => {
const hasTV = league.matches.some(m => m.links.tvcom && m.links.tvcom.url);
if (!hasTV) return;
// přidat do select boxu
const option = document.createElement('option');
option.value = league.name;
option.textContent = league.name;
select.appendChild(option);
league.matches.forEach(match => {
if (!match.links.live && !match.links.tvcom) return;
allMatches.push({ league: league.name, match });
});
});
// --- Seřadit podle času ---
allMatches.sort((a, b) => {
const parseTime = s => { const parseTime = s => {
if(!s || !s.match(/^\d{1,2}:\d{2}$/)) return Infinity; if(!s || !s.match(/^\d{1,2}:\d{2}$/)) return Infinity;
const [h,m] = s.split(':').map(Number); const [h,m] = s.split(':').map(Number);
@ -148,28 +223,29 @@ async function loadMatches() {
return parseTime(a.match.status) - parseTime(b.match.status); return parseTime(a.match.status) - parseTime(b.match.status);
}); });
filteredMatches.forEach(({league, match}) => {
// --- Vytvořit tabulku ---
allMatches.forEach(({ league, match }) => {
const tr = document.createElement('tr'); const tr = document.createElement('tr');
tr.dataset.league = league; tr.dataset.league = league;
let previewUrl = ''; let previewUrl = '';
if(match.links.preview && match.links.preview.url){ if(match.links.preview && match.links.preview.url){
previewUrl = match.links.preview.url; previewUrl = match.links.preview.url;
if (!previewUrl.startsWith('http://') && !previewUrl.startsWith('https://')) { if(!previewUrl.startsWith('http') && !previewUrl.startsWith('https')){
previewUrl = 'https://cz.basketball' + previewUrl; previewUrl = 'https://cz.basketball' + previewUrl;
} }
} }
const tvUrl = match.links.tvcom && match.links.tvcom.url;
const liveUrl = match.links.live && match.links.live.url;
tr.innerHTML = ` tr.innerHTML = `
<td>${match.status}</td> <td>${match.status}</td>
<td>${league}</td> <td>${league}</td>
<td>${match.home.name}</td> <td>${match.home.name}</td>
<td>${match.away.name}</td> <td>${match.away.name}</td>
<td>${previewUrl ? '<a href="'+previewUrl+'">Preview</a>' : ''}</td> <td>${previewUrl ? '<a href="'+previewUrl+'" target="_blank">Preview</a>' : ''}</td>
<td>${match.links.live && match.links.live.url ? '<a href="'+match.links.live.url+'" target="_blank">Live</a>' : ''}</td> <td>${liveUrl ? '<a href="'+liveUrl+'" target="_blank">Live</a>' : ''}</td>
<td>${match.links.tvcom && match.links.tvcom.url ? '<a href="'+match.links.tvcom.url+'" target="_blank">TV</a>' : ''}</td> <td>${tvUrl ? '<a href="'+tvUrl+'" target="_blank">TV</a>' : ''}</td>
`; `;
if((match.home.name && match.home.name.includes('Nymburk')) || if((match.home.name && match.home.name.includes('Nymburk')) ||
@ -191,15 +267,21 @@ async function loadMatches() {
}); });
if(closestRow) closestRow.classList.add('highlight'); if(closestRow) closestRow.classList.add('highlight');
filterMatches();
} }
// --- Filtrovat podle ligy ---
function filterMatches() { function filterMatches() {
const league = document.getElementById('league').value; const league = document.getElementById('league').value;
document.querySelectorAll('#matches tbody tr').forEach(row => { document.querySelectorAll('#matches tbody tr').forEach(row => {
row.style.display = (!league || row.dataset.league===league) ? '' : 'none'; row.style.display = (!league || row.dataset.league===league) ? '' : 'none';
}); });
} }
document.querySelectorAll('input[name="tvfilter"]').forEach(radio => {
radio.addEventListener('change', () => {
renderMatches(allMatchesGlobal);
});
});
</script> </script>
</body> </body>
</html> </html>