Compare commits
3 Commits
d1599fe2b9
...
6685f8bc46
Author | SHA1 | Date | |
---|---|---|---|
|
6685f8bc46 | ||
|
96f7b50e4e | ||
|
8ef6a2bbfa |
24
main.go
24
main.go
@ -29,7 +29,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const VERSION = "v39"
|
const VERSION = "v40"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
@ -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
|
||||||
|
22
sql/00027.sql
Normal file
22
sql/00027.sql
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
/* Updating a datapoint name also updates the jsonb array entry */
|
||||||
|
CREATE OR REPLACE FUNCTION update_triggers_datapoint_name()
|
||||||
|
RETURNS TRIGGER
|
||||||
|
LANGUAGE PLPGSQL
|
||||||
|
AS
|
||||||
|
$$
|
||||||
|
BEGIN
|
||||||
|
UPDATE "trigger"
|
||||||
|
SET
|
||||||
|
datapoints = (datapoints - OLD.name) || jsonb_build_array(NEW.name)
|
||||||
|
WHERE
|
||||||
|
datapoints ? OLD.name;
|
||||||
|
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$;
|
||||||
|
|
||||||
|
CREATE TRIGGER datapoint_renamed
|
||||||
|
AFTER UPDATE
|
||||||
|
ON public.datapoint
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE PROCEDURE update_triggers_datapoint_name();
|
@ -1,5 +1,6 @@
|
|||||||
export class UI {
|
export class UI {
|
||||||
constructor() {
|
constructor(datapointData) {
|
||||||
|
this.datapoint = datapointData
|
||||||
document.addEventListener('keydown', evt=>this.keyHandler(evt))
|
document.addEventListener('keydown', evt=>this.keyHandler(evt))
|
||||||
document.querySelector('input[name="group"]').focus()
|
document.querySelector('input[name="group"]').focus()
|
||||||
}
|
}
|
||||||
@ -16,4 +17,10 @@ export class UI {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
check_rename() {
|
||||||
|
let newName = document.querySelector(`input[name="name"]`).value
|
||||||
|
if (newName != this.datapoint.Name)
|
||||||
|
return confirm(`Trigger expressions needs to be manually updated when renaming a datapoint.\nDo you want to rename the datapoint?`)
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,48 +3,59 @@
|
|||||||
|
|
||||||
<script type="module" defer>
|
<script type="module" defer>
|
||||||
import {UI} from "/js/{{ .VERSION }}/datapoint_edit.mjs"
|
import {UI} from "/js/{{ .VERSION }}/datapoint_edit.mjs"
|
||||||
window._ui = new UI()
|
window._ui = new UI({{ .Data.Datapoint }})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{{ block "page_label" . }}{{end}}
|
{{ block "page_label" . }}{{end}}
|
||||||
|
|
||||||
<form id="form-trigger" action="/datapoint/update/{{ .Data.Datapoint.ID }}" method="post">
|
<form id="form-trigger" action="/datapoint/update/{{ .Data.Datapoint.ID }}" method="post" onsubmit="return _ui.check_rename()">
|
||||||
<div id="widgets" class="widgets">
|
<div id="widgets" class="widgets">
|
||||||
<div class="label">Group</div>
|
<div class="label">Group</div>
|
||||||
<div><input type="text" name="group" value="{{ .Data.Datapoint.Group }}"></div>
|
<div><input type="text" name="group" value="{{ .Data.Datapoint.Group }}"></div>
|
||||||
|
|
||||||
<div class="label">Name</div>
|
<div class="label">Name</div>
|
||||||
<div><input type="text" name="name" value="{{ .Data.Datapoint.Name }}"></div>
|
<div><input type="text" name="name" value="{{ .Data.Datapoint.Name }}"></div>
|
||||||
|
|
||||||
<div class="label">Datatype</div>
|
<div class="label">Datatype</div>
|
||||||
<div>
|
<div>
|
||||||
<select name="datatype">
|
<select name="datatype">
|
||||||
<option {{ if eq .Data.Datapoint.Datatype "INT" }}selected{{end}}>INT</option>
|
<option {{ if eq .Data.Datapoint.Datatype "INT" }}selected{{end}}>INT</option>
|
||||||
<option {{ if eq .Data.Datapoint.Datatype "STRING" }}selected{{end}}>STRING</option>
|
<option {{ if eq .Data.Datapoint.Datatype "STRING" }}selected{{end}}>STRING</option>
|
||||||
<option {{ if eq .Data.Datapoint.Datatype "DATETIME" }}selected{{end}}>DATETIME</option>
|
<option {{ if eq .Data.Datapoint.Datatype "DATETIME" }}selected{{end}}>DATETIME</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="label">No data<br>problem time<br>(seconds)</div>
|
<div class="label">No data<br>problem time<br>(seconds)</div>
|
||||||
<div>
|
<div>
|
||||||
<input type="text" name="nodata_seconds" value="{{ .Data.Datapoint.NodataProblemSeconds }}">
|
<input type="text" name="nodata_seconds" value="{{ .Data.Datapoint.NodataProblemSeconds }}">
|
||||||
<div class="description">A problem is raised and notified if an entry isn't made within this time.</div>
|
<div class="description">A problem is raised and notified if an entry isn't made within this time.</div>
|
||||||
<div class="description">Set to 0 to disable.</div>
|
<div class="description">Set to 0 to disable.</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="label">Comment</div>
|
<div class="label">Comment</div>
|
||||||
<div>
|
<div>
|
||||||
<textarea name="comment" rows=4>{{ .Data.Datapoint.Comment }}</textarea>
|
<textarea name="comment" rows=4>{{ .Data.Datapoint.Comment }}</textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div></div>
|
<div></div>
|
||||||
<div class="action">
|
<div class="action">
|
||||||
{{ if eq .Data.Datapoint.ID 0 }}
|
{{ if eq .Data.Datapoint.ID 0 }}
|
||||||
<button id="button-update">Create</button>
|
<button id="button-update">Create</button>
|
||||||
{{ else }}
|
{{ else }}
|
||||||
<button id="button-update">Update</button>
|
<button id="button-update">Update</button>
|
||||||
{{ end }}
|
{{ 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>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user