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.5 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">
<select
class="form-select"
id="group-select"
hx-get="/heats-content"
hx-target="#heats-content"
hx-trigger="change"
hx-include="this"
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{}, selectedGroupID)
}
</div>
</div>
</div>
</div>
</div>
</div>
}
}
templ HeatsContent(heats []models.Heat, racers []models.Racer, groupID int64) {
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>
<button
class="btn btn-primary me-2"
hx-post={ "/api/heats/generate?group_id=" + strconv.FormatInt(groupID, 10) }
hx-target="#heats-list"
hx-swap="innerHTML"
>
Regenerate Heats
</button>
</div>
</div>
}
}
func getRacerName(racers []models.Racer, id *int64) string {
for _, r := range racers {
if id != nil && r.ID == *id {
return r.FirstName + " " + r.LastName
}
}
return "TBD"
}