|
|
|
|
@ -3,84 +3,87 @@ package api |
|
|
|
|
import ( |
|
|
|
|
"github.com/grafana/grafana/pkg/api/dtos" |
|
|
|
|
"github.com/grafana/grafana/pkg/middleware" |
|
|
|
|
m "github.com/grafana/grafana/pkg/models" |
|
|
|
|
"github.com/grafana/grafana/pkg/plugins" |
|
|
|
|
"github.com/grafana/grafana/pkg/setting" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func setIndexViewData(c *middleware.Context) error { |
|
|
|
|
func setIndexViewData(c *middleware.Context) (*dtos.IndexViewData, error) { |
|
|
|
|
settings, err := getFrontendSettingsMap(c) |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
currentUser := &dtos.CurrentUser{ |
|
|
|
|
Id: c.UserId, |
|
|
|
|
IsSignedIn: c.IsSignedIn, |
|
|
|
|
Login: c.Login, |
|
|
|
|
Email: c.Email, |
|
|
|
|
Name: c.Name, |
|
|
|
|
LightTheme: c.Theme == "light", |
|
|
|
|
OrgId: c.OrgId, |
|
|
|
|
OrgName: c.OrgName, |
|
|
|
|
OrgRole: c.OrgRole, |
|
|
|
|
GravatarUrl: dtos.GetGravatarUrl(c.Email), |
|
|
|
|
IsGrafanaAdmin: c.IsGrafanaAdmin, |
|
|
|
|
var data = dtos.IndexViewData{ |
|
|
|
|
User: &dtos.CurrentUser{ |
|
|
|
|
Id: c.UserId, |
|
|
|
|
IsSignedIn: c.IsSignedIn, |
|
|
|
|
Login: c.Login, |
|
|
|
|
Email: c.Email, |
|
|
|
|
Name: c.Name, |
|
|
|
|
LightTheme: c.Theme == "light", |
|
|
|
|
OrgId: c.OrgId, |
|
|
|
|
OrgName: c.OrgName, |
|
|
|
|
OrgRole: c.OrgRole, |
|
|
|
|
GravatarUrl: dtos.GetGravatarUrl(c.Email), |
|
|
|
|
IsGrafanaAdmin: c.IsGrafanaAdmin, |
|
|
|
|
}, |
|
|
|
|
Settings: settings, |
|
|
|
|
AppUrl: setting.AppUrl, |
|
|
|
|
AppSubUrl: setting.AppSubUrl, |
|
|
|
|
GoogleAnalyticsId: setting.GoogleAnalyticsId, |
|
|
|
|
GoogleTagManagerId: setting.GoogleTagManagerId, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if setting.DisableGravatar { |
|
|
|
|
currentUser.GravatarUrl = setting.AppSubUrl + "/img/user_profile.png" |
|
|
|
|
data.User.GravatarUrl = setting.AppSubUrl + "/img/user_profile.png" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if len(currentUser.Name) == 0 { |
|
|
|
|
currentUser.Name = currentUser.Login |
|
|
|
|
if len(data.User.Name) == 0 { |
|
|
|
|
data.User.Name = data.User.Login |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
themeUrlParam := c.Query("theme") |
|
|
|
|
if themeUrlParam == "light" { |
|
|
|
|
currentUser.LightTheme = true |
|
|
|
|
data.User.LightTheme = true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
c.Data["User"] = currentUser |
|
|
|
|
c.Data["Settings"] = settings |
|
|
|
|
c.Data["AppUrl"] = setting.AppUrl |
|
|
|
|
c.Data["AppSubUrl"] = setting.AppSubUrl |
|
|
|
|
|
|
|
|
|
if setting.GoogleAnalyticsId != "" { |
|
|
|
|
c.Data["GoogleAnalyticsId"] = setting.GoogleAnalyticsId |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if setting.GoogleTagManagerId != "" { |
|
|
|
|
c.Data["GoogleTagManagerId"] = setting.GoogleTagManagerId |
|
|
|
|
data.MainNavLinks = append(data.MainNavLinks, &dtos.NavLink{ |
|
|
|
|
Text: "Dashboards", |
|
|
|
|
Icon: "fa fa-fw fa-th-large", |
|
|
|
|
Href: "/", |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
if c.OrgRole == m.ROLE_ADMIN { |
|
|
|
|
data.MainNavLinks = append(data.MainNavLinks, &dtos.NavLink{ |
|
|
|
|
Text: "Data Sources", |
|
|
|
|
Icon: "fa fa-fw fa-database", |
|
|
|
|
Href: "/datasources", |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
externalPluginJs := make([]string, 0) |
|
|
|
|
externalPluginCss := make([]string, 0) |
|
|
|
|
externalPluginMenu := make([]*plugins.ExternalPluginMenuItem, 0) |
|
|
|
|
for _, plugin := range plugins.ExternalPlugins { |
|
|
|
|
for _, js := range plugin.Js { |
|
|
|
|
externalPluginJs = append(externalPluginJs, js.Module) |
|
|
|
|
data.PluginJs = append(data.PluginJs, js.Module) |
|
|
|
|
} |
|
|
|
|
for _, css := range plugin.Css { |
|
|
|
|
externalPluginCss = append(externalPluginCss, css.Href) |
|
|
|
|
data.PluginCss = append(data.PluginCss, css.Href) |
|
|
|
|
} |
|
|
|
|
for _, item := range plugin.MenuItems { |
|
|
|
|
externalPluginMenu = append(externalPluginMenu, item) |
|
|
|
|
for _, item := range plugin.MainNavLinks { |
|
|
|
|
data.MainNavLinks = append(data.MainNavLinks, &dtos.NavLink{Text: item.Text, Href: item.Href, Icon: item.Icon}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
c.Data["ExternalPluginJs"] = externalPluginJs |
|
|
|
|
c.Data["ExternalPluginCss"] = externalPluginCss |
|
|
|
|
c.Data["ExternalPluginMenu"] = externalPluginMenu |
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
return &data, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func Index(c *middleware.Context) { |
|
|
|
|
if err := setIndexViewData(c); err != nil { |
|
|
|
|
if data, err := setIndexViewData(c); err != nil { |
|
|
|
|
c.Handle(500, "Failed to get settings", err) |
|
|
|
|
return |
|
|
|
|
} else { |
|
|
|
|
c.HTML(200, "index", data) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
c.HTML(200, "index") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func NotFoundHandler(c *middleware.Context) { |
|
|
|
|
@ -89,10 +92,10 @@ func NotFoundHandler(c *middleware.Context) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if err := setIndexViewData(c); err != nil { |
|
|
|
|
if data, err := setIndexViewData(c); err != nil { |
|
|
|
|
c.Handle(500, "Failed to get settings", err) |
|
|
|
|
return |
|
|
|
|
} else { |
|
|
|
|
c.HTML(404, "index", data) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
c.HTML(404, "index") |
|
|
|
|
} |
|
|
|
|
|