Skip to content

Commit

Permalink
Merge branch 'thatnerdjack-2024' into 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
patfair committed May 8, 2024
2 parents 6c23553 + de551ba commit eb44c80
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 277 deletions.
Binary file removed static/css/fonts/glyphicons-halflings-regular.eot
Binary file not shown.
229 changes: 0 additions & 229 deletions static/css/fonts/glyphicons-halflings-regular.svg

This file was deleted.

Binary file removed static/css/fonts/glyphicons-halflings-regular.ttf
Binary file not shown.
Binary file removed static/css/fonts/glyphicons-halflings-regular.woff
Binary file not shown.
5 changes: 5 additions & 0 deletions static/css/lib/bootstrap-icons.min.css

Large diffs are not rendered by default.

Binary file added static/css/lib/fonts/bootstrap-icons.woff
Binary file not shown.
Binary file added static/css/lib/fonts/bootstrap-icons.woff2
Binary file not shown.
1 change: 1 addition & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ <h4 class="modal-title">About Cheesy Arena</h4>
<link rel="shortcut icon" href="/static/img/favicon.ico">
<link href="/static/css/lib/bootstrap.min.css" rel="stylesheet">
<link href="/static/css/lib/bootstrap-datetimepicker.min.css" rel="stylesheet">
<link href="/static/css/lib/bootstrap-icons.min.css" rel="stylesheet">
<link href="/static/css/cheesy-arena.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1">
{{end}}
Expand Down
38 changes: 19 additions & 19 deletions templates/edit_team.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,78 +6,78 @@
*/}}
{{define "title"}}Edit Team{{end}}
{{define "body"}}
<div class="row">
<div class="col-lg-6 col-lg-offset-3">
<div class="well">
<div class="row justify-content-center">
<div class="col-lg-6">
<div class="card card-body bg-body-tertiary">
<form class="form-horizontal" action="/setup/teams/{{.Team.Id}}/edit" method="POST">
<fieldset>
<legend>Edit Team {{.Team.Id}}</legend>
<div class="form-group">
<div class="row mb-3">
<label class="col-lg-3 control-label">Name</label>
<div class="col-lg-9">
<textarea class="form-control" rows="5" name="name">{{.Team.Name}}</textarea>
</div>
</div>
<div class="form-group">
<div class="row mb-3">
<label class="col-lg-3 control-label">Nickname</label>
<div class="col-lg-9">
<input type="text" class="form-control" name="nickname" value="{{.Team.Nickname}}">
</div>
</div>
<div class="form-group">
<div class="row mb-3">
<label class="col-lg-3 control-label">City</label>
<div class="col-lg-9">
<input type="text" class="form-control" name="city" value="{{.Team.City}}">
</div>
</div>
<div class="form-group">
<div class="row mb-3">
<label class="col-lg-3 control-label">State/Province</label>
<div class="col-lg-9">
<input type="text" class="form-control" name="stateProv" value="{{.Team.StateProv}}">
</div>
</div>
<div class="form-group">
<div class="row mb-3">
<label class="col-lg-3 control-label">Country</label>
<div class="col-lg-9">
<input type="text" class="form-control" name="country" value="{{.Team.Country}}">
</div>
</div>
<div class="form-group">
<div class="row mb-3">
<label class="col-lg-3 control-label">Rookie Year</label>
<div class="col-lg-9">
<input type="text" class="form-control" name="rookieYear" value="{{.Team.RookieYear}}">
</div>
</div>
<div class="form-group">
<div class="row mb-3">
<label class="col-lg-3 control-label">Robot Name</label>
<div class="col-lg-9">
<input type="text" class="form-control" name="robotName" value="{{.Team.RobotName}}">
</div>
</div>
<div class="form-group">
<div class="row mb-3">
<label class="col-lg-3 control-label">Recent Accomplishments</label>
<div class="col-lg-9">
<textarea class="form-control" rows="5" name="accomplishments">{{.Team.Accomplishments}}</textarea>
</div>
</div>
<div class="form-group">
<label class="col-lg-5 control-label">Has Connected to Field?</label>
<div class="row mb-3">
<label class="col-lg-5 control-label" for="hasConnected">Has Connected to Field?</label>
<div class="col-lg-1 checkbox">
<input type="checkbox" name="hasConnected"{{if .Team.HasConnected}} checked{{end}} />
<input type="checkbox" id="hasConnected" name="hasConnected"{{if .Team.HasConnected}} checked{{end}} />
</div>
</div>
{{if .EventSettings.NetworkSecurityEnabled}}
<div class="form-group">
<div class="row mb-3">
<label class="col-lg-3 control-label">WPA Key</label>
<div class="col-lg-9">
<input type="text" class="form-control" name="wpaKey" value="{{.Team.WpaKey}}">
</div>
</div>
{{end}}
<div class="form-group">
<div class="col-lg-9 col-lg-offset-3">
<a href="/setup/teams"><button type="button" class="btn btn-default">Cancel</button></a>
<button type="submit" class="btn btn-info">Save</button>
<div class="row justify-content-center">
<div class="col-md-auto">
<a href="/setup/teams"><button type="button" class="btn btn-secondary">Cancel</button></a>
<button type="submit" class="btn btn-primary">Save</button>
</div>
</div>
</fieldset>
Expand Down
100 changes: 71 additions & 29 deletions templates/setup_teams.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,44 @@
{{define "body"}}
{{if .ShowErrorMessage}}
<div class="alert alert-dismissable alert-danger">
<button type="button" class="close" data-dismiss="alert">×</button>
<button type="button" class="close" data-bs-dismiss="alert">×</button>
You can't modify the team list once the qualification schedule has been generated. If you need to change
the team list, clear all other data first on the Settings page.
</div>
{{end}}
<div class="row">
<div class="col-lg-2">
<form class="form-horizontal" action="/setup/teams" method="POST">
<div class="col-lg-3">
<form action="/setup/teams" method="POST">
<fieldset>
<legend>Import Teams</legend>
{{if not .EventSettings.TbaDownloadEnabled}}<p>To automatically download data about teams, enable TBA Team Info Download on the settings page</p>{{end}}
<div class="form-group">
{{if not .EventSettings.TbaDownloadEnabled}}
<p>To automatically download data about teams, enable TBA Team Info Download on the settings page</p>
{{end}}
<div class="row mb-3">
<textarea class="form-control" rows="10" name="teamNumbers"
placeholder="One team number per line"></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn btn-info">Add Teams</button>
<div class="row mb-3">
<button type="submit" class="btn btn-primary" onclick="$('#loadingFromTba').modal('show');">Add Teams</button>
</div>
{{if .EventSettings.TbaDownloadEnabled}}
<div class="form-group">
<a href="/setup/teams/refresh" class="btn btn-info">Refresh Team Data from TBA</a>
<div class="row mb-3">
<a href="/setup/teams/refresh" class="btn btn-primary" onclick="$('#loadingFromTba').modal('show');">
Refresh Team Data from TBA
</a>
</div>
{{end}}
<div class="form-group">
<button type="button" class="btn btn-primary" onclick="$('#confirmClearTeams').modal('show');">
<div class="row mb-3">
<button type="button" class="btn btn-danger" onclick="$('#confirmClearTeams').modal('show');">
Clear Team List
</button>
</div>
{{if .EventSettings.NetworkSecurityEnabled}}
<div class="form-group">
<a href="/setup/teams/generate_wpa_keys?all=true" class="btn btn-primary">Generate All WPA Keys</a>
<div class="row mb-3">
<a href="/setup/teams/generate_wpa_keys?all=true" class="btn btn-danger">Generate All WPA Keys</a>
</div>
<div class="form-group">
<a href="/setup/teams/generate_wpa_keys?all=false" class="btn btn-primary">Generate Missing WPA Keys</a>
<div class="row mb-3">
<a href="/setup/teams/generate_wpa_keys?all=false" class="btn btn-danger">Generate Missing WPA Keys</a>
</div>
{{end}}
{{if .EventSettings.TbaPublishingEnabled}}
Expand All @@ -51,7 +55,7 @@
</fieldset>
</form>
</div>
<div class="col-lg-10">
<div class="col-lg-9">
<table class="table table-striped table-hover ">
<thead>
<tr>
Expand All @@ -75,13 +79,11 @@
<td>{{$team.RobotName}}</td>
<td class="text-center nowrap">
<form action="/setup/teams/{{$team.Id}}/delete" method="POST">
<a href="/setup/teams/{{$team.Id}}/edit">
<button type="button" class="btn btn-info btn-xs">
<i class="glyphicon glyphicon-edit"></i>
</button>
</a>
<button type="submit" class="btn btn-primary btn-xs">
<i class="glyphicon glyphicon-trash"></i>
<a href="/setup/teams/{{$team.Id}}/edit"><button type="button" class="btn btn-primary btn-sm">
<i class="bi-pencil-square"></i>
</button></a>
<button type="submit" class="btn btn-danger btn-sm">
<i class="bi-trash"></i>
</button>
</form>
</td>
Expand All @@ -96,16 +98,16 @@
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Confirm</h4>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<p>Are you sure you want to clear the team list?</p>
</div>
<div class="modal-footer">
<form class="form-horizontal" action="/setup/teams/clear" method="POST">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">Clear Team List</button>
<button type="button" class="btn btn-primary" data-bs-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-danger">Clear Team List</button>
</form>
</div>
</div>
Expand All @@ -115,21 +117,61 @@ <h4 class="modal-title">Confirm</h4>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Confirm</h4>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<p>Are you sure you want to publish the team list to The Blue Alliance? This will overwrite any
existing team list data.</p>
</div>
<div class="modal-footer">
<form class="form-horizontal" action="/setup/teams/publish" method="POST">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-default" data-bs-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">Publish Team List</button>
</form>
</div>
</div>
</div>
</div>
<div id="loadingFromTba" class="modal fade" style="top: 20%;" data-bs-backdrop="static" data-bs-keyboard="false">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Downloading Team Data from TBA...<h5>
</div>
<div class="modal-body">
<div class="progress">
<div id="teamDownloadProgressBar"
class="progress-bar progress-bar-striped progress-bar-animated"
role="progressbar"
style="width: 10%"
aria-valuemin="0"
aria-valuemax="100">
5%
</div>
</div>
</div>
</div>
</div>
</div>
{{end}}
{{define "script"}}
<script>
const teamDownloadProgressBar = $("#teamDownloadProgressBar");
$(function updateProgressBar() {
$.ajax({
url: '/setup/teams/progress',
success: function(data) {
teamDownloadProgressBar.css("width", `${data}%`);
teamDownloadProgressBar.text(`${data}%`);
},
error: function(error) {
console.log(error)
},
complete: function() {
setTimeout(updateProgressBar, 2000)
}
})
})
</script>
{{end}}
{{define "script"}}{{end}}
21 changes: 21 additions & 0 deletions web/setup_teams.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import (

const wpaKeyLength = 8

// Global var to hold the team download progress percentage.
var progressPercentage float64 = 5

// Shows the team list.
func (web *Web) teamsGetHandler(w http.ResponseWriter, r *http.Request) {
if !web.userIsAdmin(w, r) {
Expand Down Expand Up @@ -46,6 +49,8 @@ func (web *Web) teamsPostHandler(w http.ResponseWriter, r *http.Request) {
}
}

progressPercentage = 5
progressIncrement := 95.0 / float64(len(teamNumbers))
for _, teamNumber := range teamNumbers {
team := model.Team{Id: teamNumber}
if web.arena.EventSettings.TbaDownloadEnabled {
Expand All @@ -58,7 +63,11 @@ func (web *Web) teamsPostHandler(w http.ResponseWriter, r *http.Request) {
handleWebErr(w, err)
return
}

progressPercentage += progressIncrement
}
progressPercentage = 100

http.Redirect(w, r, "/setup/teams", 303)
}

Expand All @@ -74,6 +83,8 @@ func (web *Web) teamsRefreshHandler(w http.ResponseWriter, r *http.Request) {
return
}

progInc := 95.00 / float64(len(teams))

for _, team := range teams {
if err = web.populateOfficialTeamInfo(&team); err != nil {
handleWebErr(w, err)
Expand All @@ -83,9 +94,13 @@ func (web *Web) teamsRefreshHandler(w http.ResponseWriter, r *http.Request) {
handleWebErr(w, err)
return
}

progressPercentage += progInc
}

progressPercentage = 100
http.Redirect(w, r, "/setup/teams", 303)
progressPercentage = 5
}

// Clears the team list.
Expand Down Expand Up @@ -236,6 +251,12 @@ func (web *Web) teamsGenerateWpaKeysHandler(w http.ResponseWriter, r *http.Reque
http.Redirect(w, r, "/setup/teams", 303)
}

// Returns the current TBA team data download progress.
func (web *Web) teamsUpdateProgressBarHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
_, _ = w.Write([]byte(fmt.Sprintf("%.0f", progressPercentage)))
}

func (web *Web) renderTeams(w http.ResponseWriter, r *http.Request, showErrorMessage bool) {
teams, err := web.arena.Database.GetAllTeams()
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions web/setup_teams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,12 @@ func TestSetupTeamsWpaKeys(t *testing.T) {
assert.Equal(t, 500, recorder.Code)
assert.Contains(t, recorder.Body.String(), "WPA key must be between 8 and 63 characters")
}

func TestSetupTeamsProgress(t *testing.T) {
web := setupTestWeb(t)
progressPercentage = 25.4

recorder := web.getHttpResponse("/setup/teams/progress")
assert.Equal(t, 200, recorder.Code)
assert.Equal(t, "25", recorder.Body.String())
}
1 change: 1 addition & 0 deletions web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ func (web *Web) newHandler() http.Handler {
mux.HandleFunc("POST /setup/teams/{id}/edit", web.teamEditPostHandler)
mux.HandleFunc("POST /setup/teams/clear", web.teamsClearHandler)
mux.HandleFunc("GET /setup/teams/generate_wpa_keys", web.teamsGenerateWpaKeysHandler)
mux.HandleFunc("GET /setup/teams/progress", web.teamsUpdateProgressBarHandler)
mux.HandleFunc("GET /setup/teams/refresh", web.teamsRefreshHandler)
return mux
}
Expand Down

0 comments on commit eb44c80

Please sign in to comment.