Lots of work on search and dashboard loading, trying to generalize concepts and code, #960

This commit is contained in:
Torkel Ödegaard
2015-05-12 14:11:30 +02:00
parent a40299b4dc
commit b3be51f17f
15 changed files with 120 additions and 176 deletions

View File

@@ -100,6 +100,7 @@ func Register(r *macaron.Macaron) {
r.Group("/dashboards", func() {
r.Combo("/db/:slug").Get(GetDashboard).Delete(DeleteDashboard)
r.Post("/db", reqEditorRole, bind(m.SaveDashboardCommand{}), PostDashboard)
r.Get("/file/:file", GetDashboardFromJsonFile)
r.Get("/home", GetHomeDashboard)
})

View File

@@ -10,6 +10,7 @@ import (
"github.com/grafana/grafana/pkg/metrics"
"github.com/grafana/grafana/pkg/middleware"
m "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/search"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util"
)
@@ -48,7 +49,7 @@ func GetDashboard(c *middleware.Context) {
dash := query.Result
dto := dtos.DashboardFullWithMeta{
Dashboard: dash.Data,
Meta: dtos.DashboardMeta{IsStarred: isStarred, Slug: slug},
Meta: dtos.DashboardMeta{IsStarred: isStarred, Slug: slug, Type: m.DashTypeDB},
}
c.JSON(200, dto)
@@ -118,3 +119,19 @@ func GetHomeDashboard(c *middleware.Context) {
c.JSON(200, &dash)
}
func GetDashboardFromJsonFile(c *middleware.Context) {
file := c.Params(":file")
dashboard := search.GetDashboardFromJsonIndex(file)
if dashboard == nil {
c.JsonApiErr(404, "Dashboard not found", nil)
return
}
dash := dtos.DashboardFullWithMeta{Dashboard: dashboard.Data}
dash.Meta.Type = m.DashTypeJson
dash.Meta.CanSave = false
c.JSON(200, &dash)
}

View File

@@ -32,6 +32,8 @@ type DashboardMeta struct {
IsStarred bool `json:"isStarred,omitempty"`
IsHome bool `json:"isHome,omitempty"`
IsSnapshot bool `json:"isSnapshot,omitempty"`
Type string `json:"type,omitempty"`
CanSave bool `json:"canSave"`
Slug string `json:"slug"`
Expires time.Time `json:"expires"`
Created time.Time `json:"created"`