updated seasons list
This commit is contained in:
@@ -63,7 +63,7 @@ func ListSeasons(ctx context.Context, tx bun.Tx, pageOpts *PageOpts) (*SeasonLis
|
||||
pageOpts.Order = bun.OrderDesc
|
||||
}
|
||||
if pageOpts.OrderBy == "" {
|
||||
pageOpts.OrderBy = "name"
|
||||
pageOpts.OrderBy = "start_date"
|
||||
}
|
||||
seasons := []Season{}
|
||||
err := tx.NewSelect().
|
||||
|
||||
@@ -180,7 +180,7 @@ func NewSeasonSubmit(
|
||||
// Helper function to validate alphanumeric strings
|
||||
func isAlphanumeric(s string) bool {
|
||||
for _, r := range s {
|
||||
if !((r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9')) {
|
||||
if ((r < 'A') || (r > 'Z')) && ((r < '0') || (r > '9')) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ func SeasonsPage(
|
||||
return
|
||||
}
|
||||
tx.Commit()
|
||||
renderSafely(page.SeasonsList(seasons), s, r, w)
|
||||
renderSafely(page.SeasonsPage(seasons), s, r, w)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
71
internal/view/component/season/status.templ
Normal file
71
internal/view/component/season/status.templ
Normal file
@@ -0,0 +1,71 @@
|
||||
package season
|
||||
|
||||
import "git.haelnorr.com/h/oslstats/internal/db"
|
||||
import "time"
|
||||
|
||||
// StatusBadge renders a season status badge
|
||||
// Parameters:
|
||||
// - season: pointer to db.Season
|
||||
// - compact: bool - true for list view (text only, small), false for detail view (icon + text, large)
|
||||
// - useShortLabels: bool - true for "Active/Finals", false for "In Progress/Finals in Progress"
|
||||
templ StatusBadge(season *db.Season, compact bool, useShortLabels bool) {
|
||||
{{
|
||||
now := time.Now()
|
||||
status := ""
|
||||
statusColor := ""
|
||||
statusBg := ""
|
||||
|
||||
// Determine status based on dates
|
||||
if now.Before(season.StartDate) {
|
||||
status = "Upcoming"
|
||||
statusColor = "text-blue"
|
||||
statusBg = "bg-blue/10 border-blue"
|
||||
} else if !season.EndDate.IsZero() && now.After(season.EndDate.Time) {
|
||||
status = "Completed"
|
||||
statusColor = "text-green"
|
||||
statusBg = "bg-green/10 border-green"
|
||||
} else if !season.FinalsStartDate.IsZero() && now.After(season.FinalsStartDate.Time) {
|
||||
if !season.FinalsEndDate.IsZero() && now.After(season.FinalsEndDate.Time) {
|
||||
status = "Completed"
|
||||
statusColor = "text-green"
|
||||
statusBg = "bg-green/10 border-green"
|
||||
} else {
|
||||
if useShortLabels {
|
||||
status = "Finals"
|
||||
} else {
|
||||
status = "Finals in Progress"
|
||||
}
|
||||
statusColor = "text-yellow"
|
||||
statusBg = "bg-yellow/10 border-yellow"
|
||||
}
|
||||
} else {
|
||||
if useShortLabels {
|
||||
status = "Active"
|
||||
} else {
|
||||
status = "In Progress"
|
||||
}
|
||||
statusColor = "text-green"
|
||||
statusBg = "bg-green/10 border-green"
|
||||
}
|
||||
|
||||
// Determine size classes
|
||||
var sizeClasses string
|
||||
var textSize string
|
||||
var iconSize string
|
||||
if compact {
|
||||
sizeClasses = "px-2 py-1"
|
||||
textSize = "text-xs"
|
||||
iconSize = "text-sm"
|
||||
} else {
|
||||
sizeClasses = "px-4 py-2"
|
||||
textSize = "text-lg"
|
||||
iconSize = "text-2xl"
|
||||
}
|
||||
}}
|
||||
<div class={ "rounded-lg border-2 inline-flex items-center gap-2 " + sizeClasses + " " + statusBg }>
|
||||
if !compact {
|
||||
<span class={ iconSize + " " + statusColor }>●</span>
|
||||
}
|
||||
<span class={ textSize + " font-semibold " + statusColor }>{ status }</span>
|
||||
</div>
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package page
|
||||
|
||||
import "git.haelnorr.com/h/oslstats/internal/db"
|
||||
import "git.haelnorr.com/h/oslstats/internal/view/layout"
|
||||
import seasoncomp "git.haelnorr.com/h/oslstats/internal/view/component/season"
|
||||
import "time"
|
||||
import "strconv"
|
||||
|
||||
@@ -54,14 +55,14 @@ templ SeasonDetails(season *db.Season) {
|
||||
<div class="flex justify-between items-center">
|
||||
<span class="text-subtext0">Start Date:</span>
|
||||
<span class="text-text font-semibold">
|
||||
{ formatDate(season.StartDate) }
|
||||
{ formatDateLong(season.StartDate) }
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex justify-between items-center">
|
||||
<span class="text-subtext0">End Date:</span>
|
||||
<span class="text-text font-semibold">
|
||||
if !season.EndDate.IsZero() {
|
||||
{ formatDate(season.EndDate.Time) }
|
||||
{ formatDateLong(season.EndDate.Time) }
|
||||
} else {
|
||||
<span class="text-subtext1 italic">Not set</span>
|
||||
}
|
||||
@@ -90,7 +91,7 @@ templ SeasonDetails(season *db.Season) {
|
||||
<span class="text-subtext0">Start Date:</span>
|
||||
<span class="text-text font-semibold">
|
||||
if !season.FinalsStartDate.IsZero() {
|
||||
{ formatDate(season.FinalsStartDate.Time) }
|
||||
{ formatDateLong(season.FinalsStartDate.Time) }
|
||||
} else {
|
||||
<span class="text-subtext1 italic">Not set</span>
|
||||
}
|
||||
@@ -100,7 +101,7 @@ templ SeasonDetails(season *db.Season) {
|
||||
<span class="text-subtext0">End Date:</span>
|
||||
<span class="text-text font-semibold">
|
||||
if !season.FinalsEndDate.IsZero() {
|
||||
{ formatDate(season.FinalsEndDate.Time) }
|
||||
{ formatDateLong(season.FinalsEndDate.Time) }
|
||||
} else {
|
||||
<span class="text-subtext1 italic">Not set</span>
|
||||
}
|
||||
@@ -124,51 +125,14 @@ templ SeasonDetails(season *db.Season) {
|
||||
<div class="bg-surface0 border border-surface1 rounded-lg p-6">
|
||||
<h2 class="text-2xl font-bold text-text mb-4">Status</h2>
|
||||
<div class="flex items-center gap-3">
|
||||
@SeasonStatus(season)
|
||||
@seasoncomp.StatusBadge(season, false, false)
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
templ SeasonStatus(season *db.Season) {
|
||||
{{
|
||||
now := time.Now()
|
||||
status := ""
|
||||
statusColor := ""
|
||||
statusBg := ""
|
||||
|
||||
if now.Before(season.StartDate) {
|
||||
status = "Upcoming"
|
||||
statusColor = "text-blue"
|
||||
statusBg = "bg-blue/10 border-blue"
|
||||
} else if !season.EndDate.IsZero() && now.After(season.EndDate.Time) {
|
||||
status = "Completed"
|
||||
statusColor = "text-green"
|
||||
statusBg = "bg-green/10 border-green"
|
||||
} else if !season.FinalsStartDate.IsZero() && now.After(season.FinalsStartDate.Time) {
|
||||
if !season.FinalsEndDate.IsZero() && now.After(season.FinalsEndDate.Time) {
|
||||
status = "Completed"
|
||||
statusColor = "text-green"
|
||||
statusBg = "bg-green/10 border-green"
|
||||
} else {
|
||||
status = "Finals in Progress"
|
||||
statusColor = "text-yellow"
|
||||
statusBg = "bg-yellow/10 border-yellow"
|
||||
}
|
||||
} else {
|
||||
status = "In Progress"
|
||||
statusColor = "text-green"
|
||||
statusBg = "bg-green/10 border-green"
|
||||
}
|
||||
}}
|
||||
<div class={ "px-4 py-2 rounded-lg border-2 inline-flex items-center gap-2 " + statusBg }>
|
||||
<span class={ "text-2xl " + statusColor }>●</span>
|
||||
<span class={ "text-lg font-semibold " + statusColor }>{ status }</span>
|
||||
</div>
|
||||
}
|
||||
|
||||
func formatDate(t time.Time) string {
|
||||
func formatDateLong(t time.Time) string {
|
||||
return t.Format("January 2, 2006")
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,9 @@ import "git.haelnorr.com/h/oslstats/internal/db"
|
||||
import "git.haelnorr.com/h/oslstats/internal/view/layout"
|
||||
import "git.haelnorr.com/h/oslstats/internal/view/component/pagination"
|
||||
import "git.haelnorr.com/h/oslstats/internal/view/component/sort"
|
||||
import "git.haelnorr.com/h/oslstats/internal/view/component/season"
|
||||
import "fmt"
|
||||
import "time"
|
||||
import "github.com/uptrace/bun"
|
||||
|
||||
templ SeasonsPage(seasons *db.SeasonList) {
|
||||
@@ -18,6 +20,16 @@ templ SeasonsPage(seasons *db.SeasonList) {
|
||||
templ SeasonsList(seasons *db.SeasonList) {
|
||||
{{
|
||||
sortOpts := []db.OrderOpts{
|
||||
{
|
||||
Order: bun.OrderDesc,
|
||||
OrderBy: "start_date",
|
||||
Label: "Start Date (Newest First)",
|
||||
},
|
||||
{
|
||||
Order: bun.OrderAsc,
|
||||
OrderBy: "start_date",
|
||||
Label: "Start Date (Oldest First)",
|
||||
},
|
||||
{
|
||||
Order: bun.OrderAsc,
|
||||
OrderBy: "name",
|
||||
@@ -28,16 +40,6 @@ templ SeasonsList(seasons *db.SeasonList) {
|
||||
OrderBy: "name",
|
||||
Label: "Name (Z-A)",
|
||||
},
|
||||
{
|
||||
Order: bun.OrderAsc,
|
||||
OrderBy: "short_name",
|
||||
Label: "Short Name (A-Z)",
|
||||
},
|
||||
{
|
||||
Order: bun.OrderDesc,
|
||||
OrderBy: "short_name",
|
||||
Label: "Short Name (Z-A)",
|
||||
},
|
||||
}
|
||||
}}
|
||||
<div id="seasons-list-container">
|
||||
@@ -74,12 +76,25 @@ templ SeasonsList(seasons *db.SeasonList) {
|
||||
} else {
|
||||
<!-- Card grid -->
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
for _, season := range seasons.Seasons {
|
||||
for _, s := range seasons.Seasons {
|
||||
<a
|
||||
class="bg-mantle border border-surface1 rounded-lg p-6 hover:bg-surface0 transition-colors"
|
||||
href={ fmt.Sprintf("/seasons/%s", season.ShortName) }
|
||||
href={ fmt.Sprintf("/seasons/%s", s.ShortName) }
|
||||
>
|
||||
<h3 class="text-xl font-bold text-text mb-2">{ season.Name }</h3>
|
||||
<!-- Header: Name + Status Badge -->
|
||||
<div class="flex justify-between items-start mb-3">
|
||||
<h3 class="text-xl font-bold text-text">{ s.Name }</h3>
|
||||
@season.StatusBadge(&s, true, true)
|
||||
</div>
|
||||
<!-- Info Row: Short Name + Start Date -->
|
||||
<div class="flex items-center gap-3 text-sm">
|
||||
<span class="px-2 py-1 bg-surface1 rounded text-subtext0 font-mono">
|
||||
{ s.ShortName }
|
||||
</span>
|
||||
<span class="text-subtext0">
|
||||
Started: { formatDate(s.StartDate) }
|
||||
</span>
|
||||
</div>
|
||||
</a>
|
||||
}
|
||||
</div>
|
||||
@@ -90,3 +105,7 @@ templ SeasonsList(seasons *db.SeasonList) {
|
||||
<script src="/static/js/pagination.js"></script>
|
||||
</div>
|
||||
}
|
||||
|
||||
func formatDate(t time.Time) string {
|
||||
return t.Format("02/01/2006") // DD/MM/YYYY
|
||||
}
|
||||
|
||||
@@ -318,6 +318,9 @@
|
||||
.mb-2 {
|
||||
margin-bottom: calc(var(--spacing) * 2);
|
||||
}
|
||||
.mb-3 {
|
||||
margin-bottom: calc(var(--spacing) * 3);
|
||||
}
|
||||
.mb-4 {
|
||||
margin-bottom: calc(var(--spacing) * 4);
|
||||
}
|
||||
@@ -439,9 +442,6 @@
|
||||
.flex-1 {
|
||||
flex: 1;
|
||||
}
|
||||
.flex-shrink-0 {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.shrink-0 {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user