Added trigger list to datapoint edit

This commit is contained in:
Magnus Åhall 2024-07-25 08:38:06 +02:00
parent d1599fe2b9
commit 8ef6a2bbfa
2 changed files with 32 additions and 0 deletions

22
main.go
View File

@ -663,6 +663,27 @@ func pageDatapointEdit(w http.ResponseWriter, r *http.Request, _ *session.T) { /
} }
} }
/* Triggers using this datapoint is provided as a list to update
* if changing the datapoint name. Parsing expr and automatically
* changing it to renamed datapoints would be nice in the future. */
var triggers []Trigger
triggers, err = TriggersRetrieveByDatapoint(datapoint.Name)
if err != nil {
httpError(w, werr.Wrap(err).Log())
return
}
slices.SortFunc(triggers, func(a, b Trigger) int {
an := strings.ToUpper(a.Name)
bn := strings.ToUpper(b.Name)
if an < bn {
return -1
}
if an > bn {
return 1
}
return 0
})
page := Page{ page := Page{
LAYOUT: "main", LAYOUT: "main",
PAGE: "datapoint_edit", PAGE: "datapoint_edit",
@ -674,6 +695,7 @@ func pageDatapointEdit(w http.ResponseWriter, r *http.Request, _ *session.T) { /
page.Data = map[string]any{ page.Data = map[string]any{
"Datapoint": datapoint, "Datapoint": datapoint,
"Triggers": triggers,
} }
page.Render(w, r) page.Render(w, r)
return return

View File

@ -46,6 +46,16 @@
<button id="button-update">Update</button> <button id="button-update">Update</button>
{{ end }} {{ end }}
</div> </div>
<div></div>
<div style="margin-top: 32px">
<b>Used in the following triggers:</b>
<ul>
{{ range .Data.Triggers }}
<li><a href="/trigger/edit/{{ .ID }}">{{ .Name }}</a></li>
{{ end }}
</ul>
</div>
</form> </form>
{{ end }} {{ end }}