Files
cheesy-arena-lite/setup_field.go

58 lines
1.5 KiB
Go
Raw Normal View History

2014-08-04 00:52:46 -07:00
// Copyright 2014 Team 254. All Rights Reserved.
// Author: pat@patfairbank.com (Patrick Fairbank)
//
// Web routes for configuring the field components.
package main
import (
"github.com/Team254/cheesy-arena/model"
2014-08-04 00:52:46 -07:00
"html/template"
"net/http"
)
// Shows the field configuration page.
func (web *Web) fieldGetHandler(w http.ResponseWriter, r *http.Request) {
if !web.userIsAdmin(w, r) {
2015-08-22 23:33:38 -07:00
return
}
2014-09-06 17:38:21 -07:00
template, err := template.ParseFiles("templates/setup_field.html", "templates/base.html")
2014-08-04 00:52:46 -07:00
if err != nil {
handleWebErr(w, err)
return
}
data := struct {
*model.EventSettings
2014-08-04 00:52:46 -07:00
AllianceStationDisplays map[string]string
}{web.arena.EventSettings, web.arena.AllianceStationDisplays}
2014-08-04 00:52:46 -07:00
err = template.ExecuteTemplate(w, "base", data)
if err != nil {
handleWebErr(w, err)
return
}
}
// Updates the display-station mapping for a single display.
func (web *Web) fieldPostHandler(w http.ResponseWriter, r *http.Request) {
if !web.userIsAdmin(w, r) {
2015-08-22 23:33:38 -07:00
return
}
2014-08-04 00:52:46 -07:00
displayId := r.PostFormValue("displayId")
allianceStation := r.PostFormValue("allianceStation")
web.arena.AllianceStationDisplays[displayId] = allianceStation
web.arena.MatchLoadTeamsNotifier.Notify(nil)
2014-08-04 00:52:46 -07:00
http.Redirect(w, r, "/setup/field", 302)
}
// Force-reloads all the websocket-connected displays.
func (web *Web) fieldReloadDisplaysHandler(w http.ResponseWriter, r *http.Request) {
if !web.userIsAdmin(w, r) {
2015-08-22 23:33:38 -07:00
return
}
web.arena.ReloadDisplaysNotifier.Notify(nil)
2014-08-28 00:12:45 -07:00
http.Redirect(w, r, "/setup/field", 302)
}