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-20 16:51:22 -06:00
|
|
|
data.User.GravatarUrl = setting.AppSubUrl + "/public/img/transparent.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-22 14:51:31 -06:00
|
|
|
{Text: "Home", Url: setting.AppSubUrl + "/"},
|
|
|
|
{Text: "Playlists", Url: setting.AppSubUrl + "/playlists"},
|
|
|
|
{Text: "Snapshots", Url: setting.AppSubUrl + "/dashboard/snapshots"},
|
|
|
|
{Divider: true},
|
|
|
|
{Text: "New", Url: setting.AppSubUrl + "/dashboard/new"},
|
|
|
|
{Text: "Import", Url: setting.AppSubUrl + "/import/dashboard"},
|
2016-02-11 14:23:54 -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-25 08:56:28 -06:00
|
|
|
Url: setting.AppSubUrl + "/plugins",
|
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-29 05:37:35 -06:00
|
|
|
Url: setting.AppSubUrl + "/plugins/" + 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 {
|
2016-03-01 04:07:51 -06:00
|
|
|
if !page.SuppressNav {
|
|
|
|
pageLink.Children = append(pageLink.Children, &dtos.NavLink{
|
|
|
|
Url: setting.AppSubUrl + "/plugins/" + plugin.Id + "/page/" + page.Slug,
|
|
|
|
Text: page.Name,
|
|
|
|
})
|
|
|
|
}
|
2016-02-09 07:06:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2016-02-14 10:37:05 -06:00
|
|
|
if c.IsGrafanaAdmin {
|
|
|
|
data.MainNavLinks = append(data.MainNavLinks, &dtos.NavLink{
|
|
|
|
Text: "Admin",
|
|
|
|
Icon: "fa fa-fw fa-cogs",
|
|
|
|
Url: setting.AppSubUrl + "/admin",
|
2016-02-19 21:00:29 -06:00
|
|
|
Children: []*dtos.NavLink{
|
|
|
|
{Text: "Global Users", Icon: "fa fa-fw fa-cogs", Url: setting.AppSubUrl + "/admin/users"},
|
|
|
|
{Text: "Global Orgs", Icon: "fa fa-fw fa-cogs", Url: setting.AppSubUrl + "/admin/orgs"},
|
|
|
|
{Text: "Server Settings", Icon: "fa fa-fw fa-cogs", Url: setting.AppSubUrl + "/admin/settings"},
|
|
|
|
{Text: "Server Stats", Icon: "fa-fw fa-cogs", Url: setting.AppSubUrl + "/admin/stats"},
|
2016-02-20 11:31:09 -06:00
|
|
|
},
|
2016-02-14 10:37:05 -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
|
|
|
}
|
|
|
|
}
|