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{
|
2015-08-21 02:30:39 -05:00
|
|
|
Id: c.UserId,
|
2015-01-29 05:10:34 -06:00
|
|
|
IsSignedIn: c.IsSignedIn,
|
|
|
|
Login: c.Login,
|
|
|
|
Email: c.Email,
|
|
|
|
Name: c.Name,
|
2015-02-28 07:30:08 -06:00
|
|
|
LightTheme: c.Theme == "light",
|
2015-04-29 02:26:12 -05:00
|
|
|
OrgId: c.OrgId,
|
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-05-01 01:40:13 -05:00
|
|
|
if setting.DisableGravatar {
|
|
|
|
currentUser.GravatarUrl = setting.AppSubUrl + "/img/user_profile.png"
|
|
|
|
}
|
|
|
|
|
2015-02-03 03:46:52 -06:00
|
|
|
if len(currentUser.Name) == 0 {
|
|
|
|
currentUser.Name = currentUser.Login
|
|
|
|
}
|
|
|
|
|
2015-04-02 02:21:38 -05:00
|
|
|
themeUrlParam := c.Query("theme")
|
|
|
|
if themeUrlParam == "light" {
|
|
|
|
currentUser.LightTheme = true
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2015-03-27 11:13:44 -05:00
|
|
|
if setting.GoogleAnalyticsId != "" {
|
|
|
|
c.Data["GoogleAnalyticsId"] = setting.GoogleAnalyticsId
|
|
|
|
}
|
|
|
|
|
2015-08-21 02:30:39 -05:00
|
|
|
if setting.GoogleTagManagerId != "" {
|
|
|
|
c.Data["GoogleTagManagerId"] = setting.GoogleTagManagerId
|
|
|
|
}
|
|
|
|
|
2015-01-29 05:10:34 -06:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
2015-05-18 10:28:15 -05:00
|
|
|
func NotFoundHandler(c *middleware.Context) {
|
2015-01-29 05:10:34 -06:00
|
|
|
if c.IsApiRequest() {
|
2015-03-22 14:14:00 -05:00
|
|
|
c.JsonApiErr(404, "Not found", nil)
|
2015-01-29 05:10:34 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := setIndexViewData(c); err != nil {
|
|
|
|
c.Handle(500, "Failed to get settings", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
c.HTML(404, "index")
|
|
|
|
}
|