Commit 749fd618 by utkarshcmu

Saving home dashboard id in table

parent a88176e0
......@@ -160,7 +160,12 @@ func Register(r *macaron.Macaron) {
r.Delete("/:id", wrap(DeleteApiKey))
}, reqOrgAdmin)
r.Combo("/preferences").Get(GetPreferences).Put(bind(m.SavePreferencesCommand{}), wrap(SavePreferences))
// Preferences
r.Group("/preferences", func() {
r.Get("/", wrap(GetPreferences))
r.Put("/", bind(m.SavePreferencesCommand{}), wrap(SavePreferences))
r.Post("/set-home-dash", bind(m.SavePreferencesCommand{}), wrap(SetHomeDashboard))
})
// Data sources
r.Group("/datasources", func() {
......
......@@ -7,7 +7,7 @@ import (
m "github.com/grafana/grafana/pkg/models"
)
// PUT /api/user/prefs
// PUT /api/preferences
func SavePreferences(c *middleware.Context, cmd m.SavePreferencesCommand) Response {
cmd.UserId = c.UserId
......@@ -21,7 +21,7 @@ func SavePreferences(c *middleware.Context, cmd m.SavePreferencesCommand) Respon
}
// GET /api/user/prefs
// GET /api/preferences
func GetPreferences(c *middleware.Context) {
query := m.GetPreferencesQuery{UserId: c.UserId, OrgId: c.OrgId}
......@@ -38,3 +38,17 @@ func GetPreferences(c *middleware.Context) {
c.JSON(200, dto)
}
// POST /api/preferences/set-home-dash
func SetHomeDashboard(c *middleware.Context, cmd m.SavePreferencesCommand) Response {
cmd.UserId = c.UserId
cmd.OrgId = c.OrgId
if err := bus.Dispatch(&cmd); err != nil {
return ApiError(500, "Failed to set home dashboard", err)
}
return ApiSuccess("Home dashboard set")
}
......@@ -39,7 +39,7 @@ type SavePreferencesCommand struct {
UserId int64
OrgId int64
HomeDashboardId int64
Timezone string
Theme string
HomeDashboardId int64 `json:"dashboardId"`
Timezone string `json:"timezone"`
Theme string `json:"theme"`
}
package sqlstore
import (
"time"
"github.com/grafana/grafana/pkg/bus"
m "github.com/grafana/grafana/pkg/models"
)
......@@ -41,6 +42,8 @@ func SavePreferences(cmd *m.SavePreferencesCommand) error {
HomeDashboardId: cmd.HomeDashboardId,
Timezone: cmd.Timezone,
Theme: cmd.Theme,
Created: time.Now(),
Updated: time.Now(),
}
_, err = sess.Insert(&prefs)
return err
......@@ -48,6 +51,8 @@ func SavePreferences(cmd *m.SavePreferencesCommand) error {
prefs.HomeDashboardId = cmd.HomeDashboardId
prefs.Timezone = cmd.Timezone
prefs.Theme = cmd.Theme
prefs.Updated = time.Now()
prefs.Version += 1
_, err = sess.Id(prefs.Id).Update(&prefs)
return err
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment