Immediate value presentation when adding datapoint to trigger

This commit is contained in:
Magnus Åhall 2024-07-04 16:48:57 +02:00
parent 3227c22de1
commit 0de7ca4bef
2 changed files with 17 additions and 2 deletions

17
main.go
View File

@ -951,7 +951,22 @@ func actionTriggerDatapointAdd(w http.ResponseWriter, r *http.Request, _ *sessio
return 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.Header().Add("Content-Type", "application/json")
w.Write(j) w.Write(j)
} // }}} } // }}}

View File

@ -158,7 +158,7 @@ export class Trigger {
alert(json.Error) alert(json.Error)
return return
} }
this.datapoints[dp.Name] = dp this.datapoints[dp.Name] = json.Datapoint
}) })
}//}}} }//}}}
} }