From 61890ae20bf1f4b9d8caed711965c905739844b3 Mon Sep 17 00:00:00 2001 From: Haelnorr Date: Sat, 14 Feb 2026 21:08:00 +1100 Subject: [PATCH] updated season league view page --- internal/db/getlist.go | 4 + internal/db/season.go | 56 +++++ internal/embedfs/web/js/admin.js | 41 +-- internal/embedfs/web/js/tabs.js | 50 ++++ internal/handlers/season_league_add_team.go | 2 +- internal/handlers/season_league_detail.go | 21 +- internal/handlers/season_league_finals.go | 49 ++++ internal/handlers/season_league_fixtures.go | 49 ++++ internal/handlers/season_league_stats.go | 49 ++++ internal/handlers/season_league_table.go | 49 ++++ internal/handlers/season_league_teams.go | 60 +++++ internal/handlers/teams_new.go | 4 +- internal/server/routes.go | 27 +- .../view/adminview/dashboard_layout.templ | 3 +- .../view/seasonsview/leagues_section.templ | 2 +- .../seasonsview/season_league_finals.templ | 15 ++ .../seasonsview/season_league_fixtures.templ | 15 ++ .../seasonsview/season_league_layout.templ | 129 ++++++++++ .../view/seasonsview/season_league_page.templ | 234 ------------------ .../seasonsview/season_league_stats.templ | 15 ++ .../seasonsview/season_league_table.templ | 15 ++ .../seasonsview/season_league_teams.templ | 151 +++++++++++ internal/view/teamsview/new_form.templ | 53 ++-- 23 files changed, 791 insertions(+), 302 deletions(-) create mode 100644 internal/embedfs/web/js/tabs.js create mode 100644 internal/handlers/season_league_finals.go create mode 100644 internal/handlers/season_league_fixtures.go create mode 100644 internal/handlers/season_league_stats.go create mode 100644 internal/handlers/season_league_table.go create mode 100644 internal/handlers/season_league_teams.go create mode 100644 internal/view/seasonsview/season_league_finals.templ create mode 100644 internal/view/seasonsview/season_league_fixtures.templ create mode 100644 internal/view/seasonsview/season_league_layout.templ delete mode 100644 internal/view/seasonsview/season_league_page.templ create mode 100644 internal/view/seasonsview/season_league_stats.templ create mode 100644 internal/view/seasonsview/season_league_table.templ create mode 100644 internal/view/seasonsview/season_league_teams.templ diff --git a/internal/db/getlist.go b/internal/db/getlist.go index 2b96b9a..d94007d 100644 --- a/internal/db/getlist.go +++ b/internal/db/getlist.go @@ -77,6 +77,10 @@ func GetList[T any](tx bun.Tx) *listgetter[T] { return l } +func (l *listgetter[T]) String() string { + return l.q.String() +} + func (l *listgetter[T]) Join(join string, args ...any) *listgetter[T] { l.q = l.q.Join(join, args...) return l diff --git a/internal/db/season.go b/internal/db/season.go index 3567bfe..7a2bf0e 100644 --- a/internal/db/season.go +++ b/internal/db/season.go @@ -9,6 +9,22 @@ import ( "github.com/uptrace/bun" ) +// SeasonStatus represents the current status of a season +type SeasonStatus string + +const ( + // StatusUpcoming means the season has not started yet + StatusUpcoming SeasonStatus = "upcoming" + // StatusInProgress means the regular season is active + StatusInProgress SeasonStatus = "in_progress" + // StatusFinalsSoon means regular season ended, finals upcoming + StatusFinalsSoon SeasonStatus = "finals_soon" + // StatusFinals means finals are in progress + StatusFinals SeasonStatus = "finals" + // StatusCompleted means the season has finished + StatusCompleted SeasonStatus = "completed" +) + type Season struct { bun.BaseModel `bun:"table:seasons,alias:s"` @@ -107,6 +123,46 @@ type LeagueWithTeams struct { Teams []*Team } +// GetStatus returns the current status of the season based on dates +func (s *Season) GetStatus() SeasonStatus { + now := time.Now() + + if now.Before(s.StartDate) { + return StatusUpcoming + } + + if !s.FinalsStartDate.IsZero() { + if !s.FinalsEndDate.IsZero() && now.After(s.FinalsEndDate.Time) { + return StatusCompleted + } + if now.After(s.FinalsStartDate.Time) { + return StatusFinals + } + if !s.EndDate.IsZero() && now.After(s.EndDate.Time) { + return StatusFinalsSoon + } + return StatusInProgress + } + + if !s.EndDate.IsZero() && now.After(s.EndDate.Time) { + return StatusCompleted + } + + return StatusInProgress +} + +// GetDefaultTab returns the default tab to show based on the season status +func (s *Season) GetDefaultTab() string { + switch s.GetStatus() { + case StatusInProgress: + return "table" + case StatusUpcoming: + return "teams" + default: + return "finals" + } +} + func (s *Season) HasLeague(leagueID int) bool { for _, league := range s.Leagues { if league.ID == leagueID { diff --git a/internal/embedfs/web/js/admin.js b/internal/embedfs/web/js/admin.js index 04a17cd..7b66770 100644 --- a/internal/embedfs/web/js/admin.js +++ b/internal/embedfs/web/js/admin.js @@ -236,45 +236,18 @@ function sortRolesColumn(field, currentOrder, currentOrderBy) { } // Handle HTMX navigation and initialization +// Tab navigation active state is handled by tabs.js (generic). +// This file only handles admin-specific concerns (flatpickr, multi-select). document.addEventListener("DOMContentLoaded", function () { // Initialize flatpickr on page load initFlatpickr(); - // Update active nav item after HTMX navigation document.body.addEventListener("htmx:afterSwap", function (event) { - if (event.detail.target.id === "admin-content") { - // Get the current URL path - const path = window.location.pathname; - const section = path.split("/").pop() || "users"; - - // Update active state on nav items - document.querySelectorAll("nav a").forEach(function (link) { - const href = link.getAttribute("href"); - if (href && href.includes("/" + section)) { - link.classList.remove( - "border-transparent", - "text-subtext0", - "hover:text-text", - "hover:border-surface2" - ); - link.classList.add("border-blue", "text-blue", "font-semibold"); - } else { - link.classList.remove("border-blue", "text-blue", "font-semibold"); - link.classList.add( - "border-transparent", - "text-subtext0", - "hover:text-text", - "hover:border-surface2" - ); - } - }); - - // Re-initialize flatpickr after content swap - initFlatpickr(); - } - - // Re-initialize flatpickr when audit results are updated - if (event.detail.target.id === "audit-results-container") { + // Re-initialize flatpickr after admin content swap + if ( + event.detail.target.id === "admin-content" || + event.detail.target.id === "audit-results-container" + ) { initFlatpickr(); } }); diff --git a/internal/embedfs/web/js/tabs.js b/internal/embedfs/web/js/tabs.js new file mode 100644 index 0000000..57309f7 --- /dev/null +++ b/internal/embedfs/web/js/tabs.js @@ -0,0 +1,50 @@ +// Generic tab navigation handler +// Manages active tab styling after HTMX content swaps. +// +// Usage: Add data-tab-nav="" to your