Files
cheesy-arena-lite/setup_field.go
2017-08-27 13:54:24 -07:00

69 lines
1.7 KiB
Go

// 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"
"html/template"
"net/http"
)
// Shows the field configuration page.
func FieldGetHandler(w http.ResponseWriter, r *http.Request) {
if !UserIsAdmin(w, r) {
return
}
template, err := template.ParseFiles("templates/setup_field.html", "templates/base.html")
if err != nil {
handleWebErr(w, err)
return
}
data := struct {
*model.EventSettings
AllianceStationDisplays map[string]string
LightsMode string
}{eventSettings, mainArena.allianceStationDisplays, mainArena.lights.currentMode}
err = template.ExecuteTemplate(w, "base", data)
if err != nil {
handleWebErr(w, err)
return
}
}
// Updates the display-station mapping for a single display.
func FieldPostHandler(w http.ResponseWriter, r *http.Request) {
if !UserIsAdmin(w, r) {
return
}
displayId := r.PostFormValue("displayId")
allianceStation := r.PostFormValue("allianceStation")
mainArena.allianceStationDisplays[displayId] = allianceStation
mainArena.matchLoadTeamsNotifier.Notify(nil)
http.Redirect(w, r, "/setup/field", 302)
}
// Force-reloads all the websocket-connected displays.
func FieldReloadDisplaysHandler(w http.ResponseWriter, r *http.Request) {
if !UserIsAdmin(w, r) {
return
}
mainArena.reloadDisplaysNotifier.Notify(nil)
http.Redirect(w, r, "/setup/field", 302)
}
// Controls the field LEDs for testing or effect.
func FieldLightsPostHandler(w http.ResponseWriter, r *http.Request) {
if !UserIsAdmin(w, r) {
return
}
mainArena.lights.SetMode(r.PostFormValue("mode"))
http.Redirect(w, r, "/setup/field", 302)
}