Toggle added at the bottom. Future and all matches
This commit is contained in:
parent
d3a5af2117
commit
1b21d364e7
@ -17,6 +17,8 @@ function saveData() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let showAllMatches = false; // false = future matches only; true = all matches
|
||||||
|
|
||||||
function renderTable() {
|
function renderTable() {
|
||||||
const container = document.getElementById('attendance-table');
|
const container = document.getElementById('attendance-table');
|
||||||
container.innerHTML = '';
|
container.innerHTML = '';
|
||||||
@ -54,19 +56,24 @@ 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);
|
||||||
}
|
}
|
||||||
// (No filtering or extra logic, just render all dates in order)
|
// Filter dates based on toggle
|
||||||
// Render all dates in original chronological order
|
let filteredDates = [];
|
||||||
|
if (showAllMatches) {
|
||||||
|
filteredDates = data.dates;
|
||||||
|
} else {
|
||||||
|
filteredDates = data.dates.filter(date => parseDate(date) > today);
|
||||||
|
}
|
||||||
|
// Find closest date for scroll (from filtered)
|
||||||
let closestIdx = 0;
|
let closestIdx = 0;
|
||||||
let minDiff = Infinity;
|
let minDiff = Infinity;
|
||||||
data.dates.forEach((date, rowIdx) => {
|
filteredDates.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;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Only render all dates in order
|
filteredDates.forEach((date, rowIdx) => {
|
||||||
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
|
||||||
@ -152,4 +159,17 @@ function renderTable() {
|
|||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.onload = fetchData;
|
window.onload = () => {
|
||||||
|
fetchData();
|
||||||
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
const toggleBtn = document.getElementById('toggle-matches-btn');
|
||||||
|
if (toggleBtn) {
|
||||||
|
toggleBtn.textContent = 'Show All Matches';
|
||||||
|
toggleBtn.onclick = () => {
|
||||||
|
showAllMatches = !showAllMatches;
|
||||||
|
toggleBtn.textContent = showAllMatches ? 'Show Future Matches' : 'Show All Matches';
|
||||||
|
renderTable();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
@ -109,6 +109,9 @@
|
|||||||
<div id="attendance-table"></div>
|
<div id="attendance-table"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div style="display: flex; justify-content: center; margin-top: 1em;">
|
||||||
|
<button id="toggle-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 All Matches</button>
|
||||||
|
</div>
|
||||||
<script src="/static/app.js"></script>
|
<script src="/static/app.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user