-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add page to customize playoff break descriptions (closes #171).
- Loading branch information
Showing
7 changed files
with
164 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{{/* | ||
Copyright 2024 Team 254. All Rights Reserved. | ||
Author: [email protected] (Patrick Fairbank) | ||
|
||
UI for configuring scheduled breaks. | ||
*/}} | ||
{{define "title"}}Breaks Configuration{{end}} | ||
{{define "body"}} | ||
<div class="row justify-content-center"> | ||
<div class="col-lg-6"> | ||
<div class="card card-body bg-body-tertiary"> | ||
<legend>Scheduled Break Configuration</legend> | ||
{{if not .ScheduledBreaks}} | ||
<p> | ||
Playoff breaks won't appear here until alliance selection is complete and the playoff tournament is created. | ||
</p> | ||
{{end}} | ||
{{range $i, $scheduledBreak := .ScheduledBreaks}} | ||
<form method="POST"> | ||
<h5>Break #{{add $i 1}}</h5> | ||
<input type="hidden" name="id" value="{{$scheduledBreak.Id}}" /> | ||
<div class="row mb-3"> | ||
<div class="col-lg-3"> | ||
<label class="control-label">Description</label> | ||
</div> | ||
<div class="col-lg-6"> | ||
<input type="text" class="form-control" name="description" value="{{$scheduledBreak.Description}}"> | ||
</div> | ||
<div class="col-lg-3"> | ||
<button type="submit" class="btn btn-primary btn-lower-third mb-1" name="action" value="save"> | ||
Save | ||
</button> | ||
</div> | ||
</div> | ||
</form> | ||
{{end}} | ||
</div> | ||
</div> | ||
</div> | ||
{{end}} | ||
{{define "script"}} | ||
{{end}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2024 Team 254. All Rights Reserved. | ||
// Author: [email protected] (Patrick Fairbank) | ||
// | ||
// Web routes for managing scheduled breaks. | ||
|
||
package web | ||
|
||
import ( | ||
"github.com/Team254/cheesy-arena/model" | ||
"net/http" | ||
"strconv" | ||
) | ||
|
||
// Shows the breaks configuration page. | ||
func (web *Web) breaksGetHandler(w http.ResponseWriter, r *http.Request) { | ||
if !web.userIsAdmin(w, r) { | ||
return | ||
} | ||
|
||
template, err := web.parseFiles("templates/setup_breaks.html", "templates/base.html") | ||
if err != nil { | ||
handleWebErr(w, err) | ||
return | ||
} | ||
breaks, err := web.arena.Database.GetScheduledBreaksByMatchType(model.Playoff) | ||
if err != nil { | ||
handleWebErr(w, err) | ||
return | ||
} | ||
data := struct { | ||
*model.EventSettings | ||
ScheduledBreaks []model.ScheduledBreak | ||
}{web.arena.EventSettings, breaks} | ||
err = template.ExecuteTemplate(w, "base", data) | ||
if err != nil { | ||
handleWebErr(w, err) | ||
return | ||
} | ||
} | ||
|
||
// Saves the modified breaks to the database. | ||
func (web *Web) breaksPostHandler(w http.ResponseWriter, r *http.Request) { | ||
if !web.userIsAdmin(w, r) { | ||
return | ||
} | ||
|
||
scheduledBreakId, _ := strconv.Atoi(r.PostFormValue("id")) | ||
scheduledBreak, err := web.arena.Database.GetScheduledBreakById(scheduledBreakId) | ||
if err != nil { | ||
handleWebErr(w, err) | ||
return | ||
} | ||
scheduledBreak.Description = r.PostFormValue("description") | ||
if err = web.arena.Database.UpdateScheduledBreak(scheduledBreak); err != nil { | ||
handleWebErr(w, err) | ||
return | ||
} | ||
|
||
http.Redirect(w, r, "/setup/breaks", 303) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2024 Team 254. All Rights Reserved. | ||
// Author: [email protected] (Patrick Fairbank) | ||
|
||
package web | ||
|
||
import ( | ||
"github.com/Team254/cheesy-arena/model" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestSetupBreaks(t *testing.T) { | ||
web := setupTestWeb(t) | ||
|
||
web.arena.Database.CreateScheduledBreak( | ||
&model.ScheduledBreak{0, model.Playoff, 4, time.Unix(500, 0).UTC(), 900, "Field Break 1"}, | ||
) | ||
web.arena.Database.CreateScheduledBreak( | ||
&model.ScheduledBreak{0, model.Playoff, 4, time.Unix(500, 0).UTC(), 900, "Field Break 2"}, | ||
) | ||
|
||
recorder := web.getHttpResponse("/setup/breaks") | ||
assert.Equal(t, 200, recorder.Code) | ||
assert.Contains(t, recorder.Body.String(), "Field Break 1") | ||
assert.Contains(t, recorder.Body.String(), "Field Break 2") | ||
|
||
recorder = web.postHttpResponse("/setup/breaks", "id=2&description=Award Break 3") | ||
assert.Equal(t, 303, recorder.Code) | ||
recorder = web.getHttpResponse("/setup/breaks") | ||
assert.Equal(t, 200, recorder.Code) | ||
assert.Contains(t, recorder.Body.String(), "Field Break 1") | ||
assert.NotContains(t, recorder.Body.String(), "Field Break 2") | ||
assert.Contains(t, recorder.Body.String(), "Award Break 3") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters