Worked on home dashboard
This commit is contained in:
+1
-1
Submodule grafana updated: dfef4727b6...bc673fd969
+4
-3
@@ -77,9 +77,10 @@ func Register(r *macaron.Macaron) {
|
|||||||
}, reqAccountAdmin)
|
}, reqAccountAdmin)
|
||||||
|
|
||||||
// Dashboard
|
// Dashboard
|
||||||
r.Group("/dashboard", func() {
|
r.Group("/dashboards", func() {
|
||||||
r.Combo("/:slug").Get(GetDashboard).Delete(DeleteDashboard)
|
r.Combo("/db/:slug").Get(GetDashboard).Delete(DeleteDashboard)
|
||||||
r.Post("/", reqEditorRole, bind(m.SaveDashboardCommand{}), PostDashboard)
|
r.Post("/db", reqEditorRole, bind(m.SaveDashboardCommand{}), PostDashboard)
|
||||||
|
r.Get("/home", GetHomeDashboard)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Search
|
// Search
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
|
||||||
"github.com/torkelo/grafana-pro/pkg/api/dtos"
|
"github.com/torkelo/grafana-pro/pkg/api/dtos"
|
||||||
"github.com/torkelo/grafana-pro/pkg/bus"
|
"github.com/torkelo/grafana-pro/pkg/bus"
|
||||||
"github.com/torkelo/grafana-pro/pkg/middleware"
|
"github.com/torkelo/grafana-pro/pkg/middleware"
|
||||||
m "github.com/torkelo/grafana-pro/pkg/models"
|
m "github.com/torkelo/grafana-pro/pkg/models"
|
||||||
|
"github.com/torkelo/grafana-pro/pkg/setting"
|
||||||
"github.com/torkelo/grafana-pro/pkg/util"
|
"github.com/torkelo/grafana-pro/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -81,3 +86,22 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) {
|
|||||||
|
|
||||||
c.JSON(200, util.DynMap{"status": "success", "slug": cmd.Result.Slug})
|
c.JSON(200, util.DynMap{"status": "success", "slug": cmd.Result.Slug})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetHomeDashboard(c *middleware.Context) {
|
||||||
|
filePath := path.Join(setting.StaticRootPath, "app/dashboards/default.json")
|
||||||
|
file, err := os.Open(filePath)
|
||||||
|
if err != nil {
|
||||||
|
c.JsonApiErr(500, "Failed to load home dashboard", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
dash := dtos.Dashboard{}
|
||||||
|
dash.Meta.IsHome = true
|
||||||
|
jsonParser := json.NewDecoder(file)
|
||||||
|
if err := jsonParser.Decode(&dash.Model); err != nil {
|
||||||
|
c.JsonApiErr(500, "Failed to load home dashboard", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(200, &dash)
|
||||||
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ type CurrentUser struct {
|
|||||||
|
|
||||||
type DashboardMeta struct {
|
type DashboardMeta struct {
|
||||||
IsStarred bool `json:"isStarred"`
|
IsStarred bool `json:"isStarred"`
|
||||||
|
IsHome bool `json:"isHome"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Dashboard struct {
|
type Dashboard struct {
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ var (
|
|||||||
|
|
||||||
type Dashboard struct {
|
type Dashboard struct {
|
||||||
Id int64
|
Id int64
|
||||||
Slug string `xorm:"index(IX_AccountIdSlug)"`
|
Slug string
|
||||||
AccountId int64 `xorm:"index(IX_AccountIdSlug)"`
|
AccountId int64
|
||||||
|
|
||||||
Created time.Time
|
Created time.Time
|
||||||
Updated time.Time
|
Updated time.Time
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
type HomeDashboard struct {
|
||||||
|
Id int64
|
||||||
|
UserId int64
|
||||||
|
AccountId int64
|
||||||
|
|
||||||
|
Created time.Time
|
||||||
|
Updated time.Time
|
||||||
|
|
||||||
|
Data map[string]interface{}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user