added season types and changed new season to be a modal
This commit is contained in:
@@ -16,11 +16,13 @@ import (
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
// NewSeason handles GET requests - redirects to the seasons list
|
||||
// The form is now in a modal on the list page
|
||||
func NewSeason(
|
||||
s *hws.Server,
|
||||
) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
renderSafely(seasonsview.NewPage(), s, r, w)
|
||||
respond.HXRedirect(w, "/seasons")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -41,6 +43,8 @@ func NewSeasonSubmit(
|
||||
MaxLength(6).MinLength(2).Value
|
||||
version := getter.String("slap_version").
|
||||
TrimSpace().Required().AllowedValues([]string{"rebound", "slapshot1"}).Value
|
||||
type_ := getter.String("type").
|
||||
TrimSpace().Required().AllowedValues([]string{"regular", "draft"}).Value
|
||||
format := timefmt.NewBuilder().
|
||||
DayNumeric2().Slash().
|
||||
MonthNumeric2().Slash().
|
||||
@@ -52,7 +56,6 @@ func NewSeasonSubmit(
|
||||
|
||||
nameUnique := false
|
||||
shortNameUnique := false
|
||||
var season *db.Season
|
||||
if ok := conn.WithNotifyTx(s, w, r, func(ctx context.Context, tx bun.Tx) (bool, error) {
|
||||
var err error
|
||||
nameUnique, err = db.IsUnique(ctx, tx, (*db.Season)(nil), "name", name)
|
||||
@@ -66,7 +69,7 @@ func NewSeasonSubmit(
|
||||
if !nameUnique || !shortNameUnique {
|
||||
return true, nil
|
||||
}
|
||||
season, err = db.NewSeason(ctx, tx, name, version, shortname, start, db.NewAuditFromRequest(r))
|
||||
_, err = db.NewSeason(ctx, tx, name, version, shortname, type_, start, db.NewAuditFromRequest(r))
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "db.NewSeason")
|
||||
}
|
||||
@@ -84,7 +87,26 @@ func NewSeasonSubmit(
|
||||
notify.Warn(s, w, r, "Duplicate Short Name", "This short name is already taken.", nil)
|
||||
return
|
||||
}
|
||||
respond.HXRedirect(w, "/seasons/%s", season.ShortName)
|
||||
notify.SuccessWithDelay(s, w, r, "Season Created", fmt.Sprintf("Successfully created season: %s", name), nil)
|
||||
|
||||
// Return the updated seasons list
|
||||
pageOpts := &db.PageOpts{
|
||||
Page: 1,
|
||||
PerPage: 10,
|
||||
Order: bun.OrderDesc,
|
||||
OrderBy: "start_date",
|
||||
}
|
||||
var seasons *db.List[db.Season]
|
||||
if ok := conn.WithReadTx(s, w, r, func(ctx context.Context, tx bun.Tx) (bool, error) {
|
||||
var err error
|
||||
seasons, err = db.ListSeasons(ctx, tx, pageOpts)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "db.ListSeasons")
|
||||
}
|
||||
return true, nil
|
||||
}); !ok {
|
||||
return
|
||||
}
|
||||
renderSafely(seasonsview.SeasonsList(seasons), s, r, w)
|
||||
notify.Success(s, w, r, "Season Created", fmt.Sprintf("Successfully created season: %s", name), nil)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user