Compare commits
2 Commits
52a168f1aa
...
667c9f04a7
| Author | SHA1 | Date | |
|---|---|---|---|
| 667c9f04a7 | |||
| 4b81ac12cf |
@@ -1,96 +0,0 @@
|
|||||||
package handlers
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"git.haelnorr.com/h/golib/hws"
|
|
||||||
"git.haelnorr.com/h/oslstats/internal/db"
|
|
||||||
"git.haelnorr.com/h/oslstats/internal/throw"
|
|
||||||
seasonsview "git.haelnorr.com/h/oslstats/internal/view/seasonsview"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/uptrace/bun"
|
|
||||||
)
|
|
||||||
|
|
||||||
// redirectDraftSeasonLeague checks if a season is a draft type and redirects
|
|
||||||
// GET requests from /seasons/{short}/leagues/Draft/{tab} to /seasons/{short}/{tab}.
|
|
||||||
// Returns true if a redirect was issued (caller should return early).
|
|
||||||
// POST requests are not redirected since they are HTMX partial content requests.
|
|
||||||
func redirectDraftSeasonLeague(season *db.Season, tab string, w http.ResponseWriter, r *http.Request) bool {
|
|
||||||
if r.Method == "GET" && season.Type == db.SeasonTypeDraft.String() {
|
|
||||||
redirectURL := fmt.Sprintf("/seasons/%s/%s", season.ShortName, tab)
|
|
||||||
http.Redirect(w, r, redirectURL, http.StatusSeeOther)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// DraftSeasonTabPage handles GET requests for draft season tab pages at
|
|
||||||
// /seasons/{season_short_name}/{tab}. It renders the full DraftSeasonDetailPage
|
|
||||||
// with the appropriate tab content pre-rendered.
|
|
||||||
func DraftSeasonTabPage(
|
|
||||||
s *hws.Server,
|
|
||||||
conn *db.DB,
|
|
||||||
tab string,
|
|
||||||
) http.Handler {
|
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
seasonStr := r.PathValue("season_short_name")
|
|
||||||
|
|
||||||
var season *db.Season
|
|
||||||
var league *db.League
|
|
||||||
var teams []*db.Team
|
|
||||||
var availableTeams []*db.Team
|
|
||||||
var fixtures []*db.Fixture
|
|
||||||
|
|
||||||
if ok := conn.WithReadTx(s, w, r, func(ctx context.Context, tx bun.Tx) (bool, error) {
|
|
||||||
var err error
|
|
||||||
|
|
||||||
// Verify this is a draft season
|
|
||||||
season, err = db.GetSeason(ctx, tx, seasonStr)
|
|
||||||
if err != nil {
|
|
||||||
if db.IsBadRequest(err) {
|
|
||||||
throw.NotFound(s, w, r, r.URL.Path)
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
return false, errors.Wrap(err, "db.GetSeason")
|
|
||||||
}
|
|
||||||
|
|
||||||
if season.Type != db.SeasonTypeDraft.String() {
|
|
||||||
throw.NotFound(s, w, r, r.URL.Path)
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch the Draft league and teams
|
|
||||||
season, league, teams, err = db.GetSeasonLeague(ctx, tx, seasonStr, "Draft")
|
|
||||||
if err != nil {
|
|
||||||
return false, errors.Wrap(err, "db.GetSeasonLeague")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch tab-specific data
|
|
||||||
switch tab {
|
|
||||||
case "teams":
|
|
||||||
availableTeams, err = db.GetList[db.Team](tx).
|
|
||||||
Join("LEFT JOIN team_participations tp ON tp.team_id = t.id").
|
|
||||||
Where("NOT tp.season_id = ? OR tp.season_id IS NULL", season.ID).
|
|
||||||
GetAll(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return false, errors.Wrap(err, "db.GetList[Team]")
|
|
||||||
}
|
|
||||||
case "fixtures":
|
|
||||||
season, league, fixtures, err = db.GetFixtures(ctx, tx, seasonStr, "Draft")
|
|
||||||
if err != nil {
|
|
||||||
return false, errors.Wrap(err, "db.GetFixtures")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true, nil
|
|
||||||
}); !ok {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
renderSafely(seasonsview.DraftSeasonDetailPage(
|
|
||||||
season, league, teams, availableTeams, fixtures, tab,
|
|
||||||
), s, r, w)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,6 @@ package handlers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"git.haelnorr.com/h/golib/hws"
|
"git.haelnorr.com/h/golib/hws"
|
||||||
@@ -33,26 +32,15 @@ func SeasonPage(
|
|||||||
return false, errors.Wrap(err, "db.GetSeason")
|
return false, errors.Wrap(err, "db.GetSeason")
|
||||||
}
|
}
|
||||||
|
|
||||||
if season.Type != db.SeasonTypeDraft.String() {
|
|
||||||
leaguesWithTeams, err = season.MapTeamsToLeagues(ctx, tx)
|
leaguesWithTeams, err = season.MapTeamsToLeagues(ctx, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, errors.Wrap(err, "season.MapTeamsToLeagues")
|
return false, errors.Wrap(err, "season.MapTeamsToLeagues")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return true, nil
|
return true, nil
|
||||||
}); !ok {
|
}); !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if season.Type == db.SeasonTypeDraft.String() {
|
|
||||||
// Redirect draft seasons to their default tab
|
|
||||||
defaultTab := season.GetDefaultTab()
|
|
||||||
redirectURL := fmt.Sprintf("/seasons/%s/%s", seasonStr, defaultTab)
|
|
||||||
http.Redirect(w, r, redirectURL, http.StatusSeeOther)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
renderSafely(seasonsview.DetailPage(season, leaguesWithTeams), s, r, w)
|
renderSafely(seasonsview.DetailPage(season, leaguesWithTeams), s, r, w)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,11 +50,7 @@ func SeasonLeagueAddTeam(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Redirect to refresh the page
|
// Redirect to refresh the page
|
||||||
redirectURL := fmt.Sprintf("/seasons/%s/leagues/%s/teams", season.ShortName, league.ShortName)
|
w.Header().Set("HX-Redirect", fmt.Sprintf("/seasons/%s/leagues/%s/teams", season.ShortName, league.ShortName))
|
||||||
if season.Type == db.SeasonTypeDraft.String() {
|
|
||||||
redirectURL = fmt.Sprintf("/seasons/%s/teams", season.ShortName)
|
|
||||||
}
|
|
||||||
w.Header().Set("HX-Redirect", redirectURL)
|
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
notify.Success(s, w, r, "Team Added", fmt.Sprintf(
|
notify.Success(s, w, r, "Team Added", fmt.Sprintf(
|
||||||
"Successfully added '%s' to the league.",
|
"Successfully added '%s' to the league.",
|
||||||
|
|||||||
@@ -39,14 +39,6 @@ func SeasonLeaguePage(
|
|||||||
}
|
}
|
||||||
|
|
||||||
defaultTab := season.GetDefaultTab()
|
defaultTab := season.GetDefaultTab()
|
||||||
|
|
||||||
// Draft seasons redirect to /seasons/{short}/{tab} instead
|
|
||||||
if season.Type == db.SeasonTypeDraft.String() {
|
|
||||||
redirectURL := fmt.Sprintf("/seasons/%s/%s", seasonStr, defaultTab)
|
|
||||||
http.Redirect(w, r, redirectURL, http.StatusSeeOther)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
redirectURL := fmt.Sprintf(
|
redirectURL := fmt.Sprintf(
|
||||||
"/seasons/%s/leagues/%s/%s",
|
"/seasons/%s/leagues/%s/%s",
|
||||||
seasonStr, leagueStr, defaultTab,
|
seasonStr, leagueStr, defaultTab,
|
||||||
|
|||||||
@@ -39,9 +39,6 @@ func SeasonLeagueFinalsPage(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if redirectDraftSeasonLeague(season, "finals", w, r) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if r.Method == "GET" {
|
if r.Method == "GET" {
|
||||||
renderSafely(seasonsview.SeasonLeagueFinalsPage(season, league), s, r, w)
|
renderSafely(seasonsview.SeasonLeagueFinalsPage(season, league), s, r, w)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -41,9 +41,6 @@ func SeasonLeagueFixturesPage(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if redirectDraftSeasonLeague(season, "fixtures", w, r) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if r.Method == "GET" {
|
if r.Method == "GET" {
|
||||||
renderSafely(seasonsview.SeasonLeagueFixturesPage(season, league, fixtures), s, r, w)
|
renderSafely(seasonsview.SeasonLeagueFixturesPage(season, league, fixtures), s, r, w)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -39,9 +39,6 @@ func SeasonLeagueStatsPage(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if redirectDraftSeasonLeague(season, "stats", w, r) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if r.Method == "GET" {
|
if r.Method == "GET" {
|
||||||
renderSafely(seasonsview.SeasonLeagueStatsPage(season, league), s, r, w)
|
renderSafely(seasonsview.SeasonLeagueStatsPage(season, league), s, r, w)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -38,9 +38,6 @@ func SeasonLeagueTablePage(
|
|||||||
}); !ok {
|
}); !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if redirectDraftSeasonLeague(season, "table", w, r) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if r.Method == "GET" {
|
if r.Method == "GET" {
|
||||||
renderSafely(seasonsview.SeasonLeagueTablePage(season, league), s, r, w)
|
renderSafely(seasonsview.SeasonLeagueTablePage(season, league), s, r, w)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -50,9 +50,6 @@ func SeasonLeagueTeamsPage(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if redirectDraftSeasonLeague(season, "teams", w, r) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if r.Method == "GET" {
|
if r.Method == "GET" {
|
||||||
renderSafely(seasonsview.SeasonLeagueTeamsPage(season, league, teams, available), s, r, w)
|
renderSafely(seasonsview.SeasonLeagueTeamsPage(season, league, teams, available), s, r, w)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -25,21 +25,7 @@ func SeasonAddLeague(
|
|||||||
var season *db.Season
|
var season *db.Season
|
||||||
var allLeagues []*db.League
|
var allLeagues []*db.League
|
||||||
if ok := conn.WithNotifyTx(s, w, r, func(ctx context.Context, tx bun.Tx) (bool, error) {
|
if ok := conn.WithNotifyTx(s, w, r, func(ctx context.Context, tx bun.Tx) (bool, error) {
|
||||||
// Check if season is a draft season
|
err := db.NewSeasonLeague(ctx, tx, seasonShortName, leagueShortName, db.NewAuditFromRequest(r))
|
||||||
seasonCheck, err := db.GetSeason(ctx, tx, seasonShortName)
|
|
||||||
if err != nil {
|
|
||||||
if db.IsBadRequest(err) {
|
|
||||||
respond.NotFound(w, err)
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
return false, errors.Wrap(err, "db.GetSeason")
|
|
||||||
}
|
|
||||||
if seasonCheck.Type == db.SeasonTypeDraft.String() {
|
|
||||||
respond.BadRequest(w, errors.New("cannot manually manage leagues for draft seasons"))
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
err = db.NewSeasonLeague(ctx, tx, seasonShortName, leagueShortName, db.NewAuditFromRequest(r))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if db.IsBadRequest(err) {
|
if db.IsBadRequest(err) {
|
||||||
respond.BadRequest(w, err)
|
respond.BadRequest(w, err)
|
||||||
@@ -89,10 +75,6 @@ func SeasonRemoveLeague(
|
|||||||
}
|
}
|
||||||
return false, errors.Wrap(err, "db.GetSeason")
|
return false, errors.Wrap(err, "db.GetSeason")
|
||||||
}
|
}
|
||||||
if season.Type == db.SeasonTypeDraft.String() {
|
|
||||||
respond.BadRequest(w, errors.New("cannot manually manage leagues for draft seasons"))
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
err = season.RemoveLeague(ctx, tx, leagueStr, db.NewAuditFromRequest(r))
|
err = season.RemoveLeague(ctx, tx, leagueStr, db.NewAuditFromRequest(r))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if db.IsBadRequest(err) {
|
if db.IsBadRequest(err) {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package rbac
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@@ -29,7 +28,6 @@ func LoadPreviewRoleMiddleware(s *hws.Server, conn *db.DB) func(http.Handler) ht
|
|||||||
|
|
||||||
user := db.CurrentUser(r.Context())
|
user := db.CurrentUser(r.Context())
|
||||||
if user == nil {
|
if user == nil {
|
||||||
fmt.Println(user)
|
|
||||||
// User not logged in
|
// User not logged in
|
||||||
// Auth middleware skips on certain routes like CSS files so even
|
// Auth middleware skips on certain routes like CSS files so even
|
||||||
// if user IS logged in, this will trigger on those routes,
|
// if user IS logged in, this will trigger on those routes,
|
||||||
|
|||||||
@@ -97,32 +97,6 @@ func addRoutes(
|
|||||||
Method: hws.MethodPOST,
|
Method: hws.MethodPOST,
|
||||||
Handler: perms.RequirePermission(s, permissions.SeasonsUpdate)(handlers.SeasonEditSubmit(s, conn)),
|
Handler: perms.RequirePermission(s, permissions.SeasonsUpdate)(handlers.SeasonEditSubmit(s, conn)),
|
||||||
},
|
},
|
||||||
// Draft season tab pages (must be before league routes to avoid conflicts)
|
|
||||||
{
|
|
||||||
Path: "/seasons/{season_short_name}/table",
|
|
||||||
Method: hws.MethodGET,
|
|
||||||
Handler: handlers.DraftSeasonTabPage(s, conn, "table"),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Path: "/seasons/{season_short_name}/fixtures",
|
|
||||||
Method: hws.MethodGET,
|
|
||||||
Handler: handlers.DraftSeasonTabPage(s, conn, "fixtures"),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Path: "/seasons/{season_short_name}/teams",
|
|
||||||
Method: hws.MethodGET,
|
|
||||||
Handler: handlers.DraftSeasonTabPage(s, conn, "teams"),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Path: "/seasons/{season_short_name}/stats",
|
|
||||||
Method: hws.MethodGET,
|
|
||||||
Handler: handlers.DraftSeasonTabPage(s, conn, "stats"),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Path: "/seasons/{season_short_name}/finals",
|
|
||||||
Method: hws.MethodGET,
|
|
||||||
Handler: handlers.DraftSeasonTabPage(s, conn, "finals"),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Path: "/seasons/{season_short_name}/leagues/{league_short_name}",
|
Path: "/seasons/{season_short_name}/leagues/{league_short_name}",
|
||||||
Method: hws.MethodGET,
|
Method: hws.MethodGET,
|
||||||
|
|||||||
@@ -15,136 +15,6 @@ 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">●</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">★</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) {
|
templ SeasonDetails(season *db.Season, leaguesWithTeams []db.LeagueWithTeams) {
|
||||||
{{
|
{{
|
||||||
permCache := contexts.Permissions(ctx)
|
permCache := contexts.Permissions(ctx)
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import "git.haelnorr.com/h/oslstats/internal/contexts"
|
|||||||
import "git.haelnorr.com/h/oslstats/internal/permissions"
|
import "git.haelnorr.com/h/oslstats/internal/permissions"
|
||||||
|
|
||||||
templ LeaguesSection(season *db.Season, allLeagues []*db.League) {
|
templ LeaguesSection(season *db.Season, allLeagues []*db.League) {
|
||||||
if season.Type != db.SeasonTypeDraft.String() {
|
|
||||||
{{
|
{{
|
||||||
permCache := contexts.Permissions(ctx)
|
permCache := contexts.Permissions(ctx)
|
||||||
canAddLeague := permCache.HasPermission(permissions.SeasonsAddLeague)
|
canAddLeague := permCache.HasPermission(permissions.SeasonsAddLeague)
|
||||||
@@ -87,4 +86,3 @@ templ LeaguesSection(season *db.Season, allLeagues []*db.League) {
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -125,26 +125,3 @@ templ leagueNavItem(section string, label string, activeSection string, season *
|
|||||||
</a>
|
</a>
|
||||||
</li>
|
</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>
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user