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"
|
2015-11-20 02:43:10 -06:00
|
|
|
m "github.com/grafana/grafana/pkg/models"
|
2015-10-06 04:20:50 -05:00
|
|
|
"github.com/grafana/grafana/pkg/plugins"
|
2015-02-05 03:37:13 -06:00
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
2015-01-29 05:10:34 -06:00
|
|
|
)
|
|
|
|
|
2015-11-20 02:43:10 -06:00
|
|
|
func setIndexViewData(c *middleware.Context) (*dtos.IndexViewData, error) {
|
2015-02-18 07:06:44 -06:00
|
|
|
settings, err := getFrontendSettingsMap(c)
|
2015-01-29 05:10:34 -06:00
|
|
|
if err != nil {
|
2015-11-20 02:43:10 -06:00
|
|
|
return nil, err
|
2015-01-29 05:10:34 -06:00
|
|
|
}
|
|
|
|
|
2015-11-20 02:43:10 -06:00
|
|
|
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,
|
2015-01-29 05:10:34 -06:00
|
|
|
}
|
|
|
|
|
2015-05-01 01:40:13 -05:00
|
|
|
if setting.DisableGravatar {
|
2016-02-08 09:57:29 -06:00
|
|
|
data.User.GravatarUrl = setting.AppSubUrl + "/public/img/user_profile.png"
|
2015-05-01 01:40:13 -05:00
|
|
|
}
|
|
|
|
|
2015-11-20 02:43:10 -06:00
|
|
|
if len(data.User.Name) == 0 {
|
|
|
|
data.User.Name = data.User.Login
|
2015-02-03 03:46:52 -06:00
|
|
|
}
|
|
|
|
|
2015-04-02 02:21:38 -05:00
|
|
|
themeUrlParam := c.Query("theme")
|
|
|
|
if themeUrlParam == "light" {
|
2015-11-20 02:43:10 -06:00
|
|
|
data.User.LightTheme = true
|
2015-04-02 02:21:38 -05:00
|
|
|
}
|
|
|
|
|
2015-11-20 02:43:10 -06:00
|
|
|
data.MainNavLinks = append(data.MainNavLinks, &dtos.NavLink{
|
|
|
|
Text: "Dashboards",
|
2016-02-11 08:53:48 -06:00
|
|
|
Icon: "icon-gf icon-gf-dashboard",
|
2016-02-09 07:06:23 -06:00
|
|
|
Url: setting.AppSubUrl + "/",
|
2016-02-11 14:23:54 -06:00
|
|
|
Children: []*dtos.NavLink{
|
2016-02-12 04:21:42 -06:00
|
|
|
{Text: "Home dashboard", Icon: "fa fa-fw fa-list", Url: setting.AppSubUrl + "/"},
|
2016-02-11 14:23:54 -06:00
|
|
|
{Text: "Playlists", Icon: "fa fa-fw fa-list", Url: setting.AppSubUrl + "/playlists"},
|
|
|
|
{Text: "Snapshots", Icon: "fa-fw icon-gf icon-gf-snapshot", Url: setting.AppSubUrl + "/dashboard/snapshots"},
|
|
|
|
},
|
2015-11-20 02:43:10 -06:00
|
|
|
})
|
|
|
|
|
2016-02-11 14:23:54 -06:00
|
|
|
// data.MainNavLinks = append(data.MainNavLinks, &dtos.NavLink{Text: "Playlists", Icon: "fa fa-fw fa-list", Url: setting.AppSubUrl + "/playlists"})
|
|
|
|
// data.MainNavLinks = append(data.MainNavLinks, &dtos.NavLink{Text: "Snapshots", Icon: "fa-fw icon-gf icon-gf-snapshot", Url: setting.AppSubUrl + "/dashboard/snapshots"})
|
2016-02-09 07:20:41 -06:00
|
|
|
|
2015-11-20 02:43:10 -06:00
|
|
|
if c.OrgRole == m.ROLE_ADMIN {
|
|
|
|
data.MainNavLinks = append(data.MainNavLinks, &dtos.NavLink{
|
|
|
|
Text: "Data Sources",
|
2016-02-11 08:53:48 -06:00
|
|
|
Icon: "icon-gf icon-gf-datasources",
|
2016-02-09 07:06:23 -06:00
|
|
|
Url: setting.AppSubUrl + "/datasources",
|
2015-11-20 02:43:10 -06:00
|
|
|
})
|
2016-01-08 05:45:12 -06:00
|
|
|
|
|
|
|
data.MainNavLinks = append(data.MainNavLinks, &dtos.NavLink{
|
2016-02-11 08:53:48 -06:00
|
|
|
Text: "Plugins",
|
|
|
|
Icon: "icon-gf icon-gf-apps",
|
2016-02-09 07:06:23 -06:00
|
|
|
Url: setting.AppSubUrl + "/apps",
|
2016-01-08 05:45:12 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-01-10 14:37:11 -06:00
|
|
|
enabledPlugins, err := plugins.GetEnabledPlugins(c.OrgId)
|
2015-12-03 09:43:55 -06:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-12-21 16:09:27 -06:00
|
|
|
|
|
|
|
for _, plugin := range enabledPlugins.Apps {
|
2016-01-11 11:03:08 -06:00
|
|
|
if plugin.Pinned {
|
2016-02-09 07:06:23 -06:00
|
|
|
pageLink := &dtos.NavLink{
|
2016-01-11 11:03:08 -06:00
|
|
|
Text: plugin.Name,
|
2016-02-09 07:06:23 -06:00
|
|
|
Url: setting.AppSubUrl + "/apps/" + plugin.Id + "/edit",
|
2016-01-11 11:03:08 -06:00
|
|
|
Img: plugin.Info.Logos.Small,
|
2016-02-09 07:06:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, page := range plugin.Pages {
|
|
|
|
pageLink.Children = append(pageLink.Children, &dtos.NavLink{
|
|
|
|
Url: setting.AppSubUrl + "/apps/" + plugin.Id + "/page/" + page.Slug,
|
|
|
|
Text: page.Name,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
data.MainNavLinks = append(data.MainNavLinks, pageLink)
|
2015-10-06 04:20:50 -05:00
|
|
|
}
|
2015-08-21 02:30:39 -05:00
|
|
|
}
|
2015-11-11 00:30:07 -06:00
|
|
|
|
2015-11-20 02:43:10 -06:00
|
|
|
return &data, nil
|
2015-01-29 05:10:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func Index(c *middleware.Context) {
|
2015-11-20 02:43:10 -06:00
|
|
|
if data, err := setIndexViewData(c); err != nil {
|
2015-01-29 05:10:34 -06:00
|
|
|
c.Handle(500, "Failed to get settings", err)
|
|
|
|
return
|
2015-11-20 02:43:10 -06:00
|
|
|
} else {
|
|
|
|
c.HTML(200, "index", data)
|
2015-01-29 05:10:34 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2015-11-20 02:43:10 -06:00
|
|
|
if data, err := setIndexViewData(c); err != nil {
|
2015-01-29 05:10:34 -06:00
|
|
|
c.Handle(500, "Failed to get settings", err)
|
|
|
|
return
|
2015-11-20 02:43:10 -06:00
|
|
|
} else {
|
|
|
|
c.HTML(404, "index", data)
|
2015-01-29 05:10:34 -06:00
|
|
|
}
|
|
|
|
}
|