diff --git a/model/event_settings.go b/model/event_settings.go
index 3ae266ab..5e53459a 100644
--- a/model/event_settings.go
+++ b/model/event_settings.go
@@ -72,7 +72,7 @@ func (database *Database) GetEventSettings() (*EventSettings, error) {
NumPlayoffAlliances: 8,
SelectionRound2Order: "L",
SelectionRound3Order: "",
- SelectionShowUnpickedTeams: false,
+ SelectionShowUnpickedTeams: true,
TbaDownloadEnabled: true,
ApChannel: 36,
WarmupDurationSec: game.MatchTiming.WarmupDurationSec,
diff --git a/model/event_settings_test.go b/model/event_settings_test.go
index b30aafc1..059704a7 100644
--- a/model/event_settings_test.go
+++ b/model/event_settings_test.go
@@ -23,6 +23,7 @@ func TestEventSettingsReadWrite(t *testing.T) {
NumPlayoffAlliances: 8,
SelectionRound2Order: "L",
SelectionRound3Order: "",
+ SelectionShowUnpickedTeams: true,
TbaDownloadEnabled: true,
ApChannel: 36,
WarmupDurationSec: 0,
diff --git a/static/js/alliance_selection.js b/static/js/alliance_selection.js
index 75e40e96..560e9ff7 100644
--- a/static/js/alliance_selection.js
+++ b/static/js/alliance_selection.js
@@ -5,14 +5,19 @@
var websocket;
-// Sends a websocket message to show the timer.
-const showTimer = function() {
- websocket.send("showTimer");
+// Sends a websocket message to set the timer to the given time limit.
+const setTimer = function(timeLimitInput) {
+ websocket.send("setTimer", parseInt(timeLimitInput.value));
+}
+
+// Sends a websocket message to start and show the timer.
+const startTimer = function() {
+ websocket.send("startTimer");
};
-// Sends a websocket message to hide the timer.
-const hideTimer = function() {
- websocket.send("hideTimer");
+// Sends a websocket message to stop and hide the timer.
+const stopTimer = function() {
+ websocket.send("stopTimer");
}
// Handles a websocket message to update the alliance selection status.
diff --git a/templates/alliance_selection.html b/templates/alliance_selection.html
index 612a859e..27d4abda 100644
--- a/templates/alliance_selection.html
+++ b/templates/alliance_selection.html
@@ -85,23 +85,18 @@
-
- Timer starts automatically after each non-captain assignment and is hidden on the audience overlay until
- the button below is pressed.
-
+ Timer is hidden on the audience overlay until the Start/Show button below is pressed.
-
-
+
+
diff --git a/web/alliance_selection.go b/web/alliance_selection.go
index d15d0641..25cddea0 100644
--- a/web/alliance_selection.go
+++ b/web/alliance_selection.go
@@ -18,7 +18,7 @@ import (
)
// Global var to hold configurable time limit for selections. A value of zero disables the timer.
-var allianceSelectionTimeLimitSec = 0
+var allianceSelectionTimeLimitSec = 45
// Global var to hold a ticker used for the alliance selection timer.
var allianceSelectionTicker *time.Ticker
@@ -43,9 +43,6 @@ func (web *Web) allianceSelectionPostHandler(w http.ResponseWriter, r *http.Requ
return
}
- // Update time limit value.
- allianceSelectionTimeLimitSec, _ = strconv.Atoi(r.PostFormValue("timeLimitSec"))
-
// Reset picked state for each team in preparation for reconstructing it.
for i := range web.arena.AllianceSelectionRankedTeams {
web.arena.AllianceSelectionRankedTeams[i].Picked = false
@@ -96,19 +93,6 @@ func (web *Web) allianceSelectionPostHandler(w http.ResponseWriter, r *http.Requ
web.arena.AllianceSelectionShowTimer = false
web.arena.AllianceSelectionTimeRemainingSec = 0
}
- if _, nextCol := web.determineNextCell(); nextCol > 0 && allianceSelectionTimeLimitSec > 0 {
- web.arena.AllianceSelectionTimeRemainingSec = allianceSelectionTimeLimitSec
- allianceSelectionTicker = time.NewTicker(time.Second)
- go func() {
- for range allianceSelectionTicker.C {
- web.arena.AllianceSelectionTimeRemainingSec--
- web.arena.AllianceSelectionNotifier.Notify()
- if web.arena.AllianceSelectionTimeRemainingSec == 0 {
- allianceSelectionTicker.Stop()
- }
- }
- }()
- }
web.arena.AllianceSelectionNotifier.Notify()
http.Redirect(w, r, "/alliance_selection", 303)
@@ -296,7 +280,7 @@ func (web *Web) allianceSelectionWebsocketHandler(w http.ResponseWriter, r *http
// Loop, waiting for commands and responding to them, until the client closes the connection.
for {
- messageType, _, err := ws.Read()
+ messageType, data, err := ws.Read()
if err != nil {
if err == io.EOF {
// Client has closed the connection; nothing to do here.
@@ -307,11 +291,32 @@ func (web *Web) allianceSelectionWebsocketHandler(w http.ResponseWriter, r *http
}
switch messageType {
- case "showTimer":
- web.arena.AllianceSelectionShowTimer = true
- web.arena.AllianceSelectionNotifier.Notify()
- case "hideTimer":
+ case "setTimer":
+ if timeLimitSec, ok := data.(float64); ok {
+ allianceSelectionTimeLimitSec = int(timeLimitSec)
+ } else {
+ ws.WriteError("Invalid time limit value.")
+ }
+ case "startTimer":
+ if !web.arena.AllianceSelectionShowTimer {
+ web.arena.AllianceSelectionShowTimer = true
+ web.arena.AllianceSelectionTimeRemainingSec = allianceSelectionTimeLimitSec
+ web.arena.AllianceSelectionNotifier.Notify()
+ allianceSelectionTicker = time.NewTicker(time.Second)
+ go func() {
+ for range allianceSelectionTicker.C {
+ web.arena.AllianceSelectionTimeRemainingSec--
+ web.arena.AllianceSelectionNotifier.Notify()
+ if web.arena.AllianceSelectionTimeRemainingSec == 0 {
+ allianceSelectionTicker.Stop()
+ }
+ }
+ }()
+ }
+ case "stopTimer":
+ allianceSelectionTicker.Stop()
web.arena.AllianceSelectionShowTimer = false
+ web.arena.AllianceSelectionTimeRemainingSec = 0
web.arena.AllianceSelectionNotifier.Notify()
default:
ws.WriteError(fmt.Sprintf("Invalid message type '%s'.", messageType))
diff --git a/web/alliance_selection_test.go b/web/alliance_selection_test.go
index e598b2dc..fb2ef309 100644
--- a/web/alliance_selection_test.go
+++ b/web/alliance_selection_test.go
@@ -318,17 +318,17 @@ func TestAllianceSelectionWebsocket(t *testing.T) {
// Should get a status update right after connection.
readWebsocketType(t, ws, "allianceSelection")
- // Test showing and hiding the timer.
+ // Test starting and stopping the timer.
allianceSelectionMessage := struct {
ShowTimer bool
}{}
- ws.Write("showTimer", nil)
+ ws.Write("startTimer", nil)
assert.Nil(t, mapstructure.Decode(readWebsocketType(t, ws, "allianceSelection"), &allianceSelectionMessage))
assert.Equal(t, true, allianceSelectionMessage.ShowTimer)
- ws.Write("hideTimer", nil)
+ ws.Write("stopTimer", nil)
assert.Nil(t, mapstructure.Decode(readWebsocketType(t, ws, "allianceSelection"), &allianceSelectionMessage))
assert.Equal(t, false, allianceSelectionMessage.ShowTimer)
- ws.Write("showTimer", nil)
+ ws.Write("startTimer", nil)
assert.Nil(t, mapstructure.Decode(readWebsocketType(t, ws, "allianceSelection"), &allianceSelectionMessage))
assert.Equal(t, true, allianceSelectionMessage.ShowTimer)
}