diff --git a/db/migrations/20140520222523_CreateTeams.sql b/db/migrations/20140520222523_CreateTeams.sql
index d3bc495..7736b58 100644
--- a/db/migrations/20140520222523_CreateTeams.sql
+++ b/db/migrations/20140520222523_CreateTeams.sql
@@ -10,7 +10,8 @@ CREATE TABLE teams (
robotname VARCHAR(255),
accomplishments VARCHAR(1000),
wpakey VARCHAR(16),
- yellowcard bool
+ yellowcard bool,
+ hasconnected bool
);
-- +goose Down
diff --git a/field/arena.go b/field/arena.go
index bacb0db..f64aac2 100644
--- a/field/arena.go
+++ b/field/arena.go
@@ -338,6 +338,13 @@ func (arena *Arena) StartMatch() error {
log.Println(err)
}
}
+
+ // Save the teams that have successfully connected to the field.
+ if allianceStation.Team != nil && !allianceStation.Team.HasConnected && allianceStation.DsConn != nil &&
+ allianceStation.DsConn.RobotLinked {
+ allianceStation.Team.HasConnected = true
+ arena.Database.SaveTeam(allianceStation.Team)
+ }
}
arena.MatchState = StartMatch
diff --git a/field/arena_test.go b/field/arena_test.go
index da37793..69310c3 100644
--- a/field/arena_test.go
+++ b/field/arena_test.go
@@ -595,3 +595,40 @@ func TestArenaTimeout(t *testing.T) {
assert.NotNil(t, arena.StartTimeout(1))
}
}
+
+func TestSaveTeamHasConnected(t *testing.T) {
+ arena := setupTestArena(t)
+
+ arena.Database.CreateTeam(&model.Team{Id: 101})
+ arena.Database.CreateTeam(&model.Team{Id: 102})
+ arena.Database.CreateTeam(&model.Team{Id: 103})
+ arena.Database.CreateTeam(&model.Team{Id: 104})
+ arena.Database.CreateTeam(&model.Team{Id: 105})
+ arena.Database.CreateTeam(&model.Team{Id: 106, City: "San Jose", HasConnected: true})
+ match := model.Match{Red1: 101, Red2: 102, Red3: 103, Blue1: 104, Blue2: 105, Blue3: 106}
+ arena.Database.CreateMatch(&match)
+ arena.LoadMatch(&match)
+ arena.AllianceStations["R1"].DsConn = &DriverStationConnection{TeamId: 101}
+ arena.AllianceStations["R1"].Bypass = true
+ arena.AllianceStations["R2"].DsConn = &DriverStationConnection{TeamId: 102, RobotLinked: true}
+ arena.AllianceStations["R3"].DsConn = &DriverStationConnection{TeamId: 103}
+ arena.AllianceStations["R3"].Bypass = true
+ arena.AllianceStations["B1"].DsConn = &DriverStationConnection{TeamId: 104}
+ arena.AllianceStations["B1"].Bypass = true
+ arena.AllianceStations["B2"].DsConn = &DriverStationConnection{TeamId: 105, RobotLinked: true}
+ arena.AllianceStations["B3"].DsConn = &DriverStationConnection{TeamId: 106, RobotLinked: true}
+ arena.AllianceStations["B3"].Team.City = "Sand Hosay" // Change some other field to verify that it isn't saved.
+ assert.Nil(t, arena.StartMatch())
+
+ // Check that the connection status was saved for the teams that just linked for the first time.
+ teams, _ := arena.Database.GetAllTeams()
+ if assert.Equal(t, 6, len(teams)) {
+ assert.False(t, teams[0].HasConnected)
+ assert.True(t, teams[1].HasConnected)
+ assert.False(t, teams[2].HasConnected)
+ assert.False(t, teams[3].HasConnected)
+ assert.True(t, teams[4].HasConnected)
+ assert.True(t, teams[5].HasConnected)
+ assert.Equal(t, "San Jose", teams[5].City)
+ }
+}
diff --git a/model/team.go b/model/team.go
index 398deac..8de963a 100644
--- a/model/team.go
+++ b/model/team.go
@@ -17,6 +17,7 @@ type Team struct {
Accomplishments string
WpaKey string
YellowCard bool
+ HasConnected bool
}
func (database *Database) CreateTeam(team *Team) error {
diff --git a/templates/base.html b/templates/base.html
index 3681c3e..267f02a 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -65,6 +65,7 @@
Qualification Schedule
Playoff Schedule
Standings
+ Team Connection Status
Team List
diff --git a/templates/edit_team.html b/templates/edit_team.html
index 65b978f..29de6d9 100644
--- a/templates/edit_team.html
+++ b/templates/edit_team.html
@@ -60,6 +60,12 @@
+
{{if .EventSettings.NetworkSecurityEnabled}}
diff --git a/templates/teams.csv b/templates/teams.csv
index 30ac3be..df4a603 100644
--- a/templates/teams.csv
+++ b/templates/teams.csv
@@ -1,3 +1,3 @@
-Number,Name,Nickname,City,StateProv,Country,RookieYear,RobotName
-{{range $team := .}}{{$team.Id}},"{{$team.Name}}","{{$team.Nickname}}","{{$team.City}}","{{$team.StateProv}}","{{$team.Country}}",{{$team.RookieYear}},"{{$team.RobotName}}"
+Number,Name,Nickname,City,StateProv,Country,RookieYear,RobotName,HasConnected
+{{range $team := .}}{{$team.Id}},"{{$team.Name}}","{{$team.Nickname}}","{{$team.City}}","{{$team.StateProv}}","{{$team.Country}}",{{$team.RookieYear}},"{{$team.RobotName}}",{{$team.HasConnected}}
{{end}}
diff --git a/web/reports.go b/web/reports.go
index 240b6b9..353c1ef 100644
--- a/web/reports.go
+++ b/web/reports.go
@@ -274,8 +274,15 @@ func (web *Web) teamsPdfReportHandler(w http.ResponseWriter, r *http.Request) {
return
}
+ showHasConnected := r.URL.Query().Get("showHasConnected") == "true"
+
// The widths of the table columns in mm, stored here so that they can be referenced for each row.
- colWidths := map[string]float64{"Id": 12, "Name": 80, "Location": 80, "RookieYear": 23}
+ var colWidths map[string]float64
+ if showHasConnected {
+ colWidths = map[string]float64{"Id": 12, "Name": 70, "Location": 65, "RookieYear": 23, "HasConnected": 25}
+ } else {
+ colWidths = map[string]float64{"Id": 12, "Name": 80, "Location": 80, "RookieYear": 23}
+ }
rowHeight := 6.5
pdf := gofpdf.New("P", "mm", "Letter", "font")
@@ -288,7 +295,12 @@ func (web *Web) teamsPdfReportHandler(w http.ResponseWriter, r *http.Request) {
pdf.CellFormat(colWidths["Id"], rowHeight, "Team", "1", 0, "C", true, 0, "")
pdf.CellFormat(colWidths["Name"], rowHeight, "Name", "1", 0, "C", true, 0, "")
pdf.CellFormat(colWidths["Location"], rowHeight, "Location", "1", 0, "C", true, 0, "")
- pdf.CellFormat(colWidths["RookieYear"], rowHeight, "Rookie Year", "1", 1, "C", true, 0, "")
+ if showHasConnected {
+ pdf.CellFormat(colWidths["RookieYear"], rowHeight, "Rookie Year", "1", 0, "C", true, 0, "")
+ pdf.CellFormat(colWidths["HasConnected"], rowHeight, "Connected?", "1", 1, "C", true, 0, "")
+ } else {
+ pdf.CellFormat(colWidths["RookieYear"], rowHeight, "Rookie Year", "1", 1, "C", true, 0, "")
+ }
pdf.SetFont("Arial", "", 10)
for _, team := range teams {
// Render team info row.
@@ -296,7 +308,16 @@ func (web *Web) teamsPdfReportHandler(w http.ResponseWriter, r *http.Request) {
pdf.CellFormat(colWidths["Name"], rowHeight, team.Nickname, "1", 0, "L", false, 0, "")
location := fmt.Sprintf("%s, %s, %s", team.City, team.StateProv, team.Country)
pdf.CellFormat(colWidths["Location"], rowHeight, location, "1", 0, "L", false, 0, "")
- pdf.CellFormat(colWidths["RookieYear"], rowHeight, strconv.Itoa(team.RookieYear), "1", 1, "L", false, 0, "")
+ if showHasConnected {
+ pdf.CellFormat(colWidths["RookieYear"], rowHeight, strconv.Itoa(team.RookieYear), "1", 0, "L", false, 0, "")
+ var hasConnected string
+ if team.HasConnected {
+ hasConnected = "Yes"
+ }
+ pdf.CellFormat(colWidths["HasConnected"], rowHeight, hasConnected, "1", 1, "L", false, 0, "")
+ } else {
+ pdf.CellFormat(colWidths["RookieYear"], rowHeight, strconv.Itoa(team.RookieYear), "1", 1, "L", false, 0, "")
+ }
}
// Write out the PDF file as the HTTP response.
diff --git a/web/reports_test.go b/web/reports_test.go
index 647cedf..0ba2f05 100644
--- a/web/reports_test.go
+++ b/web/reports_test.go
@@ -96,9 +96,9 @@ func TestTeamsCsvReport(t *testing.T) {
recorder := web.getHttpResponse("/reports/csv/teams")
assert.Equal(t, 200, recorder.Code)
assert.Equal(t, "text/plain", recorder.HeaderMap["Content-Type"][0])
- expectedBody := "Number,Name,Nickname,City,StateProv,Country,RookieYear,RobotName\n254,\"NASA\"," +
- "\"The Cheesy Poofs\",\"San Jose\",\"CA\",\"USA\",1999,\"Barrage\"\n1114,\"GM\",\"Simbotics\"," +
- "\"St. Catharines\",\"ON\",\"Canada\",2003,\"Simbot Evolution\"\n\n"
+ expectedBody := "Number,Name,Nickname,City,StateProv,Country,RookieYear,RobotName,HasConnected\n254,\"NASA\"," +
+ "\"The Cheesy Poofs\",\"San Jose\",\"CA\",\"USA\",1999,\"Barrage\",false\n1114,\"GM\",\"Simbotics\"," +
+ "\"St. Catharines\",\"ON\",\"Canada\",2003,\"Simbot Evolution\",false\n\n"
assert.Equal(t, expectedBody, recorder.Body.String())
}
diff --git a/web/setup_teams.go b/web/setup_teams.go
index 55d9abf..a3ede9a 100644
--- a/web/setup_teams.go
+++ b/web/setup_teams.go
@@ -148,6 +148,7 @@ func (web *Web) teamEditPostHandler(w http.ResponseWriter, r *http.Request) {
return
}
}
+ team.HasConnected = r.PostFormValue("hasConnected") == "on"
err = web.arena.Database.SaveTeam(team)
if err != nil {
handleWebErr(w, err)