package homeview import "git.haelnorr.com/h/oslstats/internal/db" import "git.haelnorr.com/h/oslstats/internal/view/component/links" import "fmt" // LeagueStandings holds the data needed to render a single league's table type LeagueStandings struct { League *db.League Leaderboard []*db.LeaderboardEntry } // LatestStandings renders the latest standings section with tabs to switch // between leagues from the most recent season templ LatestStandings(season *db.Season, standings []LeagueStandings) {

Latest Standings

if season != nil { { season.Name } }
if season == nil || len(standings) == 0 {

No standings available yet.

} else {
if len(standings) > 1 {
for _, s := range standings { }
} for _, s := range standings {
@standingsTable(season, s.League, s.Leaderboard)
}
}
} templ standingsTable(season *db.Season, league *db.League, leaderboard []*db.LeaderboardEntry) { if len(leaderboard) == 0 {

No teams in this league yet.

} else {
Points: W = { fmt.Sprint(db.PointsWin) } OTW = { fmt.Sprint(db.PointsOvertimeWin) } OTL = { fmt.Sprint(db.PointsOvertimeLoss) } L = { fmt.Sprint(db.PointsLoss) }
for _, entry := range leaderboard { @standingsRow(entry, season, league) }
# Team GP W OTW OTL L GF GA GD PTS
} } templ standingsRow(entry *db.LeaderboardEntry, season *db.Season, league *db.League) { {{ r := entry.Record goalDiff := r.GoalsFor - r.GoalsAgainst var gdStr string if goalDiff > 0 { gdStr = fmt.Sprintf("+%d", goalDiff) } else { gdStr = fmt.Sprint(goalDiff) } }} { fmt.Sprint(entry.Position) } @links.TeamLinkInSeason(entry.Team, season, league) { fmt.Sprint(r.Played) } { fmt.Sprint(r.Wins) } { fmt.Sprint(r.OvertimeWins) } { fmt.Sprint(r.OvertimeLosses) } { fmt.Sprint(r.Losses) } { fmt.Sprint(r.GoalsFor) } { fmt.Sprint(r.GoalsAgainst) } if goalDiff > 0 { { gdStr } } else if goalDiff < 0 { { gdStr } } else { { gdStr } } { fmt.Sprint(r.Points) } }