Fill fields with default values
Some checks failed
continuous-integration/drone/push Build is pending
continuous-integration/drone/tag Build is failing

This commit is contained in:
nemunaire 2024-06-18 18:32:52 +02:00
parent 11163f059b
commit a4df681f88
3 changed files with 14 additions and 3 deletions

View File

@ -30,10 +30,13 @@ func DeclareNoJSRoutes(router *gin.Engine, cfg *config.Config, db *reveil.LevelD
return return
} }
defaultAlarm := time.Now().Add(460 * time.Minute)
if alarm == nil { if alarm == nil {
c.HTML(http.StatusOK, "index.tmpl", gin.H{ c.HTML(http.StatusOK, "index.tmpl", gin.H{
"noAlarm": true, "defaultAlarm": defaultAlarm.Format("15:04"),
"isPlaying": player.CommonPlayer != nil, "noAlarm": true,
"isPlaying": player.CommonPlayer != nil,
}) })
return return
} }
@ -43,6 +46,7 @@ func DeclareNoJSRoutes(router *gin.Engine, cfg *config.Config, db *reveil.LevelD
nMinutes := int((time.Until(*alarm) / time.Minute) % 90) nMinutes := int((time.Until(*alarm) / time.Minute) % 90)
c.HTML(http.StatusOK, "index.tmpl", gin.H{ c.HTML(http.StatusOK, "index.tmpl", gin.H{
"defaultAlarm": defaultAlarm.Format("15:04"),
"noAlarm": false, "noAlarm": false,
"nextAlarmDate": alarm.Format("Mon 2"), "nextAlarmDate": alarm.Format("Mon 2"),
"nextAlarmTime": alarm.Format("15:04"), "nextAlarmTime": alarm.Format("15:04"),

View File

@ -57,7 +57,7 @@
<div style="display: flex; gap: 10px;"> <div style="display: flex; gap: 10px;">
<form method="post" action="/nojs.html"> <form method="post" action="/nojs.html">
<input type="hidden" name="action" value="new"> <input type="hidden" name="action" value="new">
<input type="text" required name="time" placeholder="00:00"> <input type="text" required name="time" placeholder="00:00" value="{{ .defaultAlarm }}">
<button type="submit"> <button type="submit">
Nouvelle alarme Nouvelle alarme
</button> </button>

View File

@ -37,15 +37,22 @@
let obj; let obj;
const vtime = new Date(Date.now() + 7.6*3600000);
switch($page.params["kind"]) { switch($page.params["kind"]) {
case "single": case "single":
obj = new AlarmSingle(); obj = new AlarmSingle();
obj.time = vtime;
break; break;
case "repeated": case "repeated":
obj = new AlarmRepeated(); obj = new AlarmRepeated();
obj.weekday = vtime.getDay();
obj.time = (vtime.getHours() < 10 ? "0" : "") + vtime.getHours() + ":" + (vtime.getMinutes() < 10 ? "0" : "") + vtime.getMinutes();
break; break;
case "exceptions": case "exceptions":
obj = new AlarmException(); obj = new AlarmException();
obj.start = new Date(Date.now()).toISOString().substring(0,10);
obj.end = new Date(Date.now() + 7.5*86400000).toISOString().substring(0,10);
break; break;
} }