102 lines
3.3 KiB
Plaintext
102 lines
3.3 KiB
Plaintext
package seasonsview
|
|
|
|
import "git.haelnorr.com/h/oslstats/internal/db"
|
|
import "git.haelnorr.com/h/oslstats/internal/permissions"
|
|
import "git.haelnorr.com/h/oslstats/internal/contexts"
|
|
import "fmt"
|
|
|
|
templ SeasonLeagueFixturesPage(season *db.Season, league *db.League, fixtures []*db.Fixture, scheduleMap map[int]*db.FixtureSchedule) {
|
|
@SeasonLeagueLayout("fixtures", season, league) {
|
|
@SeasonLeagueFixtures(season, league, fixtures, scheduleMap)
|
|
}
|
|
}
|
|
|
|
templ SeasonLeagueFixtures(season *db.Season, league *db.League, fixtures []*db.Fixture, scheduleMap map[int]*db.FixtureSchedule) {
|
|
{{
|
|
permCache := contexts.Permissions(ctx)
|
|
canManage := permCache.HasPermission(permissions.FixturesManage)
|
|
|
|
// Group fixtures by game week (only allocated ones)
|
|
type gameWeekGroup struct {
|
|
Week int
|
|
Fixtures []*db.Fixture
|
|
}
|
|
groups := []gameWeekGroup{}
|
|
groupMap := map[int]int{} // week -> index in groups
|
|
for _, f := range fixtures {
|
|
if f.GameWeek == nil {
|
|
continue
|
|
}
|
|
idx, exists := groupMap[*f.GameWeek]
|
|
if !exists {
|
|
idx = len(groups)
|
|
groupMap[*f.GameWeek] = idx
|
|
groups = append(groups, gameWeekGroup{Week: *f.GameWeek, Fixtures: []*db.Fixture{}})
|
|
}
|
|
groups[idx].Fixtures = append(groups[idx].Fixtures, f)
|
|
}
|
|
}}
|
|
<div>
|
|
if canManage {
|
|
<div class="flex justify-end mb-4">
|
|
<a
|
|
href={ templ.SafeURL(fmt.Sprintf("/seasons/%s/leagues/%s/fixtures/manage", season.ShortName, league.ShortName)) }
|
|
class="rounded-lg px-4 py-2 hover:cursor-pointer text-center text-sm
|
|
bg-blue hover:bg-blue/80 text-mantle transition"
|
|
>
|
|
Manage Fixtures
|
|
</a>
|
|
</div>
|
|
}
|
|
if len(groups) == 0 {
|
|
<div class="bg-surface0 border border-surface1 rounded-lg p-8 text-center">
|
|
<p class="text-subtext0 text-lg">No fixtures scheduled yet.</p>
|
|
</div>
|
|
} else {
|
|
<div class="space-y-4">
|
|
for _, group := range groups {
|
|
<div class="bg-surface0 border border-surface1 rounded-lg overflow-hidden">
|
|
<div class="bg-mantle border-b border-surface1 px-4 py-3">
|
|
<h3 class="text-lg font-bold text-text">Game Week { fmt.Sprint(group.Week) }</h3>
|
|
</div>
|
|
<div class="divide-y divide-surface1">
|
|
for _, fixture := range group.Fixtures {
|
|
{{
|
|
sched, hasSchedule := scheduleMap[fixture.ID]
|
|
_ = sched
|
|
}}
|
|
<a
|
|
href={ templ.SafeURL(fmt.Sprintf("/fixtures/%d", fixture.ID)) }
|
|
class="px-4 py-3 flex items-center justify-between hover:bg-surface1 transition hover:cursor-pointer block"
|
|
>
|
|
<div class="flex items-center gap-3">
|
|
<span class="text-xs font-mono text-subtext0 bg-mantle px-2 py-0.5 rounded">
|
|
R{ fmt.Sprint(fixture.Round) }
|
|
</span>
|
|
<span class="text-text">
|
|
{ fixture.HomeTeam.Name }
|
|
</span>
|
|
<span class="text-subtext0 text-sm">vs</span>
|
|
<span class="text-text">
|
|
{ fixture.AwayTeam.Name }
|
|
</span>
|
|
</div>
|
|
if hasSchedule && sched.ScheduledTime != nil {
|
|
<span class="text-xs text-green font-medium">
|
|
{ sched.ScheduledTime.Format("Mon 2 Jan 3:04 PM") }
|
|
</span>
|
|
} else {
|
|
<span class="text-xs text-subtext1">
|
|
TBD
|
|
</span>
|
|
}
|
|
</a>
|
|
}
|
|
</div>
|
|
</div>
|
|
}
|
|
</div>
|
|
}
|
|
</div>
|
|
}
|