Commit f3132b45 by Torkel Ödegaard

Trying a different approach to providing frontend settings

parent a55a606a
Subproject commit dede578c7d569f87c35724f74a72216743bf9508
Subproject commit cfabccc5f29579680dcd186307c431945900c7ce
......@@ -54,7 +54,14 @@ func Register(m *macaron.Macaron) {
}
func Index(ctx *middleware.Context) {
ctx.Data["User"] = dtos.NewCurrentUser(ctx.UserAccount)
settings, err := getFrontendSettings(ctx.GetAccountId())
if err != nil {
ctx.Handle(500, "Failed to get settings", err)
return
}
ctx.Data["user"] = dtos.NewCurrentUser(ctx.UserAccount)
ctx.Data["settings"] = settings
ctx.HTML(200, "index")
}
......
package api
import (
"strconv"
"github.com/torkelo/grafana-pro/pkg/bus"
m "github.com/torkelo/grafana-pro/pkg/models"
)
func getFrontendSettings(accountId int64) (map[string]interface{}, error) {
query := m.GetDataSourcesQuery{AccountId: accountId}
err := bus.Dispatch(&query)
if err != nil {
return nil, err
}
datasources := make(map[string]interface{})
for i, ds := range query.Result {
url := ds.Url
if ds.Access == m.DS_ACCESS_PROXY {
url = "/api/datasources/proxy/" + strconv.FormatInt(ds.Id, 10)
}
var dsMap = map[string]interface{}{
"type": ds.Type,
"url": url,
}
if ds.Type == m.DS_INFLUXDB {
if ds.Access == m.DS_ACCESS_DIRECT {
dsMap["username"] = ds.User
dsMap["password"] = ds.Password
dsMap["url"] = url + "/db/" + ds.Database
}
}
// temp hack, first is always default
// TODO: implement default ds account setting
if i == 0 {
dsMap["default"] = true
}
datasources[ds.Name] = dsMap
}
// add grafana backend data source
datasources["grafana"] = map[string]interface{}{
"type": "grafana",
"url": "",
"grafanaDB": true,
}
jsonObj := map[string]interface{}{
"datasources": datasources,
}
return jsonObj, nil
}
......@@ -46,7 +46,8 @@
<script>
window.grafanaBootData = {
user:[[.User]]
user:[[.user]],
settings: [[.settings]]
};
</script>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment