improve charts
This commit is contained in:
@@ -27,7 +27,6 @@ type dashboardResponse struct {
|
||||
GeneratedAt time.Time `json:"generated_at"`
|
||||
Site string `json:"site"`
|
||||
Model string `json:"model"`
|
||||
OpenMeteoURL string `json:"open_meteo_url,omitempty"`
|
||||
RangeStart time.Time `json:"range_start"`
|
||||
RangeEnd time.Time `json:"range_end"`
|
||||
Observations []db.ObservationPoint `json:"observations"`
|
||||
@@ -53,6 +52,12 @@ func runWebServer(ctx context.Context, d *db.DB, site providers.Site, model, add
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`{"ok":true}`))
|
||||
})
|
||||
mux.HandleFunc("/chart", func(w http.ResponseWriter, r *http.Request) {
|
||||
serveIndex(w, sub)
|
||||
})
|
||||
mux.HandleFunc("/chart/", func(w http.ResponseWriter, r *http.Request) {
|
||||
serveIndex(w, sub)
|
||||
})
|
||||
mux.Handle("/", http.FileServer(http.FS(sub)))
|
||||
|
||||
srv := &http.Server{
|
||||
@@ -82,6 +87,16 @@ func runWebServer(ctx context.Context, d *db.DB, site providers.Site, model, add
|
||||
}
|
||||
}
|
||||
|
||||
func serveIndex(w http.ResponseWriter, sub fs.FS) {
|
||||
b, err := fs.ReadFile(sub, "index.html")
|
||||
if err != nil {
|
||||
http.Error(w, "not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
_, _ = w.Write(b)
|
||||
}
|
||||
|
||||
func (s *webServer) handleDashboard(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
@@ -154,16 +169,10 @@ func (s *webServer) handleDashboard(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
openMeteoURL, err := providers.OpenMeteoRequestURL(s.site, s.model)
|
||||
if err != nil {
|
||||
log.Printf("web dashboard open-meteo url error: %v", err)
|
||||
}
|
||||
|
||||
resp := dashboardResponse{
|
||||
GeneratedAt: time.Now().UTC(),
|
||||
Site: s.site.Name,
|
||||
Model: s.model,
|
||||
OpenMeteoURL: openMeteoURL,
|
||||
RangeStart: start,
|
||||
RangeEnd: end,
|
||||
Observations: observations,
|
||||
|
||||
Reference in New Issue
Block a user