Revert partial changes from 9db855f, keeping changes to preview_middleware and teams_new
This commit is contained in:
@@ -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) {
|
||||||
|
|||||||
@@ -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,86 +5,84 @@ 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)
|
canRemoveLeague := permCache.HasPermission(permissions.SeasonsRemoveLeague)
|
||||||
canRemoveLeague := permCache.HasPermission(permissions.SeasonsRemoveLeague)
|
|
||||||
|
|
||||||
// Create a map of assigned league IDs for quick lookup
|
// Create a map of assigned league IDs for quick lookup
|
||||||
assignedLeagueIDs := make(map[int]bool)
|
assignedLeagueIDs := make(map[int]bool)
|
||||||
for _, league := range season.Leagues {
|
for _, league := range season.Leagues {
|
||||||
assignedLeagueIDs[league.ID] = true
|
assignedLeagueIDs[league.ID] = true
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
if canAddLeague || canRemoveLeague {
|
if canAddLeague || canRemoveLeague {
|
||||||
<div
|
<div
|
||||||
id="leagues-section"
|
id="leagues-section"
|
||||||
class="px-6 pb-6"
|
class="px-6 pb-6"
|
||||||
>
|
>
|
||||||
<div class="bg-surface0 border border-surface1 rounded-lg p-6">
|
<div class="bg-surface0 border border-surface1 rounded-lg p-6">
|
||||||
<h2 class="text-2xl font-bold text-text mb-4">Leagues</h2>
|
<h2 class="text-2xl font-bold text-text mb-4">Leagues</h2>
|
||||||
<!-- Currently Assigned Leagues -->
|
<!-- Currently Assigned Leagues -->
|
||||||
if len(season.Leagues) > 0 {
|
if len(season.Leagues) > 0 {
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
<h3 class="text-sm font-medium text-subtext0 mb-2">Currently Assigned</h3>
|
<h3 class="text-sm font-medium text-subtext0 mb-2">Currently Assigned</h3>
|
||||||
<div class="flex flex-wrap gap-2">
|
<div class="flex flex-wrap gap-2">
|
||||||
for _, league := range season.Leagues {
|
for _, league := range season.Leagues {
|
||||||
<div class="flex items-center gap-2 bg-mantle border border-surface1 rounded-lg px-3 py-2">
|
<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-sm text-text">{ league.Name }</span>
|
||||||
<span class="text-xs text-subtext0 font-mono">({ league.ShortName })</span>
|
<span class="text-xs text-subtext0 font-mono">({ league.ShortName })</span>
|
||||||
if canRemoveLeague {
|
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
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
hx-post={ "/seasons/" + season.ShortName + "/add-league/" + league.ShortName }
|
@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' }) } }))" }
|
||||||
hx-target="#leagues-section"
|
class="text-red hover:text-red/75 hover:cursor-pointer ml-1"
|
||||||
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>
|
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
<span class="text-xs text-subtext0 font-mono">({ league.ShortName })</span>
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
|
||||||
<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>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</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>
|
||||||
}
|
</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