mirror of
https://github.com/grafana/grafana.git
synced 2025-02-03 20:21:01 -06:00
Trying a different approach to providing frontend settings
This commit is contained in:
parent
a55a606a55
commit
f3132b4513
2
grafana
2
grafana
@ -1 +1 @@
|
||||
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")
|
||||
}
|
||||
|
||||
|
61
pkg/api/api_frontendsettings.go
Normal file
61
pkg/api/api_frontendsettings.go
Normal file
@ -0,0 +1,61 @@
|
||||
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>
|
||||
|
Loading…
Reference in New Issue
Block a user