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 }) }//}}} }