Reverted to Yes No blank version. No extra menus

This commit is contained in:
Greg 2025-05-10 18:37:43 +02:00
parent 977fb5bc05
commit d3a5af2117
2 changed files with 8 additions and 54 deletions

View File

@ -15,7 +15,7 @@ function saveData() {
}); });
} }
let matchViewMode = 'future'; // 'all' or 'future'
function renderTable() { function renderTable() {
const container = document.getElementById('attendance-table'); const container = document.getElementById('attendance-table');
@ -54,30 +54,19 @@ function renderTable() {
// Assume 20xx for years < 100 // Assume 20xx for years < 100
return new Date(2000 + y, m - 1, d); return new Date(2000 + y, m - 1, d);
} }
const pastDates = data.dates.filter(date => parseDate(date) <= today); // (No filtering or extra logic, just render all dates in order)
const futureDates = data.dates.filter(date => parseDate(date) > today); // Render all dates in original chronological order
// Find most recent past date (last match)
const lastMatch = pastDates.length > 0 ? pastDates.reduce((a, b) => parseDate(a) > parseDate(b) ? a : b) : null;
// Find next match (soonest future date)
const nextMatch = futureDates.length > 0 ? futureDates.reduce((a, b) => parseDate(a) < parseDate(b) ? a : b) : null;
// Filter dates based on view mode
let filteredDates = [];
if (matchViewMode === 'all') {
filteredDates = data.dates;
} else {
filteredDates = data.dates.filter(date => parseDate(date) > today);
}
// Find closest date to today for scroll
let closestIdx = 0; let closestIdx = 0;
let minDiff = Infinity; let minDiff = Infinity;
filteredDates.forEach((date, rowIdx) => { data.dates.forEach((date, rowIdx) => {
const diff = Math.abs(parseDate(date) - today); const diff = Math.abs(parseDate(date) - today);
if (diff < minDiff) { if (diff < minDiff) {
minDiff = diff; minDiff = diff;
closestIdx = rowIdx; closestIdx = rowIdx;
} }
}); });
filteredDates.forEach((date, rowIdx) => { // Only render all dates in order
data.dates.forEach((date, rowIdx) => {
const tr = document.createElement('tr'); const tr = document.createElement('tr');
if (rowIdx === closestIdx) tr.id = 'current-match-row'; if (rowIdx === closestIdx) tr.id = 'current-match-row';
// Date cell // Date cell
@ -163,37 +152,4 @@ function renderTable() {
}, 0); }, 0);
} }
document.getElementById('add-date').onclick = function() { window.onload = fetchData;
const date = prompt('Enter date (DD/MM/YY):');
// Check format: DD/MM/YY
const dateRegex = /^\d{2}\/\d{2}\/\d{2}$/;
if (!dateRegex.test(date)) {
alert('Date must be in DD/MM/YY format.');
return;
}
if (date && !data.dates.includes(date)) {
data.dates.push(date);
saveData();
renderTable();
}
};
window.onload = () => {
fetchData();
document.addEventListener('DOMContentLoaded', () => {
const showBtn = document.getElementById('show-matches-btn');
if (showBtn) {
showBtn.textContent = 'Show All Matches';
showBtn.onclick = () => {
if (matchViewMode === 'future') {
matchViewMode = 'all';
showBtn.textContent = 'Show Future Matches';
} else {
matchViewMode = 'future';
showBtn.textContent = 'Show All Matches';
}
renderTable();
};
}
});
};

View File

@ -108,9 +108,7 @@
<div class="table-container"> <div class="table-container">
<div id="attendance-table"></div> <div id="attendance-table"></div>
</div> </div>
<div style="display: flex; justify-content: center; margin-top: 1em;">
<button id="show-matches-btn" style="background: #948979; color: #222831; border: none; padding: 0.7em 1.5em; border-radius: 4px; font-weight: bold; font-size: 1em; transition: background 0.2s; cursor: pointer;">Show</button>
</div>
<script src="/static/app.js"></script> <script src="/static/app.js"></script>
</body> </body>
</html> </html>