chronograf/server/dashboards.go

72 lines
1.6 KiB
Go
Raw Normal View History

package server
2016-12-14 07:56:26 +00:00
import (
"fmt"
"net/http"
"github.com/influxdata/chronograf"
)
2016-12-08 00:31:22 +00:00
type dashboardLinks struct {
Self string `json:"self"` // Self link mapping to this resource
}
type dashboardResponse struct {
2016-12-14 07:56:26 +00:00
chronograf.Dashboard
2016-12-08 00:31:22 +00:00
Links dashboardLinks `json:"links"`
}
2016-12-14 06:57:52 +00:00
type getDashboardsResponse struct {
2016-12-14 07:56:26 +00:00
Dashboards []dashboardResponse `json:"dashboards"`
2016-12-14 06:57:52 +00:00
}
2016-12-14 07:56:26 +00:00
func newDashboardResponse(d chronograf.Dashboard) dashboardResponse {
2016-12-08 00:31:22 +00:00
base := "/chronograf/v1/dashboards"
return dashboardResponse{
Dashboard: d,
Links: dashboardLinks{
Self: fmt.Sprintf("%s/%d", base, d.ID),
2016-12-14 07:56:26 +00:00
},
2016-12-08 00:31:22 +00:00
}
}
// Dashboards returns all dashboards within the store
func (s *Service) Dashboards(w http.ResponseWriter, r *http.Request) {
2016-12-14 07:56:26 +00:00
ctx := r.Context()
2016-12-14 06:57:52 +00:00
dashboards, err := s.DashboardsStore.All(ctx)
if err != nil {
Error(w, http.StatusInternalServerError, "Error loading layouts", s.Logger)
return
}
2016-12-14 07:56:26 +00:00
res := getDashboardsResponse{
Dashboards: []dashboardResponse{},
}
for _, dashboard := range dashboards {
res.Dashboards = append(res.Dashboards, newDashboardResponse(dashboard))
}
encodeJSON(w, http.StatusOK, res, s.Logger)
}
// DashboardID returns a single specified dashboard
func (s *Service) DashboardID(w http.ResponseWriter, r *http.Request) {
}
// NewDashboard creates and returns a new dashboard object
func (s *Service) NewDashboard(w http.ResponseWriter, r *http.Request) {
}
// RemoveDashboard deletes a dashboard
func (s *Service) RemoveDashboard(w http.ResponseWriter, r *http.Request) {
}
// UpdateDashboard updates a dashboard
func (s *Service) UpdateDashboard(w http.ResponseWriter, r *http.Request) {
}