implemented radio button system for entering the games
This commit is contained in:
@@ -54,10 +54,16 @@ func postEnter(c *gin.Context) {
|
||||
}
|
||||
|
||||
// Parse form
|
||||
a1h := strings.TrimSpace(c.PostForm("a1"))
|
||||
a2h := strings.TrimSpace(c.PostForm("a2"))
|
||||
b1h := strings.TrimSpace(c.PostForm("b1"))
|
||||
b2h := strings.TrimSpace(c.PostForm("b2"))
|
||||
p1h := strings.TrimSpace(c.PostForm("p1"))
|
||||
p2h := strings.TrimSpace(c.PostForm("p2"))
|
||||
p3h := strings.TrimSpace(c.PostForm("p3"))
|
||||
p4h := strings.TrimSpace(c.PostForm("p4"))
|
||||
|
||||
p1t := strings.TrimSpace(c.PostForm("team_p1"))
|
||||
p2t := strings.TrimSpace(c.PostForm("team_p2"))
|
||||
p3t := strings.TrimSpace(c.PostForm("team_p3"))
|
||||
p4t := strings.TrimSpace(c.PostForm("team_p4"))
|
||||
|
||||
scoreA := atoiSafe(c.PostForm("scoreA"))
|
||||
scoreB := atoiSafe(c.PostForm("scoreB"))
|
||||
|
||||
@@ -84,25 +90,46 @@ func postEnter(c *gin.Context) {
|
||||
return u, nil
|
||||
}
|
||||
|
||||
var a1, a2, b1, b2 *User
|
||||
var p1, p2, p3, p4 *User
|
||||
|
||||
// Always ensure A1 exists, fallback to current if empty
|
||||
var err error
|
||||
if a1, err = resolveUser(a1h); err != nil {
|
||||
if p1, err = resolveUser(p1h); err != nil {
|
||||
return
|
||||
}
|
||||
if a2, err = resolveUser(a2h); err != nil {
|
||||
if p2, err = resolveUser(p2h); err != nil {
|
||||
return
|
||||
}
|
||||
if b1, err = resolveUser(b1h); err != nil {
|
||||
if p3, err = resolveUser(p3h); err != nil {
|
||||
return
|
||||
}
|
||||
if b2, err = resolveUser(b2h); err != nil {
|
||||
if p4, err = resolveUser(p4h); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Generate raw teams
|
||||
var players []Player
|
||||
var team1ps, team2ps []Player
|
||||
users := []*User{p1, p2, p3, p4}
|
||||
sides := []string{p1t, p2t, p3t, p4t}
|
||||
var playerbuf []float64
|
||||
|
||||
for i, u := range users {
|
||||
if u != nil {
|
||||
if sides[i] == "A" || sides[i] == "B" {
|
||||
players = append(players, Player{u, sides[i], 0})
|
||||
playerbuf = append(playerbuf, u.Elo)
|
||||
if sides[i] == "A" {
|
||||
team1ps = append(team1ps, Player{u, sides[i], 0})
|
||||
} else {
|
||||
team2ps = append(team2ps, Player{u, sides[i], 0})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check for at least one player on each side
|
||||
if b1 == nil && b2 == nil || a1 == nil && a2 == nil {
|
||||
if len(team1ps) == 0 || len(team2ps) == 0 {
|
||||
SaveForm(c)
|
||||
SetMessage(c, "There must be at least one player on each side")
|
||||
c.Redirect(http.StatusSeeOther, "/enter")
|
||||
@@ -111,7 +138,6 @@ func postEnter(c *gin.Context) {
|
||||
|
||||
// Check for duplicate users
|
||||
seen := map[uint]bool{}
|
||||
users := []*User{a1, a2, b1, b2}
|
||||
for i, u := range users {
|
||||
if u != nil {
|
||||
if seen[u.ID] {
|
||||
@@ -148,25 +174,8 @@ func postEnter(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var players []Player
|
||||
fmt.Println("Len players", len(players))
|
||||
var playerbuf []float64
|
||||
for i, user := range users {
|
||||
if user != nil {
|
||||
var side string
|
||||
if i > 1 {
|
||||
side = "B"
|
||||
} else {
|
||||
side = "A"
|
||||
}
|
||||
players = append(players, Player{u: user, side: side, dElo: 0})
|
||||
playerbuf = append(playerbuf, user.Elo)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
team1 := NewTeam(players[:len(players)/2], g.ScoreA)
|
||||
team2 := NewTeam(players[len(players)/2:], g.ScoreB)
|
||||
team1 := NewTeam(team1ps, g.ScoreA)
|
||||
team2 := NewTeam(team2ps, g.ScoreB)
|
||||
|
||||
// Set new elo for all players
|
||||
GetNewElo([]*Team{team1, team2})
|
||||
|
||||
@@ -8,34 +8,81 @@
|
||||
{{end}}
|
||||
|
||||
<form method="POST" action="/enter">
|
||||
<div class="row">
|
||||
<div style="flex:1;min-width:180px">
|
||||
<h3>Team A</h3>
|
||||
<label class="label">Player A1</label>
|
||||
<input class="input" name="a1" {{if (index .Form "a1")}}value="{{index .Form "a1"}}"{{else}}value="{{.CurrentUser.Username}}"{{end}} placeholder="username or email">
|
||||
<div style="height:6px"></div>
|
||||
<label class="label">Player A2 (optional)</label>
|
||||
<input class="input" name="a2" value="{{index .Form "a2"}}" placeholder="username or email">
|
||||
<div style="height:12px"></div>
|
||||
<label class="label">Score A</label>
|
||||
<input class="input" type="number" name="scoreA" value="{{index .Form "scoreA"}}" placeholder="0" min="0" max="10" required>
|
||||
<div class="players">
|
||||
{{/* Player 1 */}}
|
||||
<div class="player-row">
|
||||
<input class="input" name="p1"
|
||||
{{if (index .Form "p1")}}value="{{index .Form "p1"}}"{{else}}value="{{.CurrentUser.Username}}"{{end}}
|
||||
placeholder="Player 1">
|
||||
<div class="team-choice">
|
||||
<label><input type="radio" name="team_p1" value="A" checked>A</label>
|
||||
<label><input type="radio" name="team_p1" value="B">B</label>
|
||||
<label><input type="radio" name="team_p1" value="none">None</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="flex:1;min-width:180px">
|
||||
<h3>Team B</h3>
|
||||
<label class="label">Player B1</label>
|
||||
<input class="input" name="b1" value="{{index .Form "b1"}}" placeholder="username or email">
|
||||
<div style="height:6px"></div>
|
||||
<label class="label">Player B2 (optional)</label>
|
||||
<input class="input" name="b2" value="{{index .Form "b2"}}" placeholder="username or email">
|
||||
<div style="height:12px"></div>
|
||||
<label class="label">Score B</label>
|
||||
<input class="input" type="number" name="scoreB" value="{{index .Form "scoreB"}}" placeholder="0" min="0" max="10" required>
|
||||
{{/* Player 2 */}}
|
||||
<div class="player-row">
|
||||
<input class="input" name="p2" value="{{index .Form "p2"}}" placeholder="Player 2">
|
||||
<div class="team-choice">
|
||||
<label><input type="radio" name="team_p2" value="A">A</label>
|
||||
<label><input type="radio" name="team_p2" value="B" checked>B</label>
|
||||
<label><input type="radio" name="team_p2" value="none">None</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{/* Player 3 */}}
|
||||
<div class="player-row">
|
||||
<input class="input" name="p3" value="{{index .Form "p3"}}" placeholder="Player 3 (optional)">
|
||||
<div class="team-choice">
|
||||
<label><input type="radio" name="team_p3" value="A">A</label>
|
||||
<label><input type="radio" name="team_p3" value="B">B</label>
|
||||
<label><input type="radio" name="team_p3" value="none" checked>None</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{/* Player 3 */}}
|
||||
<div class="player-row">
|
||||
<input class="input" name="p4" value="{{index .Form "p4"}}" placeholder="Player 4 (optional)">
|
||||
<div class="team-choice">
|
||||
<label><input type="radio" name="team_p4" value="A">A</label>
|
||||
<label><input type="radio" name="team_p4" value="B">B</label>
|
||||
<label><input type="radio" name="team_p4" value="none" checked>None</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="height:12px"></div>
|
||||
<div style="height:16px"></div>
|
||||
|
||||
<div class="scores">
|
||||
<label class="label">Score Team A</label>
|
||||
<input class="input" type="number" name="scoreA" value="{{index .Form "scoreA"}}" placeholder="0" min="0" max="10" required>
|
||||
|
||||
<div style="height:12px"></div>
|
||||
|
||||
<label class="label">Score Team B</label>
|
||||
<input class="input" type="number" name="scoreB" value="{{index .Form "scoreB"}}" placeholder="0" min="0" max="10" required>
|
||||
</div>
|
||||
|
||||
<div style="height:16px"></div>
|
||||
<button class="btn btn-primary" type="submit">Submit result</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.player-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.team-choice {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
font-size: 14px;
|
||||
}
|
||||
.players {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
</style>
|
||||
{{end}}
|
||||
|
||||
Reference in New Issue
Block a user