Compare commits
20 commits
Author | SHA1 | Date | |
---|---|---|---|
|
8fa8bb4c3a | ||
|
7cf2b60803 | ||
|
db41d360dc | ||
|
6685f8bc46 | ||
|
96f7b50e4e | ||
|
8ef6a2bbfa | ||
|
d1599fe2b9 | ||
|
6909b223a7 | ||
|
570ea064aa | ||
|
f8a64e4dfd | ||
|
a8bdeae3a9 | ||
|
1deb80c776 | ||
|
85a6da0b0a | ||
|
17e555e7fc | ||
|
29e1001665 | ||
|
fe48cf780e | ||
|
169c881134 | ||
|
e55e4261dd | ||
|
c3fbfa307f | ||
|
cd123ae1c1 |
41
datapoint.go
|
@ -162,8 +162,6 @@ func DatapointAdd[T any](name string, value T) (err error) { // {{{
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
service.Db.Conn.Exec(`UPDATE datapoint SET last_value = NOW(), nodata_is_problem = false WHERE id=$1`, dpID)
|
|
||||||
|
|
||||||
return
|
return
|
||||||
} // }}}
|
} // }}}
|
||||||
|
|
||||||
|
@ -172,30 +170,19 @@ func DatapointsRetrieve() (dps []Datapoint, err error) { // {{{
|
||||||
var rows *sqlx.Rows
|
var rows *sqlx.Rows
|
||||||
rows, err = service.Db.Conn.Queryx(`
|
rows, err = service.Db.Conn.Queryx(`
|
||||||
SELECT
|
SELECT
|
||||||
dp.id,
|
id, name, datatype, last_value, "group", comment, nodata_problem_seconds,
|
||||||
dp.name,
|
last_value_id AS v_id,
|
||||||
dp.datatype,
|
CASE
|
||||||
dp.last_value,
|
WHEN last_value_id IS NULL THEN null
|
||||||
dp.group,
|
ELSE last_value
|
||||||
dp.comment,
|
END AS ts,
|
||||||
dp.nodata_problem_seconds,
|
last_value_int AS value_int,
|
||||||
|
last_value_string AS value_string,
|
||||||
dpv.id AS v_id,
|
last_value_datetime AS value_datetime
|
||||||
dpv.ts,
|
FROM datapoint
|
||||||
dpv.value_int,
|
|
||||||
dpv.value_string,
|
|
||||||
dpv.value_datetime
|
|
||||||
|
|
||||||
FROM public.datapoint dp
|
|
||||||
LEFT JOIN (
|
|
||||||
SELECT
|
|
||||||
*,
|
|
||||||
row_number() OVER (PARTITION BY "datapoint_id" ORDER BY ts DESC) AS rn
|
|
||||||
FROM datapoint_value
|
|
||||||
) dpv ON dpv.datapoint_id = dp.id AND rn = 1
|
|
||||||
ORDER BY
|
ORDER BY
|
||||||
dp.group ASC,
|
"group" ASC,
|
||||||
dp.name ASC
|
name ASC
|
||||||
`)
|
`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = werr.Wrap(err)
|
err = werr.Wrap(err)
|
||||||
|
@ -255,11 +242,11 @@ func DatapointRetrieve(id int, name string) (dp Datapoint, err error) { // {{{
|
||||||
var query string
|
var query string
|
||||||
var param any
|
var param any
|
||||||
if id > 0 {
|
if id > 0 {
|
||||||
query = `SELECT *, true AS found FROM datapoint WHERE id = $1`
|
query = `SELECT id, "group", name, "datatype", comment, last_value, nodata_problem_seconds, nodata_is_problem, true AS found FROM public.datapoint WHERE id = $1`
|
||||||
param = id
|
param = id
|
||||||
dp.ID = id
|
dp.ID = id
|
||||||
} else {
|
} else {
|
||||||
query = `SELECT *, true AS found FROM datapoint WHERE name = $1`
|
query = `SELECT id, "group", name, "datatype", comment, last_value, nodata_problem_seconds, nodata_is_problem, true AS found FROM public.datapoint WHERE name = $1`
|
||||||
param = name
|
param = name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
56
main.go
|
@ -29,7 +29,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const VERSION = "v33"
|
const VERSION = "v41"
|
||||||
|
|
||||||
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
|
||||||
|
@ -689,8 +711,15 @@ func actionDatapointUpdate(w http.ResponseWriter, r *http.Request, _ *session.T)
|
||||||
var nodataSeconds int
|
var nodataSeconds int
|
||||||
nodataSeconds, _ = strconv.Atoi(r.FormValue("nodata_seconds"))
|
nodataSeconds, _ = strconv.Atoi(r.FormValue("nodata_seconds"))
|
||||||
|
|
||||||
|
// Datapoint needs to be retrieved from database for the name.
|
||||||
|
// If name has changed, trigger expressions needs to be updated.
|
||||||
var dp Datapoint
|
var dp Datapoint
|
||||||
dp.ID = id
|
dp, err = DatapointRetrieve(id, "")
|
||||||
|
if err != nil {
|
||||||
|
httpError(w, werr.Wrap(err).WithData(id).Log())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
prevDatapointName := dp.Name
|
||||||
dp.Group = r.FormValue("group")
|
dp.Group = r.FormValue("group")
|
||||||
dp.Name = r.FormValue("name")
|
dp.Name = r.FormValue("name")
|
||||||
dp.Datatype = DatapointType(r.FormValue("datatype"))
|
dp.Datatype = DatapointType(r.FormValue("datatype"))
|
||||||
|
@ -702,6 +731,29 @@ func actionDatapointUpdate(w http.ResponseWriter, r *http.Request, _ *session.T)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the trigger expressions using this
|
||||||
|
// datapoint name if changed.
|
||||||
|
if prevDatapointName != dp.Name {
|
||||||
|
var triggers []Trigger
|
||||||
|
triggers, err = TriggersRetrieveByDatapoint(dp.Name)
|
||||||
|
if err != nil {
|
||||||
|
httpError(w, werr.Wrap(err).WithData(dp.Name))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, trigger := range triggers {
|
||||||
|
err = trigger.RenameDatapoint(prevDatapointName, dp.Name)
|
||||||
|
if err != nil {
|
||||||
|
httpError(w, werr.Wrap(err).WithData([]string{prevDatapointName, dp.Name}))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = trigger.Update()
|
||||||
|
if err != nil {
|
||||||
|
httpError(w, werr.Wrap(err).WithData([]string{prevDatapointName, dp.Name, trigger.Name}))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
w.Header().Add("Location", "/datapoints")
|
w.Header().Add("Location", "/datapoints")
|
||||||
w.WriteHeader(302)
|
w.WriteHeader(302)
|
||||||
} // }}}
|
} // }}}
|
||||||
|
|
|
@ -81,7 +81,7 @@ func (ntfy NTFY) Send(problemID int, msg []byte) (err error) {
|
||||||
|
|
||||||
ackURL := fmt.Sprintf("http, OK, %s/notification/ack?problemID=%d", ntfy.AcknowledgeURL, problemID)
|
ackURL := fmt.Sprintf("http, OK, %s/notification/ack?problemID=%d", ntfy.AcknowledgeURL, problemID)
|
||||||
req.Header.Add("X-Actions", ackURL)
|
req.Header.Add("X-Actions", ackURL)
|
||||||
req.Header.Add("X-Priority", "4") // XXX: should be 5
|
req.Header.Add("X-Priority", "5")
|
||||||
req.Header.Add("X-Tags", "calendar")
|
req.Header.Add("X-Tags", "calendar")
|
||||||
|
|
||||||
res, err = http.DefaultClient.Do(req)
|
res, err = http.DefaultClient.Do(req)
|
||||||
|
|
6
page.go
|
@ -2,7 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
// External
|
// External
|
||||||
we "git.gibonuddevalla.se/go/wrappederror"
|
werr "git.gibonuddevalla.se/go/wrappederror"
|
||||||
|
|
||||||
// Standard
|
// Standard
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -25,7 +25,7 @@ type Page struct {
|
||||||
func (p *Page) Render(w http.ResponseWriter, r *http.Request) {
|
func (p *Page) Render(w http.ResponseWriter, r *http.Request) {
|
||||||
tmpl, err := getPage(p.LAYOUT, p.PAGE)
|
tmpl, err := getPage(p.LAYOUT, p.PAGE)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpError(w, we.Wrap(err).Log())
|
httpError(w, werr.Wrap(err).Log())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,6 +58,6 @@ func (p *Page) Render(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
err = tmpl.Execute(w, data)
|
err = tmpl.Execute(w, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpError(w, we.Wrap(err).Log())
|
httpError(w, werr.Wrap(err).Log())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Before Width: | Height: | Size: 128 KiB After Width: | Height: | Size: 118 KiB |
Before Width: | Height: | Size: 9.1 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 132 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 8.9 KiB |
62
sql/00026.sql
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
/* Adding last values to the datapoint table since they are a regularly used value. */
|
||||||
|
ALTER TABLE public.datapoint ADD COLUMN last_value_id int4 NULL;
|
||||||
|
ALTER TABLE public.datapoint ADD COLUMN last_value_int int8 NULL;
|
||||||
|
ALTER TABLE public.datapoint ADD COLUMN last_value_string varchar NULL;
|
||||||
|
ALTER TABLE public.datapoint ADD COLUMN last_value_datetime timestamptz NULL;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Once-run query to update it to the latest, to avoid user having to wait for the next entry. */
|
||||||
|
UPDATE public.datapoint AS dp
|
||||||
|
SET
|
||||||
|
last_value_id = dpv.id,
|
||||||
|
last_value_int = dpv.value_int,
|
||||||
|
last_value_string = dpv.value_string,
|
||||||
|
last_value_datetime = dpv.value_datetime
|
||||||
|
FROM (
|
||||||
|
SELECT
|
||||||
|
dp.id AS datapoint_id,
|
||||||
|
dpv.id,
|
||||||
|
dpv.value_int,
|
||||||
|
dpv.value_string,
|
||||||
|
dpv.value_datetime
|
||||||
|
FROM public.datapoint dp
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT
|
||||||
|
*,
|
||||||
|
row_number() OVER (PARTITION BY "datapoint_id" ORDER BY ts DESC) AS rn
|
||||||
|
FROM datapoint_value
|
||||||
|
) dpv ON dpv.datapoint_id = dp.id AND rn = 1
|
||||||
|
) AS dpv
|
||||||
|
WHERE
|
||||||
|
dpv.datapoint_id = dp.id;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* A trigger keeps the value current without bugs introduced in software missing the entry. */
|
||||||
|
CREATE OR REPLACE FUNCTION datapoint_entry()
|
||||||
|
RETURNS TRIGGER
|
||||||
|
LANGUAGE PLPGSQL
|
||||||
|
AS
|
||||||
|
$$
|
||||||
|
BEGIN
|
||||||
|
UPDATE public.datapoint
|
||||||
|
SET
|
||||||
|
nodata_is_problem = false,
|
||||||
|
last_value = NEW.ts,
|
||||||
|
last_value_id = NEW.id,
|
||||||
|
last_value_int = NEW.value_int,
|
||||||
|
last_value_string = NEW.value_string,
|
||||||
|
last_value_datetime = NEW.value_datetime
|
||||||
|
WHERE
|
||||||
|
id = NEW.datapoint_id;
|
||||||
|
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$;
|
||||||
|
|
||||||
|
CREATE TRIGGER datapoint_entry
|
||||||
|
AFTER INSERT
|
||||||
|
ON public.datapoint_value
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE PROCEDURE datapoint_entry();
|
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,3 +1,6 @@
|
||||||
|
#datapoints-filter.invalid-regex {
|
||||||
|
background-color: #ffd5d5;
|
||||||
|
}
|
||||||
#datapoints {
|
#datapoints {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(6, min-content);
|
grid-template-columns: repeat(6, min-content);
|
||||||
|
@ -97,5 +100,5 @@
|
||||||
margin-top: 16px;
|
margin-top: 16px;
|
||||||
}
|
}
|
||||||
.graph #graph-values {
|
.graph #graph-values {
|
||||||
height: calc(100vh - 416px);
|
height: calc(100vh - 200px);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,5 +20,4 @@ input[type="datetime-local"] {
|
||||||
background-color: #1b4e78;
|
background-color: #1b4e78;
|
||||||
color: #ccc;
|
color: #ccc;
|
||||||
border: 1px solid #535353;
|
border: 1px solid #535353;
|
||||||
padding: 6px;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -262,7 +262,7 @@ label {
|
||||||
top: 16px;
|
top: 16px;
|
||||||
right: 16px;
|
right: 16px;
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 8px repeat(2, min-content) 8px 1px 8px repeat(3, min-content) 8px repeat(3, min-content) 8px 1px 8px repeat(2, min-content) 8px;
|
grid-template-columns: 8px repeat(2, min-content) 8px min-content 8px 1px 8px repeat(3, min-content) 8px repeat(3, min-content) 8px 1px 8px repeat(2, min-content) 8px;
|
||||||
grid-gap: 6px 8px;
|
grid-gap: 6px 8px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
width: min-content;
|
width: min-content;
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
input[type="datetime-local"] {
|
|
||||||
padding: 6px;
|
|
||||||
}
|
|
||||||
#notifications {
|
#notifications {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(5, min-content);
|
grid-template-columns: repeat(5, min-content);
|
||||||
grid-gap: 4px 16px;
|
grid-gap: 4px 16px;
|
||||||
margin-top: 32px;
|
margin-top: 96px;
|
||||||
margin-bottom: 32px;
|
margin-bottom: 32px;
|
||||||
background-color: #2979b8;
|
background-color: #2979b8;
|
||||||
padding: 16px 24px;
|
padding: 16px 24px;
|
||||||
|
|
|
@ -13,17 +13,24 @@
|
||||||
.widgets .datapoints {
|
.widgets .datapoints {
|
||||||
font: "Roboto Mono", monospace;
|
font: "Roboto Mono", monospace;
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: min-content min-content 1fr;
|
grid-template-columns: repeat(4, min-content);
|
||||||
gap: 6px 8px;
|
gap: 6px 8px;
|
||||||
margin-bottom: 8px;
|
margin-bottom: 8px;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
.widgets .datapoints div {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
.widgets .datapoints .invalid {
|
.widgets .datapoints .invalid {
|
||||||
color: #c83737;
|
color: #c83737;
|
||||||
}
|
}
|
||||||
.widgets .datapoints .delete img {
|
.widgets .datapoints .delete img {
|
||||||
height: 16px;
|
height: 16px;
|
||||||
}
|
}
|
||||||
|
.widgets .datapoints .values img {
|
||||||
|
height: 16px;
|
||||||
|
width: 16px;
|
||||||
|
}
|
||||||
.widgets .action {
|
.widgets .action {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: min-content min-content 1fr;
|
grid-template-columns: min-content min-content 1fr;
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
#datapoints-filter.invalid-regex {
|
||||||
|
background-color: #ffd5d5;
|
||||||
|
}
|
||||||
#datapoints {
|
#datapoints {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(6, min-content);
|
grid-template-columns: repeat(6, min-content);
|
||||||
|
@ -97,5 +100,5 @@
|
||||||
margin-top: 16px;
|
margin-top: 16px;
|
||||||
}
|
}
|
||||||
.graph #graph-values {
|
.graph #graph-values {
|
||||||
height: calc(100vh - 416px);
|
height: calc(100vh - 200px);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,5 +20,4 @@ input[type="datetime-local"] {
|
||||||
background-color: #202020;
|
background-color: #202020;
|
||||||
color: #ccc;
|
color: #ccc;
|
||||||
border: 1px solid #535353;
|
border: 1px solid #535353;
|
||||||
padding: 6px;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -262,7 +262,7 @@ label {
|
||||||
top: 16px;
|
top: 16px;
|
||||||
right: 16px;
|
right: 16px;
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 8px repeat(2, min-content) 8px 1px 8px repeat(3, min-content) 8px repeat(3, min-content) 8px 1px 8px repeat(2, min-content) 8px;
|
grid-template-columns: 8px repeat(2, min-content) 8px min-content 8px 1px 8px repeat(3, min-content) 8px repeat(3, min-content) 8px 1px 8px repeat(2, min-content) 8px;
|
||||||
grid-gap: 6px 8px;
|
grid-gap: 6px 8px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
width: min-content;
|
width: min-content;
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
input[type="datetime-local"] {
|
|
||||||
padding: 6px;
|
|
||||||
}
|
|
||||||
#notifications {
|
#notifications {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(5, min-content);
|
grid-template-columns: repeat(5, min-content);
|
||||||
grid-gap: 4px 16px;
|
grid-gap: 4px 16px;
|
||||||
margin-top: 32px;
|
margin-top: 96px;
|
||||||
margin-bottom: 32px;
|
margin-bottom: 32px;
|
||||||
background-color: #333;
|
background-color: #333;
|
||||||
padding: 16px 24px;
|
padding: 16px 24px;
|
||||||
|
|
|
@ -13,17 +13,24 @@
|
||||||
.widgets .datapoints {
|
.widgets .datapoints {
|
||||||
font: "Roboto Mono", monospace;
|
font: "Roboto Mono", monospace;
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: min-content min-content 1fr;
|
grid-template-columns: repeat(4, min-content);
|
||||||
gap: 6px 8px;
|
gap: 6px 8px;
|
||||||
margin-bottom: 8px;
|
margin-bottom: 8px;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
.widgets .datapoints div {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
.widgets .datapoints .invalid {
|
.widgets .datapoints .invalid {
|
||||||
color: #c83737;
|
color: #c83737;
|
||||||
}
|
}
|
||||||
.widgets .datapoints .delete img {
|
.widgets .datapoints .delete img {
|
||||||
height: 16px;
|
height: 16px;
|
||||||
}
|
}
|
||||||
|
.widgets .datapoints .values img {
|
||||||
|
height: 16px;
|
||||||
|
width: 16px;
|
||||||
|
}
|
||||||
.widgets .action {
|
.widgets .action {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: min-content min-content 1fr;
|
grid-template-columns: min-content min-content 1fr;
|
||||||
|
|
69
static/images/default_light/forward.svg
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
width="19.999975"
|
||||||
|
height="19.999975"
|
||||||
|
viewBox="0 0 5.29166 5.2916603"
|
||||||
|
version="1.1"
|
||||||
|
id="svg8"
|
||||||
|
inkscape:version="1.3.2 (1:1.3.2+202311252150+091e20ef0f)"
|
||||||
|
sodipodi:docname="forward.svg"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/">
|
||||||
|
<defs
|
||||||
|
id="defs2" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="22.627417"
|
||||||
|
inkscape:cx="9.3028736"
|
||||||
|
inkscape:cy="12.772116"
|
||||||
|
inkscape:document-units="px"
|
||||||
|
inkscape:current-layer="layer1"
|
||||||
|
showgrid="false"
|
||||||
|
units="px"
|
||||||
|
inkscape:window-width="2190"
|
||||||
|
inkscape:window-height="1404"
|
||||||
|
inkscape:window-x="1463"
|
||||||
|
inkscape:window-y="16"
|
||||||
|
inkscape:window-maximized="0"
|
||||||
|
inkscape:showpageshadow="true"
|
||||||
|
inkscape:pagecheckerboard="0"
|
||||||
|
inkscape:deskcolor="#d6d6d6"
|
||||||
|
showborder="true" />
|
||||||
|
<metadata
|
||||||
|
id="metadata5">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<g
|
||||||
|
inkscape:label="Layer 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1"
|
||||||
|
transform="translate(-123.825,-155.04583)">
|
||||||
|
<title
|
||||||
|
id="title1">alert</title>
|
||||||
|
<title
|
||||||
|
id="title1-1">arrow-right-bold-circle</title>
|
||||||
|
<path
|
||||||
|
d="m 123.825,157.69166 a 2.6458334,2.6458334 0 0 1 2.64583,-2.64583 2.6458334,2.6458334 0 0 1 2.64583,2.64583 2.6458334,2.6458334 0 0 1 -2.64583,2.64583 2.6458334,2.6458334 0 0 1 -2.64583,-2.64583 m 3.96875,0 -1.32292,-1.32292 v 0.79375 h -1.05833 v 1.05834 h 1.05833 v 0.79375 z"
|
||||||
|
id="path1"
|
||||||
|
style="stroke-width:0.264583;fill:#abc837" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 2.2 KiB |
69
static/images/gruvbox/forward.svg
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
width="19.999975"
|
||||||
|
height="19.999975"
|
||||||
|
viewBox="0 0 5.29166 5.2916603"
|
||||||
|
version="1.1"
|
||||||
|
id="svg8"
|
||||||
|
inkscape:version="1.3.2 (1:1.3.2+202311252150+091e20ef0f)"
|
||||||
|
sodipodi:docname="forward.svg"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/">
|
||||||
|
<defs
|
||||||
|
id="defs2" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="22.627417"
|
||||||
|
inkscape:cx="9.3028736"
|
||||||
|
inkscape:cy="12.772116"
|
||||||
|
inkscape:document-units="px"
|
||||||
|
inkscape:current-layer="layer1"
|
||||||
|
showgrid="false"
|
||||||
|
units="px"
|
||||||
|
inkscape:window-width="2190"
|
||||||
|
inkscape:window-height="1404"
|
||||||
|
inkscape:window-x="1463"
|
||||||
|
inkscape:window-y="16"
|
||||||
|
inkscape:window-maximized="0"
|
||||||
|
inkscape:showpageshadow="true"
|
||||||
|
inkscape:pagecheckerboard="0"
|
||||||
|
inkscape:deskcolor="#d6d6d6"
|
||||||
|
showborder="true" />
|
||||||
|
<metadata
|
||||||
|
id="metadata5">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<g
|
||||||
|
inkscape:label="Layer 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1"
|
||||||
|
transform="translate(-123.825,-155.04583)">
|
||||||
|
<title
|
||||||
|
id="title1">alert</title>
|
||||||
|
<title
|
||||||
|
id="title1-1">arrow-right-bold-circle</title>
|
||||||
|
<path
|
||||||
|
d="m 123.825,157.69166 a 2.6458334,2.6458334 0 0 1 2.64583,-2.64583 2.6458334,2.6458334 0 0 1 2.64583,2.64583 2.6458334,2.6458334 0 0 1 -2.64583,2.64583 2.6458334,2.6458334 0 0 1 -2.64583,-2.64583 m 3.96875,0 -1.32292,-1.32292 v 0.79375 h -1.05833 v 1.05834 h 1.05833 v 0.79375 z"
|
||||||
|
id="path1"
|
||||||
|
style="stroke-width:0.264583;fill:#abc837" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 2.2 KiB |
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,10 @@ export class UI {
|
||||||
let html = Object.keys(this.trigger.datapoints).sort().map(dpName => {
|
let html = Object.keys(this.trigger.datapoints).sort().map(dpName => {
|
||||||
const dp = this.trigger.datapoints[dpName]
|
const dp = this.trigger.datapoints[dpName]
|
||||||
return `
|
return `
|
||||||
<div class="datapoint delete"><a href="#" onclick="_ui.deleteDatapoint('${dp.Name}')"><img src="/images/${this.version}/${this.theme}/delete.svg"></a></div>
|
|
||||||
<div class="datapoint name ${dp.Found ? 'valid' : 'invalid'}"><b>${dp.Name}</b></div>
|
<div class="datapoint name ${dp.Found ? 'valid' : 'invalid'}"><b>${dp.Name}</b></div>
|
||||||
<div class="datapoint value">${dp.Found ? dp.LastDatapointValue.TemplateValue : ''}</div>
|
<div class="datapoint value">${dp.Found ? dp.LastDatapointValue.TemplateValue : ''}</div>
|
||||||
|
<div class="daatpoint values"><a href="/datapoint/values/${dp.ID}"><img src="/images/${this.version}/${this.theme}/values.svg"></a></div>
|
||||||
|
<div class="datapoint delete"><a href="#" onclick="_ui.deleteDatapoint('${dp.Name}')"><img src="/images/${this.version}/${this.theme}/delete.svg"></a></div>
|
||||||
`
|
`
|
||||||
}).join('')
|
}).join('')
|
||||||
datapoints.innerHTML += html
|
datapoints.innerHTML += html
|
||||||
|
@ -84,7 +85,7 @@ export class UI {
|
||||||
})
|
})
|
||||||
}//}}}
|
}//}}}
|
||||||
deleteDatapoint(name) {//{{{
|
deleteDatapoint(name) {//{{{
|
||||||
if (!confirm(`Delete ${name}?`)) {
|
if (!confirm(`Remove datapoint ${name} from this trigger?`)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
@import "theme-@{THEME}.less";
|
@import "theme-@{THEME}.less";
|
||||||
|
|
||||||
|
#datapoints-filter.invalid-regex {
|
||||||
|
background-color: #ffd5d5;
|
||||||
|
}
|
||||||
|
|
||||||
#datapoints {
|
#datapoints {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(6, min-content);
|
grid-template-columns: repeat(6, min-content);
|
||||||
|
@ -117,6 +121,6 @@
|
||||||
margin-top: 16px;
|
margin-top: 16px;
|
||||||
|
|
||||||
#graph-values {
|
#graph-values {
|
||||||
height: calc(100vh - 416px);
|
height: calc(100vh - 200px);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,5 +29,4 @@ input[type="datetime-local"] {
|
||||||
background-color: @bg2;
|
background-color: @bg2;
|
||||||
color: #ccc;
|
color: #ccc;
|
||||||
border: 1px solid #535353;
|
border: 1px solid #535353;
|
||||||
padding: 6px;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -297,7 +297,7 @@ label {
|
||||||
right: 16px;
|
right: 16px;
|
||||||
|
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 8px repeat(2,min-content) 8px 1px 8px repeat(3,min-content) 8px repeat(3,min-content) 8px 1px 8px repeat(2,min-content) 8px;
|
grid-template-columns: 8px repeat(2,min-content) 8px min-content 8px 1px 8px repeat(3,min-content) 8px repeat(3,min-content) 8px 1px 8px repeat(2,min-content) 8px;
|
||||||
grid-gap: 6px 8px;
|
grid-gap: 6px 8px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,10 @@
|
||||||
@import "theme-@{THEME}.less";
|
@import "theme-@{THEME}.less";
|
||||||
|
|
||||||
input[type="datetime-local"] {
|
|
||||||
padding: 6px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#notifications {
|
#notifications {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(5, min-content);
|
grid-template-columns: repeat(5, min-content);
|
||||||
grid-gap: 4px 16px;
|
grid-gap: 4px 16px;
|
||||||
margin-top: 32px;
|
margin-top: 96px;
|
||||||
margin-bottom: 32px;
|
margin-bottom: 32px;
|
||||||
background-color: @bg3;
|
background-color: @bg3;
|
||||||
padding: 16px 24px;
|
padding: 16px 24px;
|
||||||
|
|
|
@ -19,11 +19,15 @@
|
||||||
.datapoints {
|
.datapoints {
|
||||||
font: "Roboto Mono", monospace;
|
font: "Roboto Mono", monospace;
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: min-content min-content 1fr;
|
grid-template-columns: repeat(4, min-content);
|
||||||
gap: 6px 8px;
|
gap: 6px 8px;
|
||||||
margin-bottom: 8px;
|
margin-bottom: 8px;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
|
||||||
|
div {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
.invalid {
|
.invalid {
|
||||||
color: #c83737;
|
color: #c83737;
|
||||||
}
|
}
|
||||||
|
@ -31,6 +35,11 @@
|
||||||
.delete img {
|
.delete img {
|
||||||
height: 16px;
|
height: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.values img {
|
||||||
|
height: 16px;
|
||||||
|
width: 16px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.action {
|
.action {
|
||||||
|
|
40
trigger.go
|
@ -4,6 +4,8 @@ import (
|
||||||
// External
|
// External
|
||||||
werr "git.gibonuddevalla.se/go/wrappederror"
|
werr "git.gibonuddevalla.se/go/wrappederror"
|
||||||
"github.com/expr-lang/expr"
|
"github.com/expr-lang/expr"
|
||||||
|
"github.com/expr-lang/expr/ast"
|
||||||
|
"github.com/expr-lang/expr/parser"
|
||||||
"github.com/lib/pq"
|
"github.com/lib/pq"
|
||||||
|
|
||||||
// Standard
|
// Standard
|
||||||
|
@ -22,6 +24,17 @@ type Trigger struct {
|
||||||
DatapointValues map[string]any
|
DatapointValues map[string]any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ExprRenamePatcher struct {
|
||||||
|
OldName string
|
||||||
|
NewName string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p ExprRenamePatcher) Visit(node *ast.Node) {
|
||||||
|
if n, ok := (*node).(*ast.IdentifierNode); ok && n.Value == p.OldName {
|
||||||
|
ast.Patch(node, &ast.IdentifierNode{Value: p.NewName})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TriggerCreate(sectionID int, name string) (t Trigger, err error) { // {{{
|
func TriggerCreate(sectionID int, name string) (t Trigger, err error) { // {{{
|
||||||
t.SectionID = sectionID
|
t.SectionID = sectionID
|
||||||
t.Name = name
|
t.Name = name
|
||||||
|
@ -127,6 +140,14 @@ func TriggerRetrieve(id int) (trigger Trigger, err error) { // {{{
|
||||||
err = json.Unmarshal(jsonData, &trigger)
|
err = json.Unmarshal(jsonData, &trigger)
|
||||||
return
|
return
|
||||||
} // }}}
|
} // }}}
|
||||||
|
func TriggerDelete(id int) (err error) { // {{{
|
||||||
|
_, err = service.Db.Conn.Exec(`DELETE FROM public.trigger WHERE id=$1`, id)
|
||||||
|
if err != nil {
|
||||||
|
return werr.Wrap(err).WithData(id)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
} // }}}
|
||||||
|
|
||||||
func (t *Trigger) Validate() (ok bool, err error) { // {{{
|
func (t *Trigger) Validate() (ok bool, err error) { // {{{
|
||||||
if strings.TrimSpace(t.Name) == "" {
|
if strings.TrimSpace(t.Name) == "" {
|
||||||
err = fmt.Errorf("Name can't be empty")
|
err = fmt.Errorf("Name can't be empty")
|
||||||
|
@ -212,14 +233,6 @@ func (t *Trigger) Update() (err error) { // {{{
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
} // }}}
|
} // }}}
|
||||||
func TriggerDelete(id int) (err error) { // {{{
|
|
||||||
_, err = service.Db.Conn.Exec(`DELETE FROM public.trigger WHERE id=$1`, id)
|
|
||||||
if err != nil {
|
|
||||||
return werr.Wrap(err).WithData(id)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
} // }}}
|
|
||||||
|
|
||||||
func (t *Trigger) Run() (output any, err error) { // {{{
|
func (t *Trigger) Run() (output any, err error) { // {{{
|
||||||
datapoints := make(map[string]Datapoint)
|
datapoints := make(map[string]Datapoint)
|
||||||
for _, dpname := range t.Datapoints {
|
for _, dpname := range t.Datapoints {
|
||||||
|
@ -248,3 +261,14 @@ func (t *Trigger) Run() (output any, err error) { // {{{
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
} // }}}
|
} // }}}
|
||||||
|
func (t *Trigger) RenameDatapoint(from, to string) error { // {{{
|
||||||
|
tree, err := parser.Parse(t.Expression)
|
||||||
|
if err != nil {
|
||||||
|
return werr.Wrap(err).WithData(t.Expression)
|
||||||
|
}
|
||||||
|
|
||||||
|
ast.Walk(&tree.Node, ExprRenamePatcher{from, to})
|
||||||
|
t.Expression = tree.Node.String()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
} // }}}
|
||||||
|
|
|
@ -11,6 +11,11 @@
|
||||||
el.value = seconds
|
el.value = seconds
|
||||||
el.form.submit()
|
el.form.submit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function enterHandler(evt) {
|
||||||
|
if (evt.key == 'Enter')
|
||||||
|
document.getElementById('form-time-selector').submit()
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,29 +24,32 @@
|
||||||
<input type="hidden" name="time-offset" value=0>
|
<input type="hidden" name="time-offset" value=0>
|
||||||
|
|
||||||
<div id="time-selector">
|
<div id="time-selector">
|
||||||
|
{{/* ====== Row 1 ====== */}}
|
||||||
{{/* Row 1 */}}
|
|
||||||
<div></div>
|
<div></div>
|
||||||
<div class="header" style="grid-column: 2 / 4">Date and time</div>
|
<div class="header" style="grid-column: 2 / 6">Date and time</div>
|
||||||
|
|
||||||
<div></div>
|
<div></div>
|
||||||
<div class="vertical-line" style="grid-column: 5; grid-row: 1 / 5; height: 100%"> </div>
|
<div class="vertical-line" style="grid-column: 7; grid-row: 1 / 5; height: 100%"> </div>
|
||||||
<div></div>
|
<div></div>
|
||||||
|
|
||||||
<div class="header" style="grid-column: 7 / 14">Offsets</div>
|
<div class="header" style="grid-column: 9 / 16">Offsets</div>
|
||||||
|
|
||||||
<div></div>
|
<div></div>
|
||||||
<div class="vertical-line" style="grid-column: 15; grid-row: 1 / 5; height: 100%"></div>
|
<div class="vertical-line" style="grid-column: 17; grid-row: 1 / 5; height: 100%"></div>
|
||||||
<div></div>
|
<div></div>
|
||||||
|
|
||||||
<div class="header" style="grid-column: 17 / 19">Presets</div>
|
<div class="header" style="grid-column: 19 / 21">Presets</div>
|
||||||
<div></div>
|
<div></div>
|
||||||
|
|
||||||
|
|
||||||
{{/* Row 2 */}}
|
|
||||||
|
|
||||||
|
{{/* ====== Row 2 ====== */}}
|
||||||
<div></div>
|
<div></div>
|
||||||
<div>From</div>
|
<div>From</div>
|
||||||
<input name="time-f" value="{{ .Data.TimeFrom }}" type="datetime-local">
|
<input name="time-f" value="{{ .Data.TimeFrom }}" type="datetime-local" onkeydown="enterHandler(event)">
|
||||||
|
<div></div>
|
||||||
|
<div></div>
|
||||||
|
|
||||||
<div></div>
|
<div></div>
|
||||||
{{/* Vertical line */}}
|
{{/* Vertical line */}}
|
||||||
|
@ -66,10 +74,14 @@
|
||||||
<div></div>
|
<div></div>
|
||||||
|
|
||||||
|
|
||||||
{{/* Row 3 */}}
|
|
||||||
|
|
||||||
|
{{/* ====== Row 3 ====== */}}
|
||||||
<div></div>
|
<div></div>
|
||||||
<div>To</div>
|
<div>To</div>
|
||||||
<input name="time-t" value="{{ .Data.TimeTo }}" type="datetime-local">
|
<input name="time-t" value="{{ .Data.TimeTo }}" type="datetime-local" onkeydown="enterHandler(event)">
|
||||||
|
<div><img src="/images/{{ .VERSION }}/{{ .CONFIG.THEME }}/forward.svg" onclick="document.getElementById('form-time-selector').submit()"></div>
|
||||||
|
<div></div>
|
||||||
|
|
||||||
<div></div>
|
<div></div>
|
||||||
{{/* Vertical line */}}
|
{{/* Vertical line */}}
|
||||||
|
@ -95,57 +107,12 @@
|
||||||
<div></div>
|
<div></div>
|
||||||
|
|
||||||
|
|
||||||
{{/* Row 4 */}}
|
|
||||||
|
|
||||||
|
{{/* ====== Row 4 ====== */}}
|
||||||
<div style="grid-column: 1 / 5; height: 8px"></div>
|
<div style="grid-column: 1 / 5; height: 8px"></div>
|
||||||
<div style="grid-column: 6 / 15; height: 8px"></div>
|
<div style="grid-column: 8 / 17; height: 8px"></div>
|
||||||
<div style="grid-column: 16 / 20; height: 8px"></div>
|
<div style="grid-column: 18 / 22; height: 8px"></div>
|
||||||
|
|
||||||
|
|
||||||
{{/*
|
|
||||||
<div>From</div>
|
|
||||||
<div>To</div>
|
|
||||||
|
|
||||||
<div></div>
|
|
||||||
<div style="background-color: #f0f;"></div>
|
|
||||||
<div></div>
|
|
||||||
|
|
||||||
<input name="time-f" value="{{ .Data.TimeFrom }}" type="datetime-local">
|
|
||||||
<input name="time-t" value="{{ .Data.TimeTo }}" type="datetime-local">
|
|
||||||
|
|
||||||
|
|
||||||
<div id="time-filter">
|
|
||||||
<div class="header-1">Presets</div>
|
|
||||||
<div class="header-2">Offsets</div>
|
|
||||||
|
|
||||||
<div class="preset"><a href="#" onclick="preset(1)">Last hour</a></div>
|
|
||||||
|
|
||||||
<div><a href="#" onclick="offsetTime(-3600)">◀</a></div>
|
|
||||||
<div>Hour</div>
|
|
||||||
<div><a href="#" onclick="offsetTime(3600)">▶</a></div>
|
|
||||||
|
|
||||||
<div class="preset"><a href="#" onclick="preset(24)">Last 24 hours</a></div>
|
|
||||||
|
|
||||||
<div><a href="#" onclick="offsetTime(-86400)">◀</a></div>
|
|
||||||
<div>Day</div>
|
|
||||||
<div><a href="#" onclick="offsetTime(86400)">▶</a></div>
|
|
||||||
|
|
||||||
<div class="preset"><a href="#" onclick="preset(24 * 7)">Last 7 days</a></div>
|
|
||||||
|
|
||||||
<div><a href="#" onclick="offsetTime(-7 * 86400)">◀</a></div>
|
|
||||||
<div>Week</div>
|
|
||||||
<div><a href="#" onclick="offsetTime(7 * 86400)">▶</a></div>
|
|
||||||
|
|
||||||
<div class="preset"><a href="#" onclick="preset(24 * 31)">Last 31 days</a></div>
|
|
||||||
<div class="preset"><a href="#" onclick="preset(24)">Last 24 hours</a></div>
|
|
||||||
<div class="preset"><a href="#" onclick="preset(24)">Last 24 hours</a></div>
|
|
||||||
|
|
||||||
<div><a href="#" onclick="offsetTime(-31 * 86400)">◀</a></div>
|
|
||||||
<div>Month</div>
|
|
||||||
<div><a href="#" onclick="offsetTime(31 * 86400)">▶</a></div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button>OK</button>
|
|
||||||
*/}}
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
<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}}
|
||||||
|
@ -46,6 +46,17 @@
|
||||||
<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>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
|
@ -3,6 +3,46 @@
|
||||||
{{ $theme := .CONFIG.THEME }}
|
{{ $theme := .CONFIG.THEME }}
|
||||||
<link rel="stylesheet" type="text/css" href="/css/{{ .VERSION }}/{{ .CONFIG.THEME }}/datapoints.css">
|
<link rel="stylesheet" type="text/css" href="/css/{{ .VERSION }}/{{ .CONFIG.THEME }}/datapoints.css">
|
||||||
<script type="text/javascript" defer>
|
<script type="text/javascript" defer>
|
||||||
|
|
||||||
|
function validateRegex(rxp) {
|
||||||
|
try {
|
||||||
|
''.match(rxp)
|
||||||
|
return true
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function showDatapoints(id) {
|
||||||
|
if (!id)
|
||||||
|
document
|
||||||
|
.querySelectorAll(`[x-datapoint-id]`)
|
||||||
|
.forEach(matchedDP=>matchedDP.classList.remove('hidden'))
|
||||||
|
else
|
||||||
|
document
|
||||||
|
.querySelectorAll(`[x-datapoint-id="${id}"]`)
|
||||||
|
.forEach(matchedDP=>matchedDP.classList.remove('hidden'))
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideDatapoints(id) {
|
||||||
|
if (!id)
|
||||||
|
document.querySelectorAll(`[x-datapoint-id]`).forEach(matchedDP=>
|
||||||
|
matchedDP.classList.add('hidden')
|
||||||
|
)
|
||||||
|
else
|
||||||
|
document.querySelectorAll(`[x-datapoint-id="${id}"]`).forEach(matchedDP=>
|
||||||
|
matchedDP.classList.add('hidden')
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateRegexValidatedStatus(validated) {
|
||||||
|
const inputFilter = document.getElementById('datapoints-filter')
|
||||||
|
if (validated)
|
||||||
|
inputFilter.classList.remove('invalid-regex')
|
||||||
|
else
|
||||||
|
inputFilter.classList.add('invalid-regex')
|
||||||
|
}
|
||||||
|
|
||||||
function filterDatapoints(inputFilter) {
|
function filterDatapoints(inputFilter) {
|
||||||
const filter = inputFilter.value.toLowerCase()
|
const filter = inputFilter.value.toLowerCase()
|
||||||
const datapoints = document.querySelectorAll('#datapoints .name')
|
const datapoints = document.querySelectorAll('#datapoints .name')
|
||||||
|
@ -10,25 +50,25 @@
|
||||||
|
|
||||||
// Shortcut to show everything if a filter is not given.
|
// Shortcut to show everything if a filter is not given.
|
||||||
if (filter == '') {
|
if (filter == '') {
|
||||||
document.querySelectorAll(`[x-datapoint-id]`).forEach(matchedDP=>
|
showDatapoints()
|
||||||
matchedDP.classList.remove('hidden')
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Show nothing if the regex is invalid and can't matching anything.
|
||||||
|
if (!validateRegex(filter)) {
|
||||||
|
hideDatapoints()
|
||||||
|
updateRegexValidatedStatus(false)
|
||||||
|
return
|
||||||
|
} else
|
||||||
|
updateRegexValidatedStatus(true)
|
||||||
|
|
||||||
datapoints.forEach(dp=>{
|
datapoints.forEach(dp=>{
|
||||||
const dpName = dp.getAttribute('x-datapoint-name')
|
const dpName = dp.getAttribute('x-datapoint-name')
|
||||||
if (dpName.toLowerCase().includes(filter)) {
|
|
||||||
datapointID = dp.getAttribute('x-datapoint-id')
|
datapointID = dp.getAttribute('x-datapoint-id')
|
||||||
document.querySelectorAll(`[x-datapoint-id="${datapointID}"]`).forEach(matchedDP=>
|
if (dpName.toLowerCase().match(filter))
|
||||||
matchedDP.classList.remove('hidden')
|
showDatapoints(datapointID)
|
||||||
)
|
else
|
||||||
} else {
|
hideDatapoints(datapointID)
|
||||||
datapointID = dp.getAttribute('x-datapoint-id')
|
|
||||||
document.querySelectorAll(`[x-datapoint-id="${datapointID}"]`).forEach(matchedDP=>
|
|
||||||
matchedDP.classList.add('hidden')
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +89,7 @@
|
||||||
<a href="/datapoint/edit/0">Create</a>
|
<a href="/datapoint/edit/0">Create</a>
|
||||||
|
|
||||||
<div style="margin-top: 16px">
|
<div style="margin-top: 16px">
|
||||||
<input id="datapoints-filter" type="text" placeholder="Filter" style="width: 320px;" oninput="filterDatapoints(this)">
|
<input id="datapoints-filter" type="text" placeholder="Filter (regexp)" style="width: 320px;" oninput="filterDatapoints(this)">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="datapoints">
|
<div id="datapoints">
|
||||||
|
|