From a4df681f887ad68b9afa16adb0b35fccf7b10720 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Tue, 18 Jun 2024 18:32:52 +0200 Subject: [PATCH] Fill fields with default values --- ui/nojs.go | 8 ++++++-- ui/nojs_templates/index.tmpl | 2 +- ui/src/routes/alarms/[kind]/new/+page.svelte | 7 +++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ui/nojs.go b/ui/nojs.go index 6611b91..d942c27 100644 --- a/ui/nojs.go +++ b/ui/nojs.go @@ -30,10 +30,13 @@ func DeclareNoJSRoutes(router *gin.Engine, cfg *config.Config, db *reveil.LevelD return } + defaultAlarm := time.Now().Add(460 * time.Minute) + if alarm == nil { c.HTML(http.StatusOK, "index.tmpl", gin.H{ - "noAlarm": true, - "isPlaying": player.CommonPlayer != nil, + "defaultAlarm": defaultAlarm.Format("15:04"), + "noAlarm": true, + "isPlaying": player.CommonPlayer != nil, }) return } @@ -43,6 +46,7 @@ func DeclareNoJSRoutes(router *gin.Engine, cfg *config.Config, db *reveil.LevelD nMinutes := int((time.Until(*alarm) / time.Minute) % 90) c.HTML(http.StatusOK, "index.tmpl", gin.H{ + "defaultAlarm": defaultAlarm.Format("15:04"), "noAlarm": false, "nextAlarmDate": alarm.Format("Mon 2"), "nextAlarmTime": alarm.Format("15:04"), diff --git a/ui/nojs_templates/index.tmpl b/ui/nojs_templates/index.tmpl index eb4be82..6717201 100644 --- a/ui/nojs_templates/index.tmpl +++ b/ui/nojs_templates/index.tmpl @@ -57,7 +57,7 @@
- + diff --git a/ui/src/routes/alarms/[kind]/new/+page.svelte b/ui/src/routes/alarms/[kind]/new/+page.svelte index 0023515..c48c453 100644 --- a/ui/src/routes/alarms/[kind]/new/+page.svelte +++ b/ui/src/routes/alarms/[kind]/new/+page.svelte @@ -37,15 +37,22 @@ let obj; + const vtime = new Date(Date.now() + 7.6*3600000); + switch($page.params["kind"]) { case "single": obj = new AlarmSingle(); + obj.time = vtime; break; case "repeated": obj = new AlarmRepeated(); + obj.weekday = vtime.getDay(); + obj.time = (vtime.getHours() < 10 ? "0" : "") + vtime.getHours() + ":" + (vtime.getMinutes() < 10 ? "0" : "") + vtime.getMinutes(); break; case "exceptions": 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; }