2015-01-29 05:10:34 -06:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2015-02-05 03:37:13 -06:00
|
|
|
"github.com/grafana/grafana/pkg/api/dtos"
|
|
|
|
"github.com/grafana/grafana/pkg/middleware"
|
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
2015-01-29 05:10:34 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func setIndexViewData(c *middleware.Context) error {
|
2015-02-18 07:06:44 -06:00
|
|
|
settings, err := getFrontendSettingsMap(c)
|
2015-01-29 05:10:34 -06:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
currentUser := &dtos.CurrentUser{
|
|
|
|
IsSignedIn: c.IsSignedIn,
|
|
|
|
Login: c.Login,
|
|
|
|
Email: c.Email,
|
|
|
|
Name: c.Name,
|
2015-02-23 13:07:49 -06:00
|
|
|
OrgName: c.OrgName,
|
|
|
|
OrgRole: c.OrgRole,
|
2015-01-29 05:10:34 -06:00
|
|
|
GravatarUrl: dtos.GetGravatarUrl(c.Email),
|
|
|
|
IsGrafanaAdmin: c.IsGrafanaAdmin,
|
|
|
|
}
|
|
|
|
|
2015-02-03 03:46:52 -06:00
|
|
|
if len(currentUser.Name) == 0 {
|
|
|
|
currentUser.Name = currentUser.Login
|
|
|
|
}
|
|
|
|
|
2015-01-29 05:10:34 -06:00
|
|
|
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")
|
|
|
|
}
|