From 7599369eed47c3c43cd109a014e12cb9ecf9f98e Mon Sep 17 00:00:00 2001 From: Jade McGough Date: Wed, 7 Dec 2016 16:31:22 -0800 Subject: [PATCH] add dashboards interface/structs --- chronograf.go | 33 +++++++++++++++++++++++++++++++++ server/dashboards.go | 19 +++++++++++++++++++ server/routes.go | 22 ++++++++++++---------- server/service.go | 1 + 4 files changed, 65 insertions(+), 10 deletions(-) diff --git a/chronograf.go b/chronograf.go index 1991f7387..036b6a4ba 100644 --- a/chronograf.go +++ b/chronograf.go @@ -223,6 +223,39 @@ type UsersStore interface { FindByEmail(ctx context.Context, Email string) (*User, error) } +// DashboardID is the dashboard ID +type DashboardID int + +// Dashboard represents all visual and query data for a dashboard +type Dashboard struct { + ID DashboardID `json:"id"` + Cells []DashboardCell `json:"cells"` + Name string `json:"name"` +} + +// DashboardCell holds visual and query information for a cell +type DashboardCell struct { + X int32 `json:"x"` + Y int32 `json:"y"` + W int32 `json:"w"` + H int32 `json:"h"` + Name string `json:"name"` + Queries []string `json:"queries"` + Type string `json:"type"` +} + +// DashboardStore is the storage and retrieval of dashboards +type DashboardStore interface { + // Create a new Dashboard in the DashboardStore + Add(context.Context, *Dashboard) (*Dashboard, error) + // Delete the Dashboard from the DashboardStore + Delete(context.Context, *Dashboard) error + // Get retrieves a dashboard if `ID` exists. + Get(ctx context.Context, ID DashboardID) (*Dashboard, error) + // Update replaces the dashboard information + Update(context.Context, *Dashboard) error +} + // ExplorationID is a unique ID for an Exploration. type ExplorationID int diff --git a/server/dashboards.go b/server/dashboards.go index cd468e70d..76bfb25b5 100644 --- a/server/dashboards.go +++ b/server/dashboards.go @@ -2,6 +2,25 @@ package server import "net/http" +type dashboardLinks struct { + Self string `json:"self"` // Self link mapping to this resource +} + +type dashboardResponse struct { + *chronograf.Dashboard + Links dashboardLinks `json:"links"` +} + +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) { diff --git a/server/routes.go b/server/routes.go index 4c256e794..e91df3e47 100644 --- a/server/routes.go +++ b/server/routes.go @@ -7,21 +7,23 @@ import ( ) type getRoutesResponse struct { - Layouts string `json:"layouts"` // Location of the layouts endpoint - Mappings string `json:"mappings"` // Location of the application mappings endpoint - Sources string `json:"sources"` // Location of the sources endpoint - Users string `json:"users"` // Location of the users endpoint - Me string `json:"me"` // Location of the me endpoint + Layouts string `json:"layouts"` // Location of the layouts endpoint + Mappings string `json:"mappings"` // Location of the application mappings endpoint + Sources string `json:"sources"` // Location of the sources endpoint + Users string `json:"users"` // Location of the users endpoint + Me string `json:"me"` // Location of the me endpoint + Dashboards string `json:"dashboards"` // Location of the dashboards endpoint } // AllRoutes returns all top level routes within chronograf func AllRoutes(logger chronograf.Logger) http.HandlerFunc { routes := getRoutesResponse{ - Sources: "/chronograf/v1/sources", - Layouts: "/chronograf/v1/layouts", - Users: "/chronograf/v1/users", - Me: "/chronograf/v1/me", - Mappings: "/chronograf/v1/mappings", + Sources: "/chronograf/v1/sources", + Layouts: "/chronograf/v1/layouts", + Users: "/chronograf/v1/users", + Me: "/chronograf/v1/me", + Mappings: "/chronograf/v1/mappings", + Dashboards: "/chronograf/v1/dashboards", } return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { diff --git a/server/service.go b/server/service.go index f4e87e351..0a7363d53 100644 --- a/server/service.go +++ b/server/service.go @@ -10,6 +10,7 @@ type Service struct { LayoutStore chronograf.LayoutStore AlertRulesStore chronograf.AlertRulesStore UsersStore chronograf.UsersStore + DashboardsStore chronograf.DashboardsStore TimeSeries chronograf.TimeSeries Logger chronograf.Logger UseAuth bool