Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
ec98c201
Commit
ec98c201
authored
Dec 28, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Datasource options are now included in bootData
parent
f3132b45
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
15 additions
and
112 deletions
+15
-112
grafana
+1
-1
pkg/api/api.go
+1
-4
pkg/api/api_config.go
+0
-99
pkg/api/api_frontendsettings.go
+13
-6
pkg/middleware/middleware.go
+0
-2
No files found.
grafana
@
47f226be
Subproject commit
cfabccc5f29579680dcd186307c431945900c7ce
Subproject commit
47f226be3b480e037692f30a320c6fcff2b9e01c
pkg/api/api.go
View file @
ec98c201
...
@@ -46,15 +46,12 @@ func Register(m *macaron.Macaron) {
...
@@ -46,15 +46,12 @@ func Register(m *macaron.Macaron) {
m
.
Post
(
"/api/dashboard/"
,
auth
,
PostDashboard
)
m
.
Post
(
"/api/dashboard/"
,
auth
,
PostDashboard
)
m
.
Delete
(
"/api/dashboard/:slug"
,
auth
,
DeleteDashboard
)
m
.
Delete
(
"/api/dashboard/:slug"
,
auth
,
DeleteDashboard
)
// frontend config
m
.
Get
(
"/frontend/config"
,
auth
,
GetConfigJS
)
// rendering
// rendering
m
.
Get
(
"/render/*"
,
auth
,
RenderToPng
)
m
.
Get
(
"/render/*"
,
auth
,
RenderToPng
)
}
}
func
Index
(
ctx
*
middleware
.
Context
)
{
func
Index
(
ctx
*
middleware
.
Context
)
{
settings
,
err
:=
getFrontendSettings
(
ctx
.
GetAccountId
()
)
settings
,
err
:=
getFrontendSettings
(
ctx
)
if
err
!=
nil
{
if
err
!=
nil
{
ctx
.
Handle
(
500
,
"Failed to get settings"
,
err
)
ctx
.
Handle
(
500
,
"Failed to get settings"
,
err
)
return
return
...
...
pkg/api/api_config.go
deleted
100644 → 0
View file @
f3132b45
package
api
import
(
"encoding/json"
"strconv"
"strings"
"github.com/torkelo/grafana-pro/pkg/bus"
"github.com/torkelo/grafana-pro/pkg/middleware"
m
"github.com/torkelo/grafana-pro/pkg/models"
)
const
configTemplate
=
`
define(['settings'],
function (Settings) {
"use strict";
return new Settings(%json%);
});
`
type
configJsTmplModel
struct
{
DataSources
[]
*
m
.
DataSource
}
// TODO: cleanup this ugly code
func
renderConfig
(
data
*
configJsTmplModel
)
string
{
datasources
:=
make
(
map
[
string
]
interface
{})
for
i
,
ds
:=
range
data
.
DataSources
{
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
,
}
buff
,
_
:=
json
.
Marshal
(
jsonObj
)
return
strings
.
Replace
(
configTemplate
,
"%json%"
,
string
(
buff
),
1
)
}
func
GetConfigJS
(
c
*
middleware
.
Context
)
{
query
:=
m
.
GetDataSourcesQuery
{
AccountId
:
c
.
GetAccountId
()}
err
:=
bus
.
Dispatch
(
&
query
)
if
err
!=
nil
{
c
.
Handle
(
500
,
"cold not load data sources"
,
err
)
return
}
vm
:=
configJsTmplModel
{
DataSources
:
query
.
Result
}
configStr
:=
renderConfig
(
&
vm
)
if
err
!=
nil
{
c
.
Handle
(
500
,
"Failed to generate config.js"
,
err
)
return
}
c
.
Header
()
.
Set
(
"Content-Type"
,
"text/javascript; charset=UTF-8"
)
c
.
Header
()
.
Set
(
"Cache-Control"
,
"no-cache, no-store, must-revalidate"
)
c
.
Header
()
.
Set
(
"Pragma"
,
"no-cache"
)
c
.
Header
()
.
Set
(
"Expires"
,
"0"
)
c
.
WriteHeader
(
200
)
c
.
Write
([]
byte
(
configStr
))
}
pkg/api/api_frontendsettings.go
View file @
ec98c201
...
@@ -4,20 +4,27 @@ import (
...
@@ -4,20 +4,27 @@ import (
"strconv"
"strconv"
"github.com/torkelo/grafana-pro/pkg/bus"
"github.com/torkelo/grafana-pro/pkg/bus"
"github.com/torkelo/grafana-pro/pkg/middleware"
m
"github.com/torkelo/grafana-pro/pkg/models"
m
"github.com/torkelo/grafana-pro/pkg/models"
)
)
func
getFrontendSettings
(
accountId
int64
)
(
map
[
string
]
interface
{},
error
)
{
func
getFrontendSettings
(
c
*
middleware
.
Context
)
(
map
[
string
]
interface
{},
error
)
{
query
:=
m
.
GetDataSourcesQuery
{
AccountId
:
accountId
}
accountDataSources
:=
make
([]
*
m
.
DataSource
,
0
)
err
:=
bus
.
Dispatch
(
&
query
)
if
err
!=
nil
{
if
c
.
Account
!=
nil
{
return
nil
,
err
query
:=
m
.
GetDataSourcesQuery
{
AccountId
:
c
.
Account
.
Id
}
err
:=
bus
.
Dispatch
(
&
query
)
if
err
!=
nil
{
return
nil
,
err
}
accountDataSources
=
query
.
Result
}
}
datasources
:=
make
(
map
[
string
]
interface
{})
datasources
:=
make
(
map
[
string
]
interface
{})
for
i
,
ds
:=
range
query
.
Result
{
for
i
,
ds
:=
range
accountDataSources
{
url
:=
ds
.
Url
url
:=
ds
.
Url
if
ds
.
Access
==
m
.
DS_ACCESS_PROXY
{
if
ds
.
Access
==
m
.
DS_ACCESS_PROXY
{
...
...
pkg/middleware/middleware.go
View file @
ec98c201
...
@@ -18,8 +18,6 @@ type Context struct {
...
@@ -18,8 +18,6 @@ type Context struct {
Account
*
models
.
Account
Account
*
models
.
Account
UserAccount
*
models
.
Account
UserAccount
*
models
.
Account
IsSigned
bool
}
}
func
(
c
*
Context
)
GetAccountId
()
int64
{
func
(
c
*
Context
)
GetAccountId
()
int64
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment