You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
2.3 KiB

package templates
import (
"strconv"
"track-gopher/models"
"track-gopher/db"
)
templ Heats(groups []models.Group, selectedGroupID int64, db *db.DB) {
@Layout("Race Heats") {
<div class="container py-4">
<h1 class="mb-4">Race Heats</h1>
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-body">
<div class="mb-3">
<label for="group-select" class="form-label">Select Group</label>
<select
class="form-select"
id="group-select"
hx-get="/heats-content"
hx-target="#heats-content"
hx-trigger="change"
hx-include="[name='group_id']"
>
<option value="">Select a group</option>
for _, group := range groups {
<option
value={ strconv.FormatInt(group.ID, 10) }
selected?={ group.ID == selectedGroupID }
>
{ group.Name }
</option>
}
</select>
</div>
<div id="heats-content">
if selectedGroupID > 0 {
@HeatsContent([]models.Heat{}, []models.Racer{})
}
</div>
</div>
</div>
</div>
</div>
</div>
}
}
templ HeatsContent(heats []models.Heat, racers []models.Racer) {
if len(racers) == 0 {
<div class="alert alert-info">No racers in this group yet.</div>
} else {
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th>Heat</th>
<th>Lane 1</th>
<th>Lane 2</th>
<th>Lane 3</th>
<th>Lane 4</th>
</tr>
</thead>
<tbody>
for i, heat := range heats {
<tr>
<td>{ strconv.Itoa(i + 1) }</td>
<td>{ getRacerName(racers, heat.Lane1ID) }</td>
<td>{ getRacerName(racers, heat.Lane2ID) }</td>
<td>{ getRacerName(racers, heat.Lane3ID) }</td>
<td>{ getRacerName(racers, heat.Lane4ID) }</td>
</tr>
}
</tbody>
</table>
<div class="mt-3">
<button
class="btn btn-primary"
hx-post="/api/heats"
hx-include="[name='group_id']"
hx-target="#heats-content"
>
Save Heats
</button>
</div>
</div>
}
}
func getRacerName(racers []models.Racer, id int64) string {
for _, r := range racers {
if r.ID == id {
return r.FirstName + " " + r.LastName
}
}
return "TBD"
}