Added start of editable dashboard

This commit is contained in:
Magnus Åhall 2026-08-20 11:13:03 +02:00
parent 1af3f59b1a
commit c3fe5951d4
8 changed files with 502 additions and 92 deletions

View file

@ -1,20 +1,50 @@
package main
import (
// External
werr "git.ahall.se/go/wrappederror"
"github.com/jackc/pgx/v5"
// Standard
"context"
)
type WidgetType int
const (
WidgetLabel WidgetType = iota
WidgetOnOff
WIDGET_LABEL WidgetType = iota
WIDGET_ONOFF
)
type Widget struct {
Type WidgetType
X int
Y int
SpanX int
SpanY int
DatapointID int
Attributes map[string]string
}
type Dashboard struct {
ID int
Name string
Widgets []Widget
}
func DashboardGet(name string) (dashboard Dashboard, err error) {
var rows pgx.Rows
rows, err = db.Query(context.Background(), `SELECT * FROM dashboard WHERE name = $1`, name)
if err != nil {
err = werr.Wrap(err)
return
}
dashboard, err = pgx.CollectExactlyOneRow(rows, pgx.RowToStructByNameLax[Dashboard])
if err != nil {
err = werr.Wrap(err)
return
}
return
}