diff --git a/main.go b/main.go index b8d04e0..90bf8b2 100644 --- a/main.go +++ b/main.go @@ -143,6 +143,7 @@ func main() { // {{{ service.Register("/trigger/addDatapoint/{id}/{datapointName}", false, false, pageTriggerDatapointAdd) service.Register("/trigger/update/{id}", false, false, pageTriggerUpdate) service.Register("/trigger/run/{id}", false, false, pageTriggerRun) + service.Register("/trigger/delete/{id}", false, false, actionTriggerDelete) service.Register("/configuration", false, false, pageConfiguration) service.Register("/entry/{datapoint}", false, false, entryDatapoint) @@ -695,7 +696,7 @@ func triggerCreate(w http.ResponseWriter, r *http.Request, _ *session.T) { // {{ } resp := struct { - OK bool + OK bool Trigger Trigger }{ true, @@ -862,6 +863,23 @@ func pageTriggerRun(w http.ResponseWriter, r *http.Request, _ *session.T) { // { w.Header().Add("Content-Type", "application/json") w.Write(j) } // }}} +func actionTriggerDelete(w http.ResponseWriter, r *http.Request, _ *session.T) { // {{{ + idStr := r.PathValue("id") + id, err := strconv.Atoi(idStr) + if err != nil { + httpError(w, werr.Wrap(err).Log()) + return + } + + err = TriggerDelete(id) + if err != nil { + httpError(w, werr.Wrap(err).Log()) + return + } + + w.Header().Add("Location", "/triggers") + w.WriteHeader(302) +} // }}} func pageConfiguration(w http.ResponseWriter, _ *http.Request, _ *session.T) { // {{{ areas, err := AreaRetrieve() diff --git a/static/css/main.css b/static/css/main.css index eda60f3..a213f0d 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -201,19 +201,6 @@ label { #areas .area .section > .name { font-weight: 800; } -#areas .area .section .triggers .trigger { - display: grid; - grid-template-columns: min-content 1fr; - grid-gap: 8px; - align-items: center; - margin-top: 8px; -} -#areas .area .section .triggers .trigger img { - height: 16px; -} -#areas .area .section .triggers .trigger .label { - color: inherit; -} dialog { background: #202020; border: 1px solid #606060; diff --git a/static/css/triggers.css b/static/css/triggers.css new file mode 100644 index 0000000..352428d --- /dev/null +++ b/static/css/triggers.css @@ -0,0 +1,117 @@ +html { + box-sizing: border-box; +} +*, +*:before, +*:after { + box-sizing: inherit; +} +*:focus { + outline: none; +} +[onClick] { + cursor: pointer; +} +html, +body { + margin: 0; + padding: 0; +} +body { + background: #282828; + font-family: sans-serif; + font-weight: 300; + color: #d5c4a1; + font-size: 11pt; +} +h1, +h2 { + margin-bottom: 4px; +} +h1:first-child, +h2:first-child { + margin-top: 0px; +} +h1 { + font-size: 1.5em; + color: #fb4934; + font-weight: 800; +} +h2 { + font-size: 1.25em; + color: #b8bb26; + font-weight: 800; +} +a { + color: #3f9da1; + text-decoration: none; +} +a:hover { + text-decoration: underline; +} +b { + font-weight: 800; +} +input[type="text"], +textarea, +select { + font-family: monospace; + background: #202020; + color: #d5c4a1; + padding: 4px 8px; + border: none; + font-size: 1em; + line-height: 1.5em; +} +button { + background: #202020; + color: #d5c4a1; + padding: 8px 32px; + border: 1px solid #535353; + font-size: 1em; + height: 3em; +} +button:focus { + background: #333; +} +.line { + grid-column: 1 / -1; + border-bottom: 1px solid #4e4e4e; +} +span.date { + color: #d5c4a1; + font-weight: 800; +} +span.time { + font-size: 0.9em; + color: #d5c4a1; +} +span.seconds { + display: none; +} +label { + user-select: none; +} +.description { + border: 1px solid #737373; + color: #3f9da1; + background: #202020; + padding: 4px 8px; + margin-top: 8px; + white-space: nowrap; + width: min-content; + border-radius: 8px; +} +#areas .area .section .triggers .trigger { + display: grid; + grid-template-columns: min-content 1fr min-content; + grid-gap: 8px; + align-items: center; + margin-top: 8px; +} +#areas .area .section .triggers .trigger img { + height: 16px; +} +#areas .area .section .triggers .trigger .label { + color: inherit; +} diff --git a/static/less/main.less b/static/less/main.less index 0f061e2..de80c87 100644 --- a/static/less/main.less +++ b/static/less/main.less @@ -117,24 +117,6 @@ &>.name { font-weight: @bold; } - - .triggers { - .trigger { - display: grid; - grid-template-columns: min-content 1fr; - grid-gap: 8px; - align-items: center; - margin-top: 8px; - - img { - height: 16px; - } - - .label { - color: inherit; - } - } - } } } } diff --git a/static/less/triggers.less b/static/less/triggers.less new file mode 100644 index 0000000..9fecbe5 --- /dev/null +++ b/static/less/triggers.less @@ -0,0 +1,26 @@ +@import 'theme.less'; + + +#areas { + .area { + .section { + .triggers { + .trigger { + display: grid; + grid-template-columns: min-content 1fr min-content; + grid-gap: 8px; + align-items: center; + margin-top: 8px; + + img { + height: 16px; + } + + .label { + color: inherit; + } + } + } + } + } +} diff --git a/trigger.go b/trigger.go index 6020f12..6525598 100644 --- a/trigger.go +++ b/trigger.go @@ -2,7 +2,7 @@ package main import ( // External - we "git.gibonuddevalla.se/go/wrappederror" + werr "git.gibonuddevalla.se/go/wrappederror" "github.com/expr-lang/expr" "github.com/lib/pq" @@ -67,7 +67,7 @@ func TriggersRetrieve() (areas []Area, err error) { // {{{ var jsonData []byte err = row.Scan(&jsonData) if err != nil { - err = we.Wrap(err) + err = werr.Wrap(err) return } @@ -77,7 +77,7 @@ func TriggersRetrieve() (areas []Area, err error) { // {{{ err = json.Unmarshal(jsonData, &areas) if err != nil { - err = we.Wrap(err) + err = werr.Wrap(err) return } @@ -97,13 +97,13 @@ func TriggersRetrieveByDatapoint(datapointName string) (triggers []Trigger, err var data []byte err = row.Scan(&data) if err != nil { - err = we.Wrap(err).WithData(datapointName) + err = werr.Wrap(err).WithData(datapointName) return } err = json.Unmarshal(data, &triggers) if err != nil { - err = we.Wrap(err).WithData(datapointName) + err = werr.Wrap(err).WithData(datapointName) return } @@ -114,7 +114,7 @@ func TriggerRetrieve(id int) (trigger Trigger, err error) { // {{{ var jsonData []byte err = row.Scan(&jsonData) if err != nil { - err = we.Wrap(err) + err = werr.Wrap(err) return } @@ -158,7 +158,7 @@ func (t *Trigger) Update() (err error) { // {{{ ) err = row.Scan(&t.ID) if err != nil { - err = we.Wrap(err).WithData( + err = werr.Wrap(err).WithData( struct { SectionID int Name string @@ -191,7 +191,7 @@ func (t *Trigger) Update() (err error) { // {{{ } if pqErr, ok := err.(*pq.Error); ok { - err = we.Wrap(err).WithData( + err = werr.Wrap(err).WithData( struct { Trigger *Trigger PostgresCode pq.ErrorCode @@ -202,7 +202,14 @@ func (t *Trigger) Update() (err error) { // {{{ pqErr.Code.Name(), }) } else if err != nil { - err = we.Wrap(err).WithData(t) + err = werr.Wrap(err).WithData(t) + } + 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 } // }}} @@ -213,7 +220,7 @@ func (t *Trigger) Run() (output any, err error) { // {{{ var dp Datapoint dp, err = DatapointRetrieve(0, dpname) if err != nil { - err = we.Wrap(err) + err = werr.Wrap(err) return } datapoints[dpname] = dp diff --git a/views/pages/triggers.gotmpl b/views/pages/triggers.gotmpl index 60baf48..a0a5bef 100644 --- a/views/pages/triggers.gotmpl +++ b/views/pages/triggers.gotmpl @@ -2,6 +2,7 @@ {{ block "page_label" . }}{{end}} {{ $version := .VERSION }} +
@@ -42,12 +49,11 @@ {{ if eq .Name "" }} {{ continue }} {{ end }} - -
- -
{{ .Name }}
-
-
+
+ + + +
{{ end }}