Dashboard editing

This commit is contained in:
Magnus Åhall 2026-08-21 11:03:14 +02:00
parent c3fe5951d4
commit dc0ad136e6
6 changed files with 1596 additions and 65 deletions

22
main.go
View file

@ -160,7 +160,8 @@ func main() { // {{{
http.HandleFunc("/configuration/notification/delete/{prio}", actionConfigurationNotificationDelete)
http.HandleFunc("/entry/{datapoint}", actionEntryDatapoint)
http.HandleFunc("/dashboard/values", actionDashboardValues)
http.HandleFunc("GET /dashboard/values", actionDashboardValues)
http.HandleFunc("POST /dashboard/update", actionDashboardUpdate)
go nodataLoop()
@ -408,7 +409,6 @@ func pageIndex(w http.ResponseWriter, r *http.Request) { // {{{
CONFIG: smonConfig.Settings,
}
dashboard, err := DashboardGet("start")
if err != nil {
logger.Error("dashboard", "error", err)
@ -436,6 +436,24 @@ func actionDashboardValues(w http.ResponseWriter, r *http.Request) { // {{{
})
w.Write(j)
} // }}}
func actionDashboardUpdate(w http.ResponseWriter, r *http.Request) { // {{{
var dashboard Dashboard
body, _ := io.ReadAll(r.Body)
err := json.Unmarshal(body, &dashboard)
if err != nil {
httpError(w, werr.Wrap(err))
return
}
err = DashboardUpdate(dashboard)
if err != nil {
httpError(w, werr.Wrap(err))
return
}
j, _ := json.Marshal(struct{ OK bool }{true})
w.Write(j)
} // }}}
func actionAreaNew(w http.ResponseWriter, r *http.Request) { // {{{
name := r.PathValue("name")