Handle no alarm in nojs page
continuous-integration/drone/push Build is pending Details
continuous-integration/drone/tag Build is passing Details

This commit is contained in:
nemunaire 2023-08-01 09:14:32 +02:00
parent 791b577c17
commit 425571d76e
2 changed files with 17 additions and 0 deletions

View File

@ -30,11 +30,20 @@ func DeclareNoJSRoutes(router *gin.Engine, cfg *config.Config, db *reveil.LevelD
return
}
if alarm == nil {
c.HTML(http.StatusOK, "index.tmpl", gin.H{
"noAlarm": true,
"isPlaying": player.CommonPlayer != nil,
})
return
}
nCycles := int(time.Until(*alarm) / (90 * time.Minute))
nDays := int(time.Until(*alarm) / (24 * time.Hour))
nMinutes := int((time.Until(*alarm) / time.Minute) % 90)
c.HTML(http.StatusOK, "index.tmpl", gin.H{
"noAlarm": false,
"nextAlarmDate": alarm.Format("Mon 2"),
"nextAlarmTime": alarm.Format("15:04"),
"sameDay": time.Now().Day() == alarm.Day(),

View File

@ -1,5 +1,8 @@
<h1 style="margin-bottom: 0">
Prochain réveil le&nbsp;:
{{ if .noAlarm}}
aucun défini
{{ else }}
{{ if .sameDay }}
aujourd'hui
{{ else if lt .nCycles 16 }}
@ -8,18 +11,23 @@
{{ .nextAlarmDate }}
{{ end }}
à {{ .nextAlarmTime }}
{{ end }}
</h1>
{{ if not .noAlarm }}
<h2 style="color: gray; margin-top: 0; margin-left: 5em">
{{ if gt .nDays 2 }}(dans {{ .nDays }} jours){{ else }}(dans {{ .nCycles }} cycles + {{ .nMinutes }} min){{ end }}
</h2>
{{ end }}
<div style="display: flex; gap: 10px;">
{{ if not .noAlarm }}
<form method="post" action="/nojs.html">
<input type="hidden" name="action" value="cancel">
<button type="submit">
Annuler la prochaine alarme
</button>
</form>
{{ end }}
{{ if .isPlaying }}
<form method="post" action="/nojs.html">