Added trigger list to datapoint edit
This commit is contained in:
parent
d1599fe2b9
commit
8ef6a2bbfa
22
main.go
22
main.go
@ -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{
|
||||
LAYOUT: "main",
|
||||
PAGE: "datapoint_edit",
|
||||
@ -674,6 +695,7 @@ func pageDatapointEdit(w http.ResponseWriter, r *http.Request, _ *session.T) { /
|
||||
|
||||
page.Data = map[string]any{
|
||||
"Datapoint": datapoint,
|
||||
"Triggers": triggers,
|
||||
}
|
||||
page.Render(w, r)
|
||||
return
|
||||
|
@ -46,6 +46,16 @@
|
||||
<button id="button-update">Update</button>
|
||||
{{ end }}
|
||||
</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>
|
||||
|
||||
{{ end }}
|
||||
|
Loading…
Reference in New Issue
Block a user