diff --git a/internal/embedfs/web/css/output.css b/internal/embedfs/web/css/output.css index 2f3e384..15ea92e 100644 --- a/internal/embedfs/web/css/output.css +++ b/internal/embedfs/web/css/output.css @@ -489,9 +489,6 @@ .w-20 { width: calc(var(--spacing) * 20); } - .w-24 { - width: calc(var(--spacing) * 24); - } .w-26 { width: calc(var(--spacing) * 26); } diff --git a/internal/handlers/fixtures.go b/internal/handlers/fixtures.go index fbc9aac..4c01d92 100644 --- a/internal/handlers/fixtures.go +++ b/internal/handlers/fixtures.go @@ -2,6 +2,7 @@ package handlers import ( "context" + "fmt" "net/http" "strconv" @@ -69,6 +70,7 @@ func UpdateFixtures( leagueShortName := getter.String("league_short_name").TrimSpace().Required().Value allocations := getter.GetMaps("allocations") if !getter.ValidateAndNotify(s, w, r) { + w.WriteHeader(http.StatusBadRequest) return } updates, err := mapUpdates(allocations) @@ -91,6 +93,7 @@ func UpdateFixtures( } var valid bool fixtures, valid = updateFixtures(fixtures, updates) + fmt.Println(len(fixtures)) if !valid { notify.Warn(s, w, r, "Invalid game weeks", "A game week is missing or has no games", nil) return false, nil @@ -158,10 +161,27 @@ func updateFixtures(fixtures []*db.Fixture, updates map[int]int) ([]*db.Fixture, gameWeeks := map[int]int{} for _, fixture := range fixtures { if gameWeek, exists := updates[fixture.ID]; exists { - fixture.GameWeek = &gameWeek - updated = append(updated, fixture) + var newValue *int + var oldValue int + if fixture.GameWeek != nil { + oldValue = *fixture.GameWeek + } else { + oldValue = 0 + } + if gameWeek == 0 { + newValue = nil + } else { + newValue = &gameWeek + } + if gameWeek != oldValue { + fixture.GameWeek = newValue + updated = append(updated, fixture) + } + // fuck i hate pointers sometimes + } + if fixture.GameWeek != nil { + gameWeeks[*fixture.GameWeek]++ } - gameWeeks[*fixture.GameWeek]++ } for i := range len(gameWeeks) { count, exists := gameWeeks[i+1] diff --git a/internal/validation/forms.go b/internal/validation/forms.go index c691e79..675e29d 100644 --- a/internal/validation/forms.go +++ b/internal/validation/forms.go @@ -3,7 +3,6 @@ package validation import ( "net/http" "regexp" - "strconv" "strings" "git.haelnorr.com/h/golib/hws" @@ -32,18 +31,24 @@ func (f *FormGetter) GetList(key string) []string { } func (f *FormGetter) GetMaps(key string) []map[string]string { - var result []map[string]string - for key, values := range f.r.Form { - re := regexp.MustCompile(key + "\\[([0-9]+)\\]\\[([a-zA-Z]+)\\]") - matches := re.FindStringSubmatch(key) + results := map[string]map[string]string{} + re := regexp.MustCompile(key + "\\[([0-9]+)\\]\\[([a-zA-Z_]+)\\]") + for k, v := range f.r.Form { + matches := re.FindStringSubmatch(k) if len(matches) >= 3 { - index, _ := strconv.Atoi(matches[1]) - for index >= len(result) { - result = append(result, map[string]string{}) + realKey := matches[1] + field := matches[2] + value := strings.Join(v, ",") + if _, exists := results[realKey]; !exists { + results[realKey] = map[string]string{} } - result[index][matches[2]] = values[0] + results[realKey][field] = value } } + result := []map[string]string{} + for _, v := range results { + result = append(result, v) + } return result } diff --git a/internal/view/seasonsview/season_league_fixtures_manage.templ b/internal/view/seasonsview/season_league_fixtures_manage.templ index 3697c55..365d4e2 100644 --- a/internal/view/seasonsview/season_league_fixtures_manage.templ +++ b/internal/view/seasonsview/season_league_fixtures_manage.templ @@ -60,18 +60,19 @@ templ SeasonLeagueManageFixtures(season *db.Season, league *db.League, fixtures
- Round: +
- + - - - - All game weeks must have at least 1 fixture - + +
+ + All game weeks must have at least 1 fixture + + + +
@@ -114,7 +123,7 @@ templ SeasonLeagueManageFixtures(season *db.Season, league *db.League, fixtures

Game Weeks

- No game weeks yet. Add one to start allocating fixtures. + No game weeks yet. Generate fixtures to get started.