DustyP 9 months ago
parent 1bb5f5e640
commit b1dccc9552

@ -14,107 +14,66 @@ templ RaceManage(groups []models.Group, currentGroup models.Group, heats []model
<div class="col-md-6">
<div class="card">
<div class="card-header bg-primary text-white">
<h3 class="mb-0">Race Controls</h3>
<h4 class="mb-0">Race Control</h4>
</div>
<div class="card-body">
<div class="mb-3">
<label for="group-select" class="form-label">Racing Group</label>
<select id="group-select" class="form-select" hx-post="/api/race/set-group" hx-trigger="change" hx-vals='js:{"group_id": parseInt(this.value)}' hx-swap="none">
<select id="group-select" class="form-select" hx-post="/api/race/set-group" hx-trigger="change" hx-swap="none">
for _, group := range groups {
<option value={ fmt.Sprintf("%d", group.ID) } selected?={ group.ID == currentGroup.ID }>
<option value={ strconv.FormatInt(group.ID, 10) } selected?={ group.ID == currentGroup.ID }>
{ group.Name }
</option>
}
</select>
</div>
<div class="d-flex justify-content-between mb-3">
<button id="prev-heat-btn" class="btn btn-secondary" hx-post="/api/race/previous-heat" hx-swap="none" disabled?={ currentHeatNum <= 1 }>
<i class="bi bi-arrow-left"></i> Previous Heat
</button>
<span class="align-self-center">
<strong>Heat { strconv.Itoa(currentHeatNum) } of { strconv.Itoa(len(heats)) }</strong>
</span>
<button id="next-heat-btn" class="btn btn-secondary" hx-post="/api/race/next-heat" hx-swap="none" disabled?={ currentHeatNum >= len(heats) }>
Next Heat <i class="bi bi-arrow-right"></i>
</button>
</div>
<div class="d-flex justify-content-between">
<button id="reset-timer-btn" class="btn btn-warning" onclick="resetTimer()">
<i class="bi bi-arrow-clockwise"></i> Reset Timer
</button>
<button id="force-end-btn" class="btn btn-danger" onclick="forceEndHeat()">
<i class="bi bi-flag-fill"></i> Force End Heat
</button>
<button id="rerun-heat-btn" class="btn btn-info" hx-post="/api/race/rerun-heat" hx-swap="none">
<i class="bi bi-arrow-repeat"></i> Re-run Heat
</button>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card">
<div class="card-header bg-primary text-white">
<h3 class="mb-0">Timer</h3>
</div>
<div class="card-body">
<div class="timer-display text-center">
<div id="timer" class="display-1 fw-bold">0.000</div>
<div id="status-indicator" class="badge bg-secondary mb-3">Ready</div>
<div class="mb-3">
<h5>Current Heat: { strconv.Itoa(currentHeatNum) } of { strconv.Itoa(len(heats)) }</h5>
<div class="btn-group" role="group">
<button id="prev-heat-btn" class="btn btn-secondary" hx-post="/api/race/previous-heat" hx-swap="none" disabled?={ currentHeatNum <= 1 }>
<i class="bi bi-arrow-left"></i> Previous Heat
</button>
<button id="next-heat-btn" class="btn btn-secondary" hx-post="/api/race/next-heat" hx-swap="none" disabled?={ currentHeatNum >= len(heats) }>
Next Heat <i class="bi bi-arrow-right"></i>
</button>
</div>
</div>
<div class="d-flex justify-content-center">
<div id="gate-status" class="alert alert-secondary">
Gate Status: <span id="gate-status-text">Unknown</span>
<div class="mb-3">
<h5>Timer Control</h5>
<div class="d-flex align-items-center mb-2">
<h3 id="timer" class="me-3">0.000</h3>
<span id="status-indicator" class="badge mb-3 bg-secondary">Ready</span>
</div>
<div class="btn-group" role="group">
<button class="btn btn-warning" onclick="resetTimer()">
<i class="bi bi-arrow-repeat"></i> Reset Timer
</button>
<button class="btn btn-danger" onclick="forceEndHeat()">
<i class="bi bi-flag-fill"></i> Force End
</button>
<button class="btn btn-info" hx-post="/api/race/rerun-heat" hx-swap="none">
<i class="bi bi-arrow-counterclockwise"></i> Re-Run Heat
</button>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="card mb-4">
<div class="card-header bg-primary text-white">
<h3 class="mb-0">Current Heat</h3>
</div>
<div class="card-body">
<div id="current-heat">
@raceManageCurrentHeat(heats, racers, currentHeatNum, results)
<div id="gate-status" class="alert alert-secondary">
<strong>Gate Status:</strong> <span id="gate-status-text">Unknown</span>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="card mb-4">
<div class="card-header bg-info text-white">
<h3 class="mb-0">Next Heat</h3>
</div>
<div class="card-body">
if currentHeatNum < len(heats) {
@raceManageNextHeat(heats, racers, currentHeatNum+1)
} else {
<div class="alert alert-info">No more heats in this group</div>
}
</div>
</div>
</div>
<div class="col-md-6">
<div class="card mb-4">
<div class="card-header bg-secondary text-white">
<h3 class="mb-0">Heat Results</h3>
<div class="card">
<div class="card-header bg-primary text-white">
<h4 class="mb-0">Heat Results</h4>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-striped table-sm">
<table class="table table-striped">
<thead>
<tr>
<th>Heat</th>
@ -126,12 +85,12 @@ templ RaceManage(groups []models.Group, currentGroup models.Group, heats []model
</thead>
<tbody>
for _, result := range results {
<tr>
<tr class={ "table-primary" }>
<td>{ strconv.Itoa(result.HeatNumber) }</td>
<td>{ fmt.Sprintf("%.3f (#%d)", result.Lane1Time, result.Lane1Position) }</td>
<td>{ fmt.Sprintf("%.3f (#%d)", result.Lane2Time, result.Lane2Position) }</td>
<td>{ fmt.Sprintf("%.3f (#%d)", result.Lane3Time, result.Lane3Position) }</td>
<td>{ fmt.Sprintf("%.3f (#%d)", result.Lane4Time, result.Lane4Position) }</td>
<td>{ fmt.Sprintf("%.4f", result.Lane1Time) } ({ strconv.Itoa(result.Lane1Position) })</td>
<td>{ fmt.Sprintf("%.4f", result.Lane2Time) } ({ strconv.Itoa(result.Lane2Position) })</td>
<td>{ fmt.Sprintf("%.4f", result.Lane3Time) } ({ strconv.Itoa(result.Lane3Position) })</td>
<td>{ fmt.Sprintf("%.4f", result.Lane4Time) } ({ strconv.Itoa(result.Lane4Position) })</td>
</tr>
}
</tbody>
@ -141,8 +100,51 @@ templ RaceManage(groups []models.Group, currentGroup models.Group, heats []model
</div>
</div>
</div>
<!-- Current Heat Display -->
@currentHeatDisplay(heats, racers, currentHeatNum, results)
<!-- Next Heat Preview -->
if currentHeatNum < len(heats) {
<div class="card mb-4">
<div class="card-header bg-secondary text-white">
<h4 class="mb-0">Next Heat: { strconv.Itoa(currentHeatNum + 1) }</h4>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Lane</th>
<th>Racer</th>
<th>Car #</th>
</tr>
</thead>
<tbody>
for _, heat := range heats {
if heat.HeatNum == currentHeatNum + 1 {
if heat.Lane1ID != nil {
@nextHeatRacer(1, *heat.Lane1ID, racers)
}
if heat.Lane2ID != nil {
@nextHeatRacer(2, *heat.Lane2ID, racers)
}
if heat.Lane3ID != nil {
@nextHeatRacer(3, *heat.Lane3ID, racers)
}
if heat.Lane4ID != nil {
@nextHeatRacer(4, *heat.Lane4ID, racers)
}
}
}
</tbody>
</table>
</div>
</div>
</div>
}
</div>
<script>
// Set up SSE connection
console.log("Setting up SSE connection...");
@ -329,10 +331,10 @@ templ RaceManage(groups []models.Group, currentGroup models.Group, heats []model
}
}
// Helper template for displaying current heat in the management view
templ raceManageCurrentHeat(heats []models.Heat, racers []models.Racer, currentHeatNum int, results []models.HeatResult) {
// Find the current heat
templ currentHeatDisplay(heats []models.Heat, racers []models.Racer, currentHeatNum int, results []models.HeatResult) {
{{
// Find current heat
// Find the current heat
var currentHeat models.Heat
for _, heat := range heats {
if heat.HeatNum == currentHeatNum {
@ -341,7 +343,7 @@ templ raceManageCurrentHeat(heats []models.Heat, racers []models.Racer, currentH
}
}
// Find heat result if available
// Find the current result
var currentResult *models.HeatResult
for _, result := range results {
if result.HeatNumber == currentHeatNum {
@ -350,40 +352,33 @@ templ raceManageCurrentHeat(heats []models.Heat, racers []models.Racer, currentH
}
}
}}
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<th>Lane</th>
<th>Racer</th>
<th>Car #</th>
<th>Time</th>
<th>Position</th>
</tr>
</thead>
<tbody>
<div class="card mb-4">
<div class="card-header bg-primary text-white">
<h4 class="mb-0">Current Heat: { strconv.Itoa(currentHeatNum) }</h4>
</div>
<div class="card-body">
<div class="row">
if currentHeat.Lane1ID != nil {
@raceManageLaneRow(1, *currentHeat.Lane1ID, racers, currentResult)
@raceLaneInfo(1, *currentHeat.Lane1ID, racers, currentResult)
}
if currentHeat.Lane2ID != nil {
@raceManageLaneRow(2, *currentHeat.Lane2ID, racers, currentResult)
@raceLaneInfo(2, *currentHeat.Lane2ID, racers, currentResult)
}
if currentHeat.Lane3ID != nil {
@raceManageLaneRow(3, *currentHeat.Lane3ID, racers, currentResult)
@raceLaneInfo(3, *currentHeat.Lane3ID, racers, currentResult)
}
if currentHeat.Lane4ID != nil {
@raceManageLaneRow(4, *currentHeat.Lane4ID, racers, currentResult)
@raceLaneInfo(4, *currentHeat.Lane4ID, racers, currentResult)
}
</tbody>
</table>
</div>
</div>
</div>
}
// Helper template for displaying a lane row in the management view
templ raceManageLaneRow(lane int, racerID int64, racers []models.Racer, result *models.HeatResult) {
// Helper template for displaying a lane in the race manager
templ raceLaneInfo(lane int, racerID int64, racers []models.Racer, result *models.HeatResult) {
{{
// Find racer
// Find the racer
var racer models.Racer
for _, r := range racers {
if r.ID == racerID {
@ -393,92 +388,48 @@ templ raceManageLaneRow(lane int, racerID int64, racers []models.Racer, result *
}
// Get time and position from result if available
var time float64
var position int
var hasResult bool
var timeStr string = "--.-"
var positionStr string = "-"
if result != nil {
hasResult = true
switch lane {
case 1:
time = result.Lane1Time
position = result.Lane1Position
case 2:
time = result.Lane2Time
position = result.Lane2Position
case 3:
time = result.Lane3Time
position = result.Lane3Position
case 4:
time = result.Lane4Time
position = result.Lane4Position
}
}
}}
<tr>
<td>{ strconv.Itoa(lane) }</td>
<td>{ racer.FirstName } { racer.LastName }</td>
<td>{ racer.CarNumber }</td>
<td id={ fmt.Sprintf("lane-%d-time", lane) }>
if hasResult {
{ fmt.Sprintf("%.3f", time) }
} else {
--.-
}
</td>
<td id={ fmt.Sprintf("lane-%d-position", lane) }>
if hasResult {
{ strconv.Itoa(position) }
} else {
-
}
</td>
</tr>
}
// Helper template for displaying next heat in the management view
templ raceManageNextHeat(heats []models.Heat, racers []models.Racer, heatNum int) {
{{
// Find the heat
var nextHeat models.Heat
for _, heat := range heats {
if heat.HeatNum == heatNum {
nextHeat = heat
break
if lane == 1 && result.Lane1Time > 0 {
timeStr = fmt.Sprintf("%.4f", result.Lane1Time)
positionStr = strconv.Itoa(result.Lane1Position)
} else if lane == 2 && result.Lane2Time > 0 {
timeStr = fmt.Sprintf("%.4f", result.Lane2Time)
positionStr = strconv.Itoa(result.Lane2Position)
} else if lane == 3 && result.Lane3Time > 0 {
timeStr = fmt.Sprintf("%.4f", result.Lane3Time)
positionStr = strconv.Itoa(result.Lane3Position)
} else if lane == 4 && result.Lane4Time > 0 {
timeStr = fmt.Sprintf("%.4f", result.Lane4Time)
positionStr = strconv.Itoa(result.Lane4Position)
}
}
}}
<div class="table-responsive">
<table class="table table-striped table-sm">
<thead>
<tr>
<th>Lane</th>
<th>Racer</th>
<th>Car #</th>
</tr>
</thead>
<tbody>
if nextHeat.Lane1ID != nil {
@raceManageNextHeatRow(1, *nextHeat.Lane1ID, racers)
}
if nextHeat.Lane2ID != nil {
@raceManageNextHeatRow(2, *nextHeat.Lane2ID, racers)
}
if nextHeat.Lane3ID != nil {
@raceManageNextHeatRow(3, *nextHeat.Lane3ID, racers)
}
if nextHeat.Lane4ID != nil {
@raceManageNextHeatRow(4, *nextHeat.Lane4ID, racers)
}
</tbody>
</table>
<div class="col-md-3 mb-3">
<div class="card h-100">
<div class="card-header bg-secondary text-white">
<h5 class="mb-0">Lane { strconv.Itoa(lane) }</h5>
</div>
<div class="card-body">
<h5 class="card-title">{ racer.FirstName } { racer.LastName }</h5>
<p class="card-text">Car #: { racer.CarNumber }</p>
<div class="d-flex justify-content-between">
<div>
<strong>Time:</strong> <span id="lane-{strconv.Itoa(lane)}-time">{ timeStr }</span>
</div>
<div>
<strong>Position:</strong> <span id="lane-{strconv.Itoa(lane)}-position">{ positionStr }</span>
</div>
</div>
</div>
</div>
</div>
}
// Helper template for displaying a row in the next heat preview
templ raceManageNextHeatRow(lane int, racerID int64, racers []models.Racer) {
// Helper template for displaying a racer in the next heat
templ nextHeatRacer(lane int, racerID int64, racers []models.Racer) {
{{
// Find racer
var racer models.Racer
@ -489,7 +440,6 @@ templ raceManageNextHeatRow(lane int, racerID int64, racers []models.Racer) {
}
}
}}
<tr>
<td>{ strconv.Itoa(lane) }</td>
<td>{ racer.FirstName } { racer.LastName }</td>

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save