mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-04 18:52:56 +00:00
dev day #89
This commit is contained in:
@@ -345,8 +345,21 @@ func (c *ScoreboardController) StartTimer(ctx *gin.Context) {
|
||||
if s.ElapsedSeconds == 0 && s.Timer != "" {
|
||||
s.ElapsedSeconds = parseTimerToSeconds(s.Timer)
|
||||
}
|
||||
s.TimerStartUnix = time.Now().Unix() - int64(s.ElapsedSeconds)
|
||||
s.Running = true
|
||||
// Respect caps similarly to computeTimer
|
||||
cap := s.HalfLength * 60
|
||||
if cap <= 0 { cap = 45 * 60 }
|
||||
if s.Half >= 2 { cap = s.HalfLength * 120 }
|
||||
if s.ElapsedSeconds >= cap {
|
||||
// Already at or beyond cap; keep paused at cap
|
||||
s.ElapsedSeconds = cap
|
||||
s.Timer = formatSeconds(s.ElapsedSeconds)
|
||||
s.Running = false
|
||||
s.TimerStartUnix = 0
|
||||
} else {
|
||||
// Start from current elapsed
|
||||
s.TimerStartUnix = time.Now().Unix() - int64(s.ElapsedSeconds)
|
||||
s.Running = true
|
||||
}
|
||||
if err := c.DB.Save(s).Error; err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "failed to save"}); return
|
||||
}
|
||||
@@ -368,8 +381,11 @@ func (c *ScoreboardController) PauseTimer(ctx *gin.Context) {
|
||||
// Cap and set display string
|
||||
cap := s.HalfLength * 60
|
||||
if cap <= 0 { cap = 45 * 60 }
|
||||
if s.Half >= 2 { cap = s.HalfLength * 120 }
|
||||
if s.ElapsedSeconds > cap { s.ElapsedSeconds = cap }
|
||||
s.Timer = formatSeconds(s.ElapsedSeconds)
|
||||
// Clear start marker when paused
|
||||
s.TimerStartUnix = 0
|
||||
if err := c.DB.Save(s).Error; err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "failed to save"}); return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user