2014-09-06 17:06:06 -07:00
|
|
|
// Copyright 2014 Team 254. All Rights Reserved.
|
|
|
|
|
// Author: pat@patfairbank.com (Patrick Fairbank)
|
|
|
|
|
//
|
|
|
|
|
// Web handlers for the FTA diagnostic display.
|
|
|
|
|
|
2017-08-31 23:26:22 -07:00
|
|
|
package web
|
2014-09-06 17:06:06 -07:00
|
|
|
|
|
|
|
|
import (
|
2017-08-23 22:41:56 -07:00
|
|
|
"github.com/Team254/cheesy-arena/model"
|
2018-08-31 22:40:08 -07:00
|
|
|
"github.com/Team254/cheesy-arena/websocket"
|
2014-09-06 17:06:06 -07:00
|
|
|
"net/http"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Renders the FTA diagnostic display.
|
2017-08-28 20:14:32 -07:00
|
|
|
func (web *Web) ftaDisplayHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
if !web.userIsAdmin(w, r) {
|
2015-08-22 23:33:38 -07:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-31 23:26:22 -07:00
|
|
|
template, err := web.parseFiles("templates/fta_display.html", "templates/base.html")
|
2014-09-06 17:06:06 -07:00
|
|
|
if err != nil {
|
|
|
|
|
handleWebErr(w, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
data := struct {
|
2017-08-23 22:41:56 -07:00
|
|
|
*model.EventSettings
|
2017-08-28 20:14:32 -07:00
|
|
|
}{web.arena.EventSettings}
|
2018-09-03 16:46:57 -07:00
|
|
|
err = template.ExecuteTemplate(w, "base_no_navbar", data)
|
2014-09-06 17:06:06 -07:00
|
|
|
if err != nil {
|
|
|
|
|
handleWebErr(w, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-13 21:07:14 -07:00
|
|
|
|
|
|
|
|
// The websocket endpoint for the FTA display client to receive status updates.
|
2017-08-28 20:14:32 -07:00
|
|
|
func (web *Web) ftaDisplayWebsocketHandler(w http.ResponseWriter, r *http.Request) {
|
2016-08-13 21:07:14 -07:00
|
|
|
// TODO(patrick): Enable authentication once Safari (for iPad) supports it over Websocket.
|
|
|
|
|
|
2018-08-31 22:40:08 -07:00
|
|
|
ws, err := websocket.NewWebsocket(w, r)
|
2016-08-13 21:07:14 -07:00
|
|
|
if err != nil {
|
|
|
|
|
handleWebErr(w, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
2018-08-31 22:40:08 -07:00
|
|
|
defer ws.Close()
|
2016-08-13 21:07:14 -07:00
|
|
|
|
2018-08-31 22:40:08 -07:00
|
|
|
// Subscribe the websocket to the notifiers whose messages will be passed on to the client.
|
|
|
|
|
ws.HandleNotifiers(web.arena.ArenaStatusNotifier, web.arena.ReloadDisplaysNotifier)
|
2016-08-13 21:07:14 -07:00
|
|
|
}
|