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 (
|
2017-08-23 22:41:56 -07:00
|
|
|
"github.com/Team254/cheesy-arena/model"
|
2014-08-04 00:52:46 -07:00
|
|
|
"html/template"
|
|
|
|
|
"net/http"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Shows the field configuration page.
|
|
|
|
|
func FieldGetHandler(w http.ResponseWriter, r *http.Request) {
|
2015-08-22 23:33:38 -07:00
|
|
|
if !UserIsAdmin(w, r) {
|
|
|
|
|
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 {
|
2017-08-23 22:41:56 -07:00
|
|
|
*model.EventSettings
|
2014-08-04 00:52:46 -07:00
|
|
|
AllianceStationDisplays map[string]string
|
2014-08-28 00:12:45 -07:00
|
|
|
LightsMode string
|
|
|
|
|
}{eventSettings, mainArena.allianceStationDisplays, mainArena.lights.currentMode}
|
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 FieldPostHandler(w http.ResponseWriter, r *http.Request) {
|
2015-08-22 23:33:38 -07:00
|
|
|
if !UserIsAdmin(w, r) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-04 00:52:46 -07:00
|
|
|
displayId := r.PostFormValue("displayId")
|
|
|
|
|
allianceStation := r.PostFormValue("allianceStation")
|
|
|
|
|
mainArena.allianceStationDisplays[displayId] = allianceStation
|
|
|
|
|
mainArena.matchLoadTeamsNotifier.Notify(nil)
|
|
|
|
|
http.Redirect(w, r, "/setup/field", 302)
|
|
|
|
|
}
|
2014-08-23 22:04:26 -07:00
|
|
|
|
|
|
|
|
// Force-reloads all the websocket-connected displays.
|
|
|
|
|
func FieldReloadDisplaysHandler(w http.ResponseWriter, r *http.Request) {
|
2015-08-22 23:33:38 -07:00
|
|
|
if !UserIsAdmin(w, r) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-23 22:04:26 -07:00
|
|
|
mainArena.reloadDisplaysNotifier.Notify(nil)
|
|
|
|
|
http.Redirect(w, r, "/setup/field", 302)
|
|
|
|
|
}
|
2014-08-28 00:12:45 -07:00
|
|
|
|
|
|
|
|
// Controls the field LEDs for testing or effect.
|
|
|
|
|
func FieldLightsPostHandler(w http.ResponseWriter, r *http.Request) {
|
2015-08-22 23:33:38 -07:00
|
|
|
if !UserIsAdmin(w, r) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-28 00:12:45 -07:00
|
|
|
mainArena.lights.SetMode(r.PostFormValue("mode"))
|
|
|
|
|
http.Redirect(w, r, "/setup/field", 302)
|
|
|
|
|
}
|