mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 13:46:44 -04:00
Add a standalone bracket display.
This commit is contained in:
@@ -30,6 +30,7 @@ const (
|
||||
AllianceStationDisplay
|
||||
AnnouncerDisplay
|
||||
AudienceDisplay
|
||||
BracketDisplay
|
||||
FieldMonitorDisplay
|
||||
QueueingDisplay
|
||||
RankingsDisplay
|
||||
@@ -41,6 +42,7 @@ var DisplayTypeNames = map[DisplayType]string{
|
||||
AllianceStationDisplay: "Alliance Station",
|
||||
AnnouncerDisplay: "Announcer",
|
||||
AudienceDisplay: "Audience",
|
||||
BracketDisplay: "Bracket",
|
||||
FieldMonitorDisplay: "Field Monitor",
|
||||
QueueingDisplay: "Queueing",
|
||||
RankingsDisplay: "Rankings",
|
||||
@@ -52,6 +54,7 @@ var displayTypePaths = map[DisplayType]string{
|
||||
AllianceStationDisplay: "/displays/alliance_station",
|
||||
AnnouncerDisplay: "/displays/announcer",
|
||||
AudienceDisplay: "/displays/audience",
|
||||
BracketDisplay: "/displays/bracket",
|
||||
FieldMonitorDisplay: "/displays/field_monitor",
|
||||
QueueingDisplay: "/displays/queueing",
|
||||
RankingsDisplay: "/displays/rankings",
|
||||
|
||||
40
static/css/bracket_display.css
Normal file
40
static/css/bracket_display.css
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
Copyright 2022 Team 254. All Rights Reserved.
|
||||
Author: pat@patfairbank.com (Patrick Fairbank)
|
||||
*/
|
||||
|
||||
html {
|
||||
height: 100%;
|
||||
cursor: default;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
}
|
||||
body {
|
||||
height: 100%;
|
||||
background: -moz-linear-gradient(top, #003375 1%, #3C679D 100%); /* FF3.6+ */
|
||||
background: -webkit-linear-gradient(top, #003375 1%, #3C679D 100%); /* Chrome10+,Safari5.1+ */
|
||||
background-repeat: no-repeat;
|
||||
font-family: "FuturaLT";
|
||||
}
|
||||
#column {
|
||||
width: 80%;
|
||||
height: 100%;
|
||||
margin: 0 auto;
|
||||
}
|
||||
#titlebar {
|
||||
padding: 40px 0px;
|
||||
line-height: 50px;
|
||||
font-size: 40px;
|
||||
font-family: "FuturaLTBold";
|
||||
color: #fff;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
#bracket {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
margin: auto auto;
|
||||
text-align: center;
|
||||
}
|
||||
18
static/js/bracket_display.js
Normal file
18
static/js/bracket_display.js
Normal file
@@ -0,0 +1,18 @@
|
||||
// Copyright 2022 Team 254. All Rights Reserved.
|
||||
// Author: pat@patfairbank.com (Patrick Fairbank)
|
||||
//
|
||||
// Client-side methods for the bracket display.
|
||||
|
||||
var websocket;
|
||||
|
||||
// Handles a websocket message to populate the final score data, which also triggers a bracket update.
|
||||
const handleScorePosted = function(data) {
|
||||
$("#bracketSvg").attr("src", "/api/bracket/svg?v=" + new Date().getTime());
|
||||
};
|
||||
|
||||
$(function() {
|
||||
// Set up the websocket back to the server.
|
||||
websocket = new CheesyWebsocket("/displays/bracket/websocket", {
|
||||
scorePosted: function(event) { handleScorePosted(event.data); },
|
||||
});
|
||||
});
|
||||
@@ -78,6 +78,7 @@
|
||||
<li><a href="/display">Placeholder</a></li>
|
||||
<li><a href="/displays/announcer">Announcer</a></li>
|
||||
<li><a href="/displays/audience">Audience</a></li>
|
||||
<li><a href="/displays/bracket">Bracket</a></li>
|
||||
<li><a href="/displays/field_monitor">Field Monitor</a></li>
|
||||
<li><a href="/displays/field_monitor?fta=true">Field Monitor (FTA)</a></li>
|
||||
<li><a href="/displays/queueing">Queueing</a></li>
|
||||
|
||||
33
templates/bracket_display.html
Normal file
33
templates/bracket_display.html
Normal file
@@ -0,0 +1,33 @@
|
||||
{{/*
|
||||
Copyright 2022 Team 254. All Rights Reserved.
|
||||
Author: pat@patfairbank.com (Patrick Fairbank)
|
||||
|
||||
Display for showing the playoff bracket.
|
||||
*/}}
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Bracket Display - {{.EventSettings.Name}} - Cheesy Arena </title>
|
||||
<link rel="shortcut icon" href="/static/img/favicon.ico">
|
||||
<link rel="stylesheet" href="/static/css/lib/bootstrap.min.css" />
|
||||
<link rel="stylesheet" href="/static/css/cheesy-arena.css" />
|
||||
<link rel="stylesheet" href="/static/css/bracket_display.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="column">
|
||||
<div id="titlebar">
|
||||
<div class="pull-left">Playoff Bracket</div>
|
||||
<div class="pull-right">{{.EventSettings.Name}}</div>
|
||||
<div> </div>
|
||||
</div>
|
||||
<div id="bracket">
|
||||
<img id="bracketSvg" src="" />
|
||||
</div>
|
||||
</div>
|
||||
<script src="/static/js/lib/jquery.min.js"></script>
|
||||
<script src="/static/js/lib/jquery.json-2.4.min.js"></script>
|
||||
<script src="/static/js/lib/jquery.websocket-0.0.1.js"></script>
|
||||
<script src="/static/js/cheesy-websocket.js"></script>
|
||||
<script src="/static/js/bracket_display.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -244,6 +244,9 @@ func (web *Web) allianceSelectionFinalizeHandler(w http.ResponseWriter, r *http.
|
||||
}
|
||||
}
|
||||
|
||||
// Signal displays of the bracket to update themselves.
|
||||
web.arena.ScorePostedNotifier.Notify()
|
||||
|
||||
http.Redirect(w, r, "/alliance_selection", 303)
|
||||
}
|
||||
|
||||
|
||||
53
web/bracket_display.go
Normal file
53
web/bracket_display.go
Normal file
@@ -0,0 +1,53 @@
|
||||
// Copyright 2022 Team 254. All Rights Reserved.
|
||||
// Author: pat@patfairbank.com (Patrick Fairbank)
|
||||
//
|
||||
// Web handlers for the bracket display.
|
||||
|
||||
package web
|
||||
|
||||
import (
|
||||
"github.com/Team254/cheesy-arena-lite/model"
|
||||
"github.com/Team254/cheesy-arena-lite/websocket"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Renders the display which shows the playoff bracket.
|
||||
func (web *Web) bracketDisplayHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if !web.enforceDisplayConfiguration(w, r, nil) {
|
||||
return
|
||||
}
|
||||
|
||||
template, err := web.parseFiles("templates/bracket_display.html")
|
||||
if err != nil {
|
||||
handleWebErr(w, err)
|
||||
return
|
||||
}
|
||||
data := struct {
|
||||
*model.EventSettings
|
||||
}{web.arena.EventSettings}
|
||||
err = template.ExecuteTemplate(w, "bracket_display.html", data)
|
||||
if err != nil {
|
||||
handleWebErr(w, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// The websocket endpoint for the bracket display.
|
||||
func (web *Web) bracketDisplayWebsocketHandler(w http.ResponseWriter, r *http.Request) {
|
||||
display, err := web.registerDisplay(r)
|
||||
if err != nil {
|
||||
handleWebErr(w, err)
|
||||
return
|
||||
}
|
||||
defer web.arena.MarkDisplayDisconnected(display.DisplayConfiguration.Id)
|
||||
|
||||
ws, err := websocket.NewWebsocket(w, r)
|
||||
if err != nil {
|
||||
handleWebErr(w, err)
|
||||
return
|
||||
}
|
||||
defer ws.Close()
|
||||
|
||||
// Subscribe the websocket to the notifiers whose messages will be passed on to the client.
|
||||
ws.HandleNotifiers(display.Notifier, web.arena.ScorePostedNotifier, web.arena.ReloadDisplaysNotifier)
|
||||
}
|
||||
34
web/bracket_display_test.go
Normal file
34
web/bracket_display_test.go
Normal file
@@ -0,0 +1,34 @@
|
||||
// Copyright 2022 Team 254. All Rights Reserved.
|
||||
// Author: pat@patfairbank.com (Patrick Fairbank)
|
||||
|
||||
package web
|
||||
|
||||
import (
|
||||
"github.com/Team254/cheesy-arena-lite/websocket"
|
||||
gorillawebsocket "github.com/gorilla/websocket"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBracketDisplay(t *testing.T) {
|
||||
web := setupTestWeb(t)
|
||||
|
||||
recorder := web.getHttpResponse("/displays/bracket?displayId=1")
|
||||
assert.Equal(t, 200, recorder.Code)
|
||||
assert.Contains(t, recorder.Body.String(), "Bracket Display - Untitled Event - Cheesy Arena")
|
||||
}
|
||||
|
||||
func TestBracketDisplayWebsocket(t *testing.T) {
|
||||
web := setupTestWeb(t)
|
||||
|
||||
server, wsUrl := web.startTestServer()
|
||||
defer server.Close()
|
||||
conn, _, err := gorillawebsocket.DefaultDialer.Dial(wsUrl+"/displays/bracket/websocket?displayId=1", nil)
|
||||
assert.Nil(t, err)
|
||||
defer conn.Close()
|
||||
ws := websocket.NewTestWebsocket(conn)
|
||||
|
||||
// Should get a few status updates right after connection.
|
||||
readWebsocketType(t, ws, "displayConfiguration")
|
||||
readWebsocketType(t, ws, "scorePosted")
|
||||
}
|
||||
@@ -130,6 +130,8 @@ func (web *Web) newHandler() http.Handler {
|
||||
router.HandleFunc("/displays/announcer/websocket", web.announcerDisplayWebsocketHandler).Methods("GET")
|
||||
router.HandleFunc("/displays/audience", web.audienceDisplayHandler).Methods("GET")
|
||||
router.HandleFunc("/displays/audience/websocket", web.audienceDisplayWebsocketHandler).Methods("GET")
|
||||
router.HandleFunc("/displays/bracket", web.bracketDisplayHandler).Methods("GET")
|
||||
router.HandleFunc("/displays/bracket/websocket", web.bracketDisplayWebsocketHandler).Methods("GET")
|
||||
router.HandleFunc("/displays/field_monitor", web.fieldMonitorDisplayHandler).Methods("GET")
|
||||
router.HandleFunc("/displays/field_monitor/websocket", web.fieldMonitorDisplayWebsocketHandler).Methods("GET")
|
||||
router.HandleFunc("/displays/queueing", web.queueingDisplayHandler).Methods("GET")
|
||||
|
||||
Reference in New Issue
Block a user