From 77743019b0313be440b6b3d2a7b115fd2892c9a4 Mon Sep 17 00:00:00 2001 From: Jan Novak Date: Thu, 9 Apr 2026 13:29:48 +0200 Subject: [PATCH] feat: Hide future months from month range filter and table columns Compare against current YYYY-MM to exclude future months from the from/to selectors, default selection, and table column display. Co-Authored-By: Claude Sonnet 4.6 --- templates/adults.html | 34 ++++++++++++++++++++++++++++++---- templates/juniors.html | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/templates/adults.html b/templates/adults.html index 8087338..47b0394 100644 --- a/templates/adults.html +++ b/templates/adults.html @@ -923,6 +923,8 @@ } // Month range filter + var maxMonthIdx; + function applyMonthFilter() { var fromIdx = parseInt(document.getElementById('fromMonth').value); var toIdx = parseInt(document.getElementById('toMonth').value); @@ -940,17 +942,41 @@ var fromSelect = document.getElementById('fromMonth'); var toSelect = document.getElementById('toMonth'); fromSelect.value = 0; - toSelect.value = fromSelect.options.length - 1; + toSelect.value = maxMonthIdx; applyMonthFilter(); } - // Set defaults (last 5 months) and apply on load + // Remove future months from selects, set defaults, apply on load (function() { + var now = new Date(); + var currentMonth = now.getFullYear() + '-' + String(now.getMonth() + 1).padStart(2, '0'); + maxMonthIdx = sortedMonths.length - 1; + for (var i = 0; i < sortedMonths.length; i++) { + if (sortedMonths[i] > currentMonth) { + maxMonthIdx = i - 1; + break; + } + } + var fromSelect = document.getElementById('fromMonth'); var toSelect = document.getElementById('toMonth'); - var defaultFrom = Math.max(0, fromSelect.options.length - 5); + + // Remove future month options + for (var i = fromSelect.options.length - 1; i > maxMonthIdx; i--) { + fromSelect.remove(i); + toSelect.remove(i); + } + + // Hide future month columns permanently + document.querySelectorAll('[data-month-idx]').forEach(function(el) { + if (parseInt(el.getAttribute('data-month-idx')) > maxMonthIdx) { + el.classList.add('month-hidden'); + } + }); + + var defaultFrom = Math.max(0, maxMonthIdx - 4); fromSelect.value = defaultFrom; - toSelect.value = fromSelect.options.length - 1; + toSelect.value = maxMonthIdx; applyMonthFilter(); })(); diff --git a/templates/juniors.html b/templates/juniors.html index c177cf7..055700f 100644 --- a/templates/juniors.html +++ b/templates/juniors.html @@ -904,6 +904,8 @@ } // Month range filter + var maxMonthIdx; + function applyMonthFilter() { var fromIdx = parseInt(document.getElementById('fromMonth').value); var toIdx = parseInt(document.getElementById('toMonth').value); @@ -921,17 +923,41 @@ var fromSelect = document.getElementById('fromMonth'); var toSelect = document.getElementById('toMonth'); fromSelect.value = 0; - toSelect.value = fromSelect.options.length - 1; + toSelect.value = maxMonthIdx; applyMonthFilter(); } - // Set defaults (last 5 months) and apply on load + // Remove future months from selects, set defaults, apply on load (function() { + var now = new Date(); + var currentMonth = now.getFullYear() + '-' + String(now.getMonth() + 1).padStart(2, '0'); + maxMonthIdx = sortedMonths.length - 1; + for (var i = 0; i < sortedMonths.length; i++) { + if (sortedMonths[i] > currentMonth) { + maxMonthIdx = i - 1; + break; + } + } + var fromSelect = document.getElementById('fromMonth'); var toSelect = document.getElementById('toMonth'); - var defaultFrom = Math.max(0, fromSelect.options.length - 5); + + // Remove future month options + for (var i = fromSelect.options.length - 1; i > maxMonthIdx; i--) { + fromSelect.remove(i); + toSelect.remove(i); + } + + // Hide future month columns permanently + document.querySelectorAll('[data-month-idx]').forEach(function(el) { + if (parseInt(el.getAttribute('data-month-idx')) > maxMonthIdx) { + el.classList.add('month-hidden'); + } + }); + + var defaultFrom = Math.max(0, maxMonthIdx - 4); fromSelect.value = defaultFrom; - toSelect.value = fromSelect.options.length - 1; + toSelect.value = maxMonthIdx; applyMonthFilter(); })();