diff --git a/garden-app/server/templates.go b/garden-app/server/templates.go
index 721c6e2e..c3aa3e96 100644
--- a/garden-app/server/templates.go
+++ b/garden-app/server/templates.go
@@ -129,6 +129,27 @@ func templateFuncs(r *http.Request) map[string]any {
return item.String() == target.String()
})
},
+ "ZoneQuickWater": func(z *ZoneResponse) []string {
+ var waterDurations []string
+ if z.NextWater.Duration == nil || z.NextWater.Duration.Duration == 0 {
+ return append(waterDurations, "15m", "30m", "1h")
+ }
+
+ divideDuration := func(d time.Duration, f int) string {
+ divided := time.Duration(int(d.Seconds())/f) * time.Second
+ if divided > time.Minute {
+ divided = (divided + 30*time.Second).Truncate(time.Minute)
+ }
+ return formatDuration(&pkg.Duration{Duration: divided})
+ }
+
+ baseDuration := z.NextWater.Duration.Duration
+ waterDurations = append(waterDurations, divideDuration(baseDuration, 4))
+ waterDurations = append(waterDurations, divideDuration(baseDuration, 2))
+ waterDurations = append(waterDurations, divideDuration(baseDuration, 1))
+
+ return waterDurations
+ },
}
}
diff --git a/garden-app/server/templates/zones.html b/garden-app/server/templates/zones.html
index 6308a41b..c179275d 100644
--- a/garden-app/server/templates/zones.html
+++ b/garden-app/server/templates/zones.html
@@ -46,7 +46,7 @@
{{ define "nextWaterDetail" }}
{{ if and .Duration .Time }}
- Watering for
+ Watering for
{{ FormatDuration .Duration }}
{{ FormatUpcomingDate .Time }}
@@ -61,7 +61,6 @@
{{ define "infoPopover" }}
-
{{ .ID }}
Position: {{ .Position }}
@@ -73,17 +72,31 @@
{{ define "zoneActionButton" }}
+{{ end }}
+
+{{ define "quickWaterLinks" }}
+{{ $zone := . }}
+{{ range (ZoneQuickWater .) }}
+
+
+ {{ . }}
+
+
+{{ end }}
{{ end }}
\ No newline at end of file
diff --git a/garden-app/server/zone_responses.go b/garden-app/server/zone_responses.go
index 7f4b3a1b..da7ec0c7 100644
--- a/garden-app/server/zone_responses.go
+++ b/garden-app/server/zone_responses.go
@@ -101,16 +101,16 @@ func (zr *ZoneResponse) Render(w http.ResponseWriter, r *http.Request) error {
)
if render.GetAcceptedContentType(r) == render.ContentTypeHTML {
- history, apiErr := zr.api.getWaterHistoryFromRequest(r, zr.Zone, logger)
- // non-fatal error so we can still render the HTML page
- if apiErr != nil {
- logger.Error("error getting water history", "error", apiErr)
- zr.HistoryError = apiErr.ErrorText
- return nil
+ // only get history when rendering a ZoneDetail page
+ if zr.api.GetIDParam(r) != "" {
+ history, apiErr := zr.api.getWaterHistoryFromRequest(r, zr.Zone, logger)
+ if apiErr != nil {
+ logger.Error("error getting water history", "error", apiErr)
+ zr.HistoryError = apiErr.ErrorText
+ }
+ zr.History = NewZoneWaterHistoryResponse(history)
}
- zr.History = NewZoneWaterHistoryResponse(history)
-
if r.Method == http.MethodPut {
w.Header().Add("HX-Trigger", "newZone")
}