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

46
main.go
View file

@ -160,6 +160,8 @@ func main() { // {{{
http.HandleFunc("/configuration/notification/delete/{prio}", actionConfigurationNotificationDelete)
http.HandleFunc("/entry/{datapoint}", actionEntryDatapoint)
http.HandleFunc("/dashboard/values", actionDashboardValues)
go nodataLoop()
smonConfig, err = SmonConfigInit()
@ -406,18 +408,34 @@ func pageIndex(w http.ResponseWriter, r *http.Request) { // {{{
CONFIG: smonConfig.Settings,
}
data := make(map[string]any)
data["Dashboard"] = Dashboard{
Widgets: []Widget{
{Type: 0, X: 1, Y: 1, Attributes: map[string]string{"Label":"Services"}},
{Type: 1, X: 1, Y: 2, DatapointID: 13, Attributes: map[string]string{"Label":"Borg"}},
{Type: 1, X: 1, Y: 3, DatapointID: 13, Attributes: map[string]string{"Label":"Databasus"}},
},
dashboard, err := DashboardGet("start")
if err != nil {
logger.Error("dashboard", "error", err)
}
data := make(map[string]any)
data["Dashboard"] = dashboard
page.Data = data
page.Render(w, r)
} // }}}
func actionDashboardValues(w http.ResponseWriter, r *http.Request) { // {{{
values, err := DatapointsValue([]int{13, 15})
if err != nil {
logger.Error("dashboard", "error", err)
httpError(w, err)
return
}
j, _ := json.Marshal(struct {
OK bool
Values []DatapointTiny
}{
true,
values,
})
w.Write(j)
} // }}}
func actionAreaNew(w http.ResponseWriter, r *http.Request) { // {{{
name := r.PathValue("name")
@ -429,7 +447,6 @@ func actionAreaNew(w http.ResponseWriter, r *http.Request) { // {{{
w.Header().Add("Location", "/configuration")
w.WriteHeader(302)
return
} // }}}
func actionAreaRename(w http.ResponseWriter, r *http.Request) { // {{{
idStr := r.PathValue("id")
@ -448,7 +465,6 @@ func actionAreaRename(w http.ResponseWriter, r *http.Request) { // {{{
w.Header().Add("Location", "/configuration")
w.WriteHeader(302)
return
} // }}}
func actionAreaDelete(w http.ResponseWriter, r *http.Request) { // {{{
idStr := r.PathValue("id")
@ -466,7 +482,6 @@ func actionAreaDelete(w http.ResponseWriter, r *http.Request) { // {{{
w.Header().Add("Location", "/configuration")
w.WriteHeader(302)
return
} // }}}
func actionSectionNew(w http.ResponseWriter, r *http.Request) { // {{{
@ -486,7 +501,6 @@ func actionSectionNew(w http.ResponseWriter, r *http.Request) { // {{{
w.Header().Add("Location", "/configuration")
w.WriteHeader(302)
return
} // }}}
func actionSectionRename(w http.ResponseWriter, r *http.Request) { // {{{
idStr := r.PathValue("id")
@ -505,7 +519,6 @@ func actionSectionRename(w http.ResponseWriter, r *http.Request) { // {{{
w.Header().Add("Location", "/configuration")
w.WriteHeader(302)
return
} // }}}
func actionSectionDelete(w http.ResponseWriter, r *http.Request) { // {{{
idStr := r.PathValue("id")
@ -523,7 +536,6 @@ func actionSectionDelete(w http.ResponseWriter, r *http.Request) { // {{{
w.Header().Add("Location", "/configuration")
w.WriteHeader(302)
return
} // }}}
func pageProblems(w http.ResponseWriter, r *http.Request) { // {{{
@ -588,7 +600,6 @@ func pageProblems(w http.ResponseWriter, r *http.Request) { // {{{
"TimeTo": timeTo.Format("2006-01-02T15:04:05"),
}
page.Render(w, r)
return
} // }}}
func actionProblemAcknowledge(w http.ResponseWriter, r *http.Request) { // {{{
idStr := r.PathValue("id")
@ -606,8 +617,6 @@ func actionProblemAcknowledge(w http.ResponseWriter, r *http.Request) { // {{{
w.Header().Add("Location", "/problems")
w.WriteHeader(302)
return
} // }}}
func actionProblemUnacknowledge(w http.ResponseWriter, r *http.Request) { // {{{
idStr := r.PathValue("id")
@ -625,8 +634,6 @@ func actionProblemUnacknowledge(w http.ResponseWriter, r *http.Request) { // {{{
w.Header().Add("Location", "/problems")
w.WriteHeader(302)
return
} // }}}
func pageDatapoints(w http.ResponseWriter, r *http.Request) { // {{{
@ -653,7 +660,6 @@ func pageDatapoints(w http.ResponseWriter, r *http.Request) { // {{{
"Datapoints": datapoints,
}
page.Render(w, r)
return
} // }}}
func pageDatapointEdit(w http.ResponseWriter, r *http.Request) { // {{{
idStr := r.PathValue("id")
@ -710,7 +716,6 @@ func pageDatapointEdit(w http.ResponseWriter, r *http.Request) { // {{{
"Triggers": triggers,
}
page.Render(w, r)
return
} // }}}
func actionDatapointUpdate(w http.ResponseWriter, r *http.Request) { // {{{
idStr := r.PathValue("id")
@ -843,7 +848,6 @@ func pageDatapointValues(w http.ResponseWriter, r *http.Request) { // {{{
"TimeTo": timeTo.Format("2006-01-02T15:04:05"),
}
page.Render(w, r)
return
} // }}}
func actionDatapointJson(w http.ResponseWriter, r *http.Request) { // {{{
idStr := r.PathValue("id")