omg it compiled
parent
16327a87d7
commit
de0efa0b27
|
@ -20,9 +20,9 @@ type DashboardsStore struct {
|
|||
}
|
||||
|
||||
// All returns all known dashboards
|
||||
func (s *DashboardsStore) All(ctx context.Context) ([]chronograf.Dashboard, error) {
|
||||
func (d *DashboardsStore) All(ctx context.Context) ([]chronograf.Dashboard, error) {
|
||||
var srcs []chronograf.Dashboard
|
||||
if err := s.client.db.View(func(tx *bolt.Tx) error {
|
||||
if err := d.client.db.View(func(tx *bolt.Tx) error {
|
||||
if err := tx.Bucket(DashboardBucket).ForEach(func(k, v []byte) error {
|
||||
var src chronograf.Dashboard
|
||||
if err := internal.UnmarshalDashboard(v, &src); err != nil {
|
||||
|
|
|
@ -247,6 +247,7 @@ type DashboardCell struct {
|
|||
|
||||
// DashboardsStore is the storage and retrieval of dashboards
|
||||
type DashboardsStore interface {
|
||||
All(context.Context) ([]Dashboard, error)
|
||||
// Create a new Dashboard in the DashboardStore
|
||||
Add(context.Context, *Dashboard) (*Dashboard, error)
|
||||
// Delete the Dashboard from the DashboardStore if `ID` exists.
|
||||
|
|
|
@ -1,39 +1,53 @@
|
|||
package server
|
||||
|
||||
import "net/http"
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/influxdata/chronograf"
|
||||
)
|
||||
|
||||
type dashboardLinks struct {
|
||||
Self string `json:"self"` // Self link mapping to this resource
|
||||
}
|
||||
|
||||
type dashboardResponse struct {
|
||||
*chronograf.Dashboard
|
||||
chronograf.Dashboard
|
||||
Links dashboardLinks `json:"links"`
|
||||
}
|
||||
|
||||
type getDashboardsResponse struct {
|
||||
Dashboards []ldashboardResponse `json:"dashboards"`
|
||||
Dashboards []dashboardResponse `json:"dashboards"`
|
||||
}
|
||||
|
||||
func newDashboardResponse(d *chronograf.Dashboard) dashboardResponse {
|
||||
func newDashboardResponse(d chronograf.Dashboard) dashboardResponse {
|
||||
base := "/chronograf/v1/dashboards"
|
||||
return dashboardResponse{
|
||||
Dashboard: d,
|
||||
Links: dashboardLinks{
|
||||
Self: fmt.Sprintf("%s/%d", base, d.ID),
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Dashboards returns all dashboards within the store
|
||||
func (s *Service) Dashboards(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
dashboards, err := s.DashboardsStore.All(ctx)
|
||||
if err != nil {
|
||||
Error(w, http.StatusInternalServerError, "Error loading layouts", s.Logger)
|
||||
return
|
||||
}
|
||||
|
||||
encodeJSON(w, http.StatusOK, getDashboardsResponse{Dashboards: []dashboardResponse{}}, s.Logger)
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue