More work on backend for user favorites

This commit is contained in:
Torkel Ödegaard
2015-01-29 12:10:34 +01:00
parent e02e60171e
commit 1d6413bfae
14 changed files with 138 additions and 59 deletions

View File

@@ -6,7 +6,6 @@ import (
"github.com/torkelo/grafana-pro/pkg/api/dtos"
"github.com/torkelo/grafana-pro/pkg/middleware"
m "github.com/torkelo/grafana-pro/pkg/models"
"github.com/torkelo/grafana-pro/pkg/setting"
)
// Register adds http routes
@@ -46,6 +45,8 @@ func Register(r *macaron.Macaron) {
r.Put("/", bind(m.UpdateUserCommand{}), UpdateUser)
r.Post("/using/:id", SetUsingAccount)
r.Get("/accounts", GetUserAccounts)
r.Post("/favorites/dashboard/:id", AddAsFavorite)
r.Delete("/favorites/dashboard/:id", RemoveAsFavorite)
})
// account
@@ -97,51 +98,3 @@ func Register(r *macaron.Macaron) {
r.NotFound(NotFound)
}
func setIndexViewData(c *middleware.Context) error {
settings, err := getFrontendSettings(c)
if err != nil {
return err
}
currentUser := &dtos.CurrentUser{
IsSignedIn: c.IsSignedIn,
Login: c.Login,
Email: c.Email,
Name: c.Name,
AccountName: c.AccountName,
AccountRole: c.AccountRole,
GravatarUrl: dtos.GetGravatarUrl(c.Email),
IsGrafanaAdmin: c.IsGrafanaAdmin,
}
c.Data["User"] = currentUser
c.Data["Settings"] = settings
c.Data["AppUrl"] = setting.AppUrl
c.Data["AppSubUrl"] = setting.AppSubUrl
return nil
}
func Index(c *middleware.Context) {
if err := setIndexViewData(c); err != nil {
c.Handle(500, "Failed to get settings", err)
return
}
c.HTML(200, "index")
}
func NotFound(c *middleware.Context) {
if c.IsApiRequest() {
c.JsonApiErr(200, "Not found", nil)
return
}
if err := setIndexViewData(c); err != nil {
c.Handle(500, "Failed to get settings", err)
return
}
c.HTML(404, "index")
}