draft seasons get special treatment :)

This commit is contained in:
2026-02-18 20:36:15 +11:00
parent 25a2109d1e
commit 59748b9bb9
16 changed files with 416 additions and 78 deletions

View File

@@ -15,6 +15,136 @@ templ DetailPage(season *db.Season, leaguesWithTeams []db.LeagueWithTeams) {
}
}
templ DraftSeasonDetailPage(season *db.Season, league *db.League, teams []*db.Team, available []*db.Team, fixtures []*db.Fixture, defaultTab string) {
@baseview.Layout(season.Name) {
<div class="max-w-screen-2xl mx-auto px-4 py-8">
@DraftSeasonDetail(season, league, teams, available, fixtures, defaultTab)
</div>
<script src="/static/js/tabs.js" defer></script>
}
}
templ DraftSeasonDetail(season *db.Season, league *db.League, teams []*db.Team, available []*db.Team, fixtures []*db.Fixture, defaultTab string) {
{{
permCache := contexts.Permissions(ctx)
canEditSeason := permCache.HasPermission(permissions.SeasonsUpdate)
}}
<div class="bg-mantle border border-surface1 rounded-lg overflow-hidden">
<!-- Header Section -->
<div class="bg-surface0 border-b border-surface1 px-6 py-8">
<div class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4 mb-4">
<div>
<div class="flex items-center gap-3 mb-2">
<h1 class="text-4xl font-bold text-text">{ season.Name }</h1>
<span class="text-lg font-mono text-subtext0 bg-surface1 px-2 py-0.5 rounded">{ season.ShortName }</span>
</div>
<div class="flex items-center gap-2 flex-wrap">
@SeasonTypeBadge(season.Type)
@SlapVersionBadge(season.SlapVersion)
@StatusBadge(season, false, false)
</div>
</div>
<div class="flex gap-2">
if canEditSeason {
<a
href={ templ.SafeURL("/seasons/" + season.ShortName + "/edit") }
class="rounded-lg px-4 py-2 hover:cursor-pointer text-center
bg-blue hover:bg-blue/75 text-mantle transition"
>
Edit
</a>
}
<a
href="/seasons"
class="rounded-lg px-4 py-2 hover:cursor-pointer text-center
bg-surface1 hover:bg-surface2 text-text transition"
>
Back to Seasons
</a>
</div>
</div>
<!-- Season Dates -->
<div class="mt-4 pt-4 border-t border-surface1">
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<!-- Regular Season -->
<div class="bg-mantle border border-surface1 rounded-lg p-4">
<h3 class="text-sm font-semibold text-text mb-3 flex items-center justify-center gap-2">
<span class="text-blue">&#9679;</span>
Regular Season
</h3>
<div class="grid grid-cols-2 gap-4">
<div class="text-center">
<div class="text-xs text-subtext0 uppercase mb-1">Start</div>
<div class="text-sm text-text font-medium">{ formatDateLong(season.StartDate) }</div>
</div>
<div class="text-center">
<div class="text-xs text-subtext0 uppercase mb-1">Finish</div>
if !season.EndDate.IsZero() {
<div class="text-sm text-text font-medium">{ formatDateLong(season.EndDate.Time) }</div>
} else {
<div class="text-sm text-subtext1 italic">Not set</div>
}
</div>
</div>
</div>
<!-- Finals -->
<div class="bg-mantle border border-surface1 rounded-lg p-4">
<h3 class="text-sm font-semibold text-text mb-3 flex items-center justify-center gap-2">
<span class="text-yellow">&#9733;</span>
Finals
</h3>
<div class="grid grid-cols-2 gap-4">
<div class="text-center">
<div class="text-xs text-subtext0 uppercase mb-1">Start</div>
if !season.FinalsStartDate.IsZero() {
<div class="text-sm text-text font-medium">{ formatDateLong(season.FinalsStartDate.Time) }</div>
} else {
<div class="text-sm text-subtext1 italic">Not set</div>
}
</div>
<div class="text-center">
<div class="text-xs text-subtext0 uppercase mb-1">Finish</div>
if !season.FinalsEndDate.IsZero() {
<div class="text-sm text-text font-medium">{ formatDateLong(season.FinalsEndDate.Time) }</div>
} else {
<div class="text-sm text-subtext1 italic">Not set</div>
}
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Tab Navigation -->
<nav class="bg-surface0 border-b border-surface1" data-tab-nav="season-league-content">
<ul class="flex flex-wrap">
@draftNavItem("table", "Table", defaultTab, season, league)
@draftNavItem("fixtures", "Fixtures", defaultTab, season, league)
@draftNavItem("teams", "Teams", defaultTab, season, league)
@draftNavItem("stats", "Stats", defaultTab, season, league)
@draftNavItem("finals", "Finals", defaultTab, season, league)
</ul>
</nav>
<!-- Content Area -->
<main class="bg-crust p-6" id="season-league-content">
switch defaultTab {
case "table":
@SeasonLeagueTable()
case "fixtures":
@SeasonLeagueFixtures(season, league, fixtures)
case "teams":
@SeasonLeagueTeams(season, league, teams, available)
case "stats":
@SeasonLeagueStats()
case "finals":
@SeasonLeagueFinals()
}
</main>
</div>
}
templ SeasonDetails(season *db.Season, leaguesWithTeams []db.LeagueWithTeams) {
{{
permCache := contexts.Permissions(ctx)

View File

@@ -5,84 +5,86 @@ import "git.haelnorr.com/h/oslstats/internal/contexts"
import "git.haelnorr.com/h/oslstats/internal/permissions"
templ LeaguesSection(season *db.Season, allLeagues []*db.League) {
{{
permCache := contexts.Permissions(ctx)
canAddLeague := permCache.HasPermission(permissions.SeasonsAddLeague)
canRemoveLeague := permCache.HasPermission(permissions.SeasonsRemoveLeague)
if season.Type != db.SeasonTypeDraft.String() {
{{
permCache := contexts.Permissions(ctx)
canAddLeague := permCache.HasPermission(permissions.SeasonsAddLeague)
canRemoveLeague := permCache.HasPermission(permissions.SeasonsRemoveLeague)
// Create a map of assigned league IDs for quick lookup
assignedLeagueIDs := make(map[int]bool)
for _, league := range season.Leagues {
assignedLeagueIDs[league.ID] = true
}
}}
if canAddLeague || canRemoveLeague {
<div
id="leagues-section"
class="px-6 pb-6"
>
<div class="bg-surface0 border border-surface1 rounded-lg p-6">
<h2 class="text-2xl font-bold text-text mb-4">Leagues</h2>
<!-- Currently Assigned Leagues -->
if len(season.Leagues) > 0 {
<div class="mb-4">
<h3 class="text-sm font-medium text-subtext0 mb-2">Currently Assigned</h3>
<div class="flex flex-wrap gap-2">
for _, league := range season.Leagues {
<div class="flex items-center gap-2 bg-mantle border border-surface1 rounded-lg px-3 py-2">
<span class="text-sm text-text">{ league.Name }</span>
<span class="text-xs text-subtext0 font-mono">({ league.ShortName })</span>
if canRemoveLeague {
<button
type="button"
@click={ "window.dispatchEvent(new CustomEvent('confirm-action', { detail: { title: 'Remove League', message: 'Are you sure you want to remove " + league.Name + " from this season?', action: () => htmx.ajax('DELETE', '/seasons/" + season.ShortName + "/leagues/" + league.ShortName + "', { target: '#leagues-section', swap: 'outerHTML' }) } }))" }
class="text-red hover:text-red/75 hover:cursor-pointer ml-1"
>
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
</svg>
</button>
}
</div>
}
</div>
</div>
}
<!-- Available Leagues to Add -->
if canAddLeague && len(allLeagues) > 0 {
{{
// Filter out already assigned leagues
availableLeagues := []*db.League{}
for _, league := range allLeagues {
if !assignedLeagueIDs[league.ID] {
availableLeagues = append(availableLeagues, league)
}
}
}}
if len(availableLeagues) > 0 {
<div>
<h3 class="text-sm font-medium text-subtext0 mb-2">Add League</h3>
// Create a map of assigned league IDs for quick lookup
assignedLeagueIDs := make(map[int]bool)
for _, league := range season.Leagues {
assignedLeagueIDs[league.ID] = true
}
}}
if canAddLeague || canRemoveLeague {
<div
id="leagues-section"
class="px-6 pb-6"
>
<div class="bg-surface0 border border-surface1 rounded-lg p-6">
<h2 class="text-2xl font-bold text-text mb-4">Leagues</h2>
<!-- Currently Assigned Leagues -->
if len(season.Leagues) > 0 {
<div class="mb-4">
<h3 class="text-sm font-medium text-subtext0 mb-2">Currently Assigned</h3>
<div class="flex flex-wrap gap-2">
for _, league := range availableLeagues {
<button
type="button"
hx-post={ "/seasons/" + season.ShortName + "/add-league/" + league.ShortName }
hx-target="#leagues-section"
hx-swap="outerHTML"
class="flex items-center gap-2 bg-surface1 hover:bg-surface2 border border-overlay0 rounded-lg px-3 py-2 transition hover:cursor-pointer"
>
for _, league := range season.Leagues {
<div class="flex items-center gap-2 bg-mantle border border-surface1 rounded-lg px-3 py-2">
<span class="text-sm text-text">{ league.Name }</span>
<span class="text-xs text-subtext0 font-mono">({ league.ShortName })</span>
<svg class="w-4 h-4 text-green" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"></path>
</svg>
</button>
if canRemoveLeague {
<button
type="button"
@click={ "window.dispatchEvent(new CustomEvent('confirm-action', { detail: { title: 'Remove League', message: 'Are you sure you want to remove " + league.Name + " from this season?', action: () => htmx.ajax('DELETE', '/seasons/" + season.ShortName + "/leagues/" + league.ShortName + "', { target: '#leagues-section', swap: 'outerHTML' }) } }))" }
class="text-red hover:text-red/75 hover:cursor-pointer ml-1"
>
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
</svg>
</button>
}
</div>
}
</div>
</div>
}
}
<!-- Available Leagues to Add -->
if canAddLeague && len(allLeagues) > 0 {
{{
// Filter out already assigned leagues
availableLeagues := []*db.League{}
for _, league := range allLeagues {
if !assignedLeagueIDs[league.ID] {
availableLeagues = append(availableLeagues, league)
}
}
}}
if len(availableLeagues) > 0 {
<div>
<h3 class="text-sm font-medium text-subtext0 mb-2">Add League</h3>
<div class="flex flex-wrap gap-2">
for _, league := range availableLeagues {
<button
type="button"
hx-post={ "/seasons/" + season.ShortName + "/add-league/" + league.ShortName }
hx-target="#leagues-section"
hx-swap="outerHTML"
class="flex items-center gap-2 bg-surface1 hover:bg-surface2 border border-overlay0 rounded-lg px-3 py-2 transition hover:cursor-pointer"
>
<span class="text-sm text-text">{ league.Name }</span>
<span class="text-xs text-subtext0 font-mono">({ league.ShortName })</span>
<svg class="w-4 h-4 text-green" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"></path>
</svg>
</button>
}
</div>
</div>
}
}
</div>
</div>
</div>
}
}
}

View File

@@ -125,3 +125,26 @@ templ leagueNavItem(section string, label string, activeSection string, season *
</a>
</li>
}
templ draftNavItem(section string, label string, activeSection string, season *db.Season, league *db.League) {
{{
isActive := section == activeSection
baseClasses := "inline-block px-6 py-3 transition-colors cursor-pointer border-b-2"
activeClasses := "border-blue text-blue font-semibold"
inactiveClasses := "border-transparent text-subtext0 hover:text-text hover:border-surface2"
displayURL := fmt.Sprintf("/seasons/%s/%s", season.ShortName, section)
postURL := fmt.Sprintf("/seasons/%s/leagues/%s/%s", season.ShortName, league.ShortName, section)
}}
<li class="inline-block">
<a
href={ templ.SafeURL(displayURL) }
hx-post={ postURL }
hx-target="#season-league-content"
hx-swap="innerHTML"
hx-push-url={ displayURL }
class={ baseClasses, templ.KV(activeClasses, isActive), templ.KV(inactiveClasses, !isActive) }
>
{ label }
</a>
</li>
}