updated season league view page

This commit is contained in:
2026-02-14 21:08:00 +11:00
parent 8a79533de3
commit 27915d0047
23 changed files with 791 additions and 302 deletions

View File

@@ -46,7 +46,7 @@ func SeasonLeagueAddTeam(
}
// Redirect to refresh the page
w.Header().Set("HX-Redirect", fmt.Sprintf("/seasons/%s/leagues/%s", season.ShortName, league.ShortName))
w.Header().Set("HX-Redirect", fmt.Sprintf("/seasons/%s/leagues/%s/teams", season.ShortName, league.ShortName))
w.WriteHeader(http.StatusOK)
notify.Success(s, w, r, "Team Added", fmt.Sprintf(
"Successfully added '%s' to the league.",

View File

@@ -2,16 +2,17 @@ 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"
)
// SeasonLeaguePage redirects to the appropriate default tab based on season status
func SeasonLeaguePage(
s *hws.Server,
conn *db.DB,
@@ -22,22 +23,13 @@ func SeasonLeaguePage(
var season *db.Season
var league *db.League
var teams []*db.Team
var allTeams []*db.Team
if ok := conn.WithReadTx(s, w, r, func(ctx context.Context, tx bun.Tx) (bool, error) {
var err error
season, league, teams, err = db.GetSeasonLeague(ctx, tx, seasonStr, leagueStr)
season, league, _, err = db.GetSeasonLeague(ctx, tx, seasonStr, leagueStr)
if err != nil {
return false, errors.Wrap(err, "db.GetSeasonLeague")
}
// Get all teams for the dropdown (to add teams)
allTeams, err = db.GetList[db.Team](tx).GetAll(ctx)
if err != nil {
return false, errors.Wrap(err, "db.GetList[Team]")
}
return true, nil
}); !ok {
return
@@ -48,6 +40,11 @@ func SeasonLeaguePage(
return
}
renderSafely(seasonsview.SeasonLeaguePage(season, league, teams, allTeams), s, r, w)
defaultTab := season.GetDefaultTab()
redirectURL := fmt.Sprintf(
"/seasons/%s/leagues/%s/%s",
seasonStr, leagueStr, defaultTab,
)
http.Redirect(w, r, redirectURL, http.StatusSeeOther)
})
}

View File

@@ -0,0 +1,49 @@
package handlers
import (
"context"
"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"
)
// SeasonLeagueFinalsPage renders the finals tab of a season league page
func SeasonLeagueFinalsPage(
s *hws.Server,
conn *db.DB,
) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
seasonStr := r.PathValue("season_short_name")
leagueStr := r.PathValue("league_short_name")
var season *db.Season
var league *db.League
if ok := conn.WithReadTx(s, w, r, func(ctx context.Context, tx bun.Tx) (bool, error) {
var err error
season, league, _, err = db.GetSeasonLeague(ctx, tx, seasonStr, leagueStr)
if err != nil {
return false, errors.Wrap(err, "db.GetSeasonLeague")
}
return true, nil
}); !ok {
return
}
if season == nil || league == nil {
throw.NotFound(s, w, r, r.URL.Path)
return
}
if r.Method == "GET" {
renderSafely(seasonsview.SeasonLeagueFinalsPage(season, league), s, r, w)
} else {
renderSafely(seasonsview.SeasonLeagueFinals(), s, r, w)
}
})
}

View File

@@ -0,0 +1,49 @@
package handlers
import (
"context"
"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"
)
// SeasonLeagueFixturesPage renders the fixtures tab of a season league page
func SeasonLeagueFixturesPage(
s *hws.Server,
conn *db.DB,
) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
seasonStr := r.PathValue("season_short_name")
leagueStr := r.PathValue("league_short_name")
var season *db.Season
var league *db.League
if ok := conn.WithReadTx(s, w, r, func(ctx context.Context, tx bun.Tx) (bool, error) {
var err error
season, league, _, err = db.GetSeasonLeague(ctx, tx, seasonStr, leagueStr)
if err != nil {
return false, errors.Wrap(err, "db.GetSeasonLeague")
}
return true, nil
}); !ok {
return
}
if season == nil || league == nil {
throw.NotFound(s, w, r, r.URL.Path)
return
}
if r.Method == "GET" {
renderSafely(seasonsview.SeasonLeagueFixturesPage(season, league), s, r, w)
} else {
renderSafely(seasonsview.SeasonLeagueFixtures(), s, r, w)
}
})
}

View File

@@ -0,0 +1,49 @@
package handlers
import (
"context"
"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"
)
// SeasonLeagueStatsPage renders the stats tab of a season league page
func SeasonLeagueStatsPage(
s *hws.Server,
conn *db.DB,
) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
seasonStr := r.PathValue("season_short_name")
leagueStr := r.PathValue("league_short_name")
var season *db.Season
var league *db.League
if ok := conn.WithReadTx(s, w, r, func(ctx context.Context, tx bun.Tx) (bool, error) {
var err error
season, league, _, err = db.GetSeasonLeague(ctx, tx, seasonStr, leagueStr)
if err != nil {
return false, errors.Wrap(err, "db.GetSeasonLeague")
}
return true, nil
}); !ok {
return
}
if season == nil || league == nil {
throw.NotFound(s, w, r, r.URL.Path)
return
}
if r.Method == "GET" {
renderSafely(seasonsview.SeasonLeagueStatsPage(season, league), s, r, w)
} else {
renderSafely(seasonsview.SeasonLeagueStats(), s, r, w)
}
})
}

View File

@@ -0,0 +1,49 @@
package handlers
import (
"context"
"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"
)
// SeasonLeagueTablePage renders the table tab of a season league page
func SeasonLeagueTablePage(
s *hws.Server,
conn *db.DB,
) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
seasonStr := r.PathValue("season_short_name")
leagueStr := r.PathValue("league_short_name")
var season *db.Season
var league *db.League
if ok := conn.WithReadTx(s, w, r, func(ctx context.Context, tx bun.Tx) (bool, error) {
var err error
season, league, _, err = db.GetSeasonLeague(ctx, tx, seasonStr, leagueStr)
if err != nil {
return false, errors.Wrap(err, "db.GetSeasonLeague")
}
return true, nil
}); !ok {
return
}
if season == nil || league == nil {
throw.NotFound(s, w, r, r.URL.Path)
return
}
if r.Method == "GET" {
renderSafely(seasonsview.SeasonLeagueTablePage(season, league), s, r, w)
} else {
renderSafely(seasonsview.SeasonLeagueTable(), s, r, w)
}
})
}

View File

@@ -0,0 +1,60 @@
package handlers
import (
"context"
"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"
)
// SeasonLeagueTeamsPage renders the teams tab of a season league page
func SeasonLeagueTeamsPage(
s *hws.Server,
conn *db.DB,
) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
seasonStr := r.PathValue("season_short_name")
leagueStr := r.PathValue("league_short_name")
var season *db.Season
var league *db.League
var teams []*db.Team
var available []*db.Team
if ok := conn.WithReadTx(s, w, r, func(ctx context.Context, tx bun.Tx) (bool, error) {
var err error
season, league, teams, err = db.GetSeasonLeague(ctx, tx, seasonStr, leagueStr)
if err != nil {
return false, errors.Wrap(err, "db.GetSeasonLeague")
}
available, 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]")
}
return true, nil
}); !ok {
return
}
if season == nil || league == nil {
throw.NotFound(s, w, r, r.URL.Path)
return
}
if r.Method == "GET" {
renderSafely(seasonsview.SeasonLeagueTeamsPage(season, league, teams, available), s, r, w)
} else {
renderSafely(seasonsview.SeasonLeagueTeams(season, league, teams, available), s, r, w)
}
})
}

View File

@@ -36,10 +36,10 @@ func NewTeamSubmit(
TrimSpace().Required().
MaxLength(25).MinLength(3).Value
shortName := getter.String("short_name").
TrimSpace().Required().
TrimSpace().Required().ToUpper().
MaxLength(3).MinLength(3).Value
altShortName := getter.String("alt_short_name").
TrimSpace().Required().
TrimSpace().Required().ToUpper().
MaxLength(3).MinLength(3).Value
color := getter.String("color").
TrimSpace().MaxLength(7).Value