From 0de7ca4bef411b05c142f4be1e80fa95d7715b13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20=C3=85hall?= Date: Thu, 4 Jul 2024 16:48:57 +0200 Subject: [PATCH 1/3] Immediate value presentation when adding datapoint to trigger --- main.go | 17 ++++++++++++++++- static/js/trigger_edit.mjs | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index b429a8d..3673310 100644 --- a/main.go +++ b/main.go @@ -951,7 +951,22 @@ func actionTriggerDatapointAdd(w http.ResponseWriter, r *http.Request, _ *sessio return } - j, _ := json.Marshal(struct{ OK bool }{OK: true}) + // Also retrieve the datapoint to get the latest value + // for immediate presentation when added. + dp, err := DatapointRetrieve(0, dpName) + if err != nil { + httpError(w, werr.Wrap(err).WithData(dpName).Log()) + return + } + dp.LastDatapointValue.TemplateValue = dp.LastDatapointValue.Value() + j, _ := json.Marshal( + struct { + OK bool + Datapoint Datapoint + }{ + true, + dp, + }) w.Header().Add("Content-Type", "application/json") w.Write(j) } // }}} diff --git a/static/js/trigger_edit.mjs b/static/js/trigger_edit.mjs index f706136..826afd4 100644 --- a/static/js/trigger_edit.mjs +++ b/static/js/trigger_edit.mjs @@ -158,7 +158,7 @@ export class Trigger { alert(json.Error) return } - this.datapoints[dp.Name] = dp + this.datapoints[dp.Name] = json.Datapoint }) }//}}} } From fefd4af10cd0c79fe37887f4160d4ec28e636bdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20=C3=85hall?= Date: Thu, 4 Jul 2024 16:54:23 +0200 Subject: [PATCH 2/3] Present times in configured timezone --- datapoint.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/datapoint.go b/datapoint.go index a75491a..2d2286e 100644 --- a/datapoint.go +++ b/datapoint.go @@ -54,14 +54,14 @@ func (dp DatapointValue) Value() any { // {{{ } if dp.ValueDateTime.Valid { - return dp.ValueDateTime.Time + return dp.ValueDateTime.Time.In(smonConfig.timezoneLocation) } return nil } // }}} func (dp DatapointValue) FormattedTime() string { // {{{ if dp.ValueDateTime.Valid { - return dp.ValueDateTime.Time.Format("2006-01-02 15:04:05") + return dp.ValueDateTime.Time.In(smonConfig.timezoneLocation).Format("2006-01-02 15:04:05") } return "invalid time" } // }}} From 5d24baedac98a0f034e38c694dc472e344cfa49c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20=C3=85hall?= Date: Thu, 4 Jul 2024 16:55:29 +0200 Subject: [PATCH 3/3] Bumped to v31 --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 3673310..dfca0a2 100644 --- a/main.go +++ b/main.go @@ -29,7 +29,7 @@ import ( "time" ) -const VERSION = "v30" +const VERSION = "v31" var ( logger *slog.Logger