From baeeced87b59549c31b8066769f72be954525830 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20=C3=85hall?= Date: Thu, 2 May 2024 08:59:55 +0200 Subject: [PATCH] Implemented datapoint delete --- datapoint.go | 7 ++++ main.go | 18 ++++++++++ static/css/datapoints.css | 2 +- static/images/delete.svg | 67 +++++++++++++++++++++++++++++++++++ static/less/datapoints.less | 2 +- views/pages/datapoints.gotmpl | 8 +++-- 6 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 static/images/delete.svg diff --git a/datapoint.go b/datapoint.go index 9e925ad..a4b556b 100644 --- a/datapoint.go +++ b/datapoint.go @@ -233,3 +233,10 @@ func DatapointRetrieve(id int, name string) (dp Datapoint, err error) { // {{{ return } // }}} +func DatapointDelete(id int) (err error) {// {{{ + _, err = service.Db.Conn.Exec(`DELETE FROM datapoint WHERE id=$1`, id) + if err != nil { + err = we.Wrap(err).WithData(id) + } + return +}// }}} diff --git a/main.go b/main.go index bc8aaeb..c19f337 100644 --- a/main.go +++ b/main.go @@ -111,6 +111,7 @@ func main() { // {{{ service.Register("/datapoints", false, false, pageDatapoints) service.Register("/datapoint/edit/{id}", false, false, pageDatapointEdit) service.Register("/datapoint/update/{id}", false, false, pageDatapointUpdate) + service.Register("/datapoint/delete/{id}", false, false, pageDatapointDelete) service.Register("/triggers", false, false, pageTriggers) service.Register("/trigger/edit/{id}", false, false, pageTriggerEdit) @@ -491,6 +492,23 @@ func pageDatapointUpdate(w http.ResponseWriter, r *http.Request, _ *session.T) { w.Header().Add("Location", "/datapoints") w.WriteHeader(302) } // }}} +func pageDatapointDelete(w http.ResponseWriter, r *http.Request, _ *session.T) { // {{{ + idStr := r.PathValue("id") + id, err := strconv.Atoi(idStr) + if err != nil { + httpError(w, we.Wrap(err).Log()) + return + } + + err = DatapointDelete(id) + if err != nil { + httpError(w, we.Wrap(err).Log()) + return + } + + w.Header().Add("Location", "/datapoints") + w.WriteHeader(302) +} // }}} func pageTriggers(w http.ResponseWriter, _ *http.Request, _ *session.T) { // {{{ areas, err := TriggersRetrieve() diff --git a/static/css/datapoints.css b/static/css/datapoints.css index 35f613e..0713253 100644 --- a/static/css/datapoints.css +++ b/static/css/datapoints.css @@ -99,7 +99,7 @@ label { } #datapoints { display: grid; - grid-template-columns: repeat(4, min-content); + grid-template-columns: repeat(5, min-content); grid-gap: 8px 16px; margin-top: 16px; } diff --git a/static/images/delete.svg b/static/images/delete.svg new file mode 100644 index 0000000..23ba519 --- /dev/null +++ b/static/images/delete.svg @@ -0,0 +1,67 @@ + + + + + + + + + + image/svg+xml + + + + + + trash-can-outline + + + diff --git a/static/less/datapoints.less b/static/less/datapoints.less index 2bffef9..7483cc9 100644 --- a/static/less/datapoints.less +++ b/static/less/datapoints.less @@ -2,7 +2,7 @@ #datapoints { display: grid; - grid-template-columns: repeat(4, min-content); + grid-template-columns: repeat(5, min-content); grid-gap: 8px 16px; margin-top: 16px; diff --git a/views/pages/datapoints.gotmpl b/views/pages/datapoints.gotmpl index a3c073f..50e3727 100644 --- a/views/pages/datapoints.gotmpl +++ b/views/pages/datapoints.gotmpl @@ -1,5 +1,6 @@ {{ define "page" }} - + {{ $version := .VERSION }} + {{ block "page_label" . }}{{end}} @@ -10,6 +11,7 @@
Datatype
Last value
Value
+
{{ range .Data.Datapoints }}
@@ -20,8 +22,8 @@
{{ if .LastDatapointValue.ValueDateTime.Valid }}{{ format_time .LastDatapointValue.Value }}{{ end }}
{{ else }}
{{ .LastDatapointValue.Value }}
- {{ end }} + {{ end }} +
{{ end }} - {{ end }}