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
d69258e2
Commit
d69258e2
authored
Dec 18, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backend can now generate config.js, the very basic stuff, more work needed
parent
ce947d47
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
79 additions
and
49 deletions
+79
-49
grafana
+1
-1
pkg/api/api.go
+3
-0
pkg/api/api_account.go
+2
-3
pkg/api/api_config.go
+68
-0
pkg/configuration/configuration.go
+0
-40
pkg/models/datasource.go
+5
-5
No files found.
grafana
@
4e542d8b
Subproject commit
ad91093902bdfc0d2a87bb362a76a9057aef4361
Subproject commit
4e542d8b83844f8faa4d5ae3edab593950aaa344
pkg/api/api.go
View file @
d69258e2
...
...
@@ -43,6 +43,9 @@ func Register(m *macaron.Macaron) {
m
.
Post
(
"/api/dashboard/"
,
auth
,
PostDashboard
)
m
.
Delete
(
"/api/dashboard/:slug"
,
auth
,
DeleteDashboard
)
// frontend config
m
.
Get
(
"/frontend/config"
,
auth
,
GetConfigJS
)
// rendering
m
.
Get
(
"/render/*"
,
auth
,
RenderToPng
)
}
...
...
pkg/api/api_account.go
View file @
d69258e2
package
api
import
(
"github.com/gin-gonic/gin"
"github.com/torkelo/grafana-pro/pkg/api/dtos"
"github.com/torkelo/grafana-pro/pkg/middleware"
"github.com/torkelo/grafana-pro/pkg/models"
...
...
@@ -96,7 +95,7 @@ func SetUsingAccount(c *middleware.Context) {
otherAccounts
,
err
:=
models
.
GetOtherAccountsFor
(
c
.
UserAccount
.
Id
)
if
err
!=
nil
{
c
.
JSON
(
500
,
gin
.
H
{
"message"
:
err
.
Error
()})
c
.
JSON
(
500
,
utils
.
DynMap
{
"message"
:
err
.
Error
()})
return
}
...
...
@@ -116,7 +115,7 @@ func SetUsingAccount(c *middleware.Context) {
account
.
UsingAccountId
=
usingAccountId
err
=
models
.
SaveAccount
(
account
)
if
err
!=
nil
{
c
.
JSON
(
500
,
gin
.
H
{
"message"
:
err
.
Error
()})
c
.
JSON
(
500
,
utils
.
DynMap
{
"message"
:
err
.
Error
()})
return
}
...
...
pkg/api/api_config.go
0 → 100644
View file @
d69258e2
package
api
import
(
"encoding/json"
"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
}
func
renderConfig
(
data
*
configJsTmplModel
)
string
{
datasources
:=
make
(
map
[
string
]
interface
{})
for
_
,
ds
:=
range
data
.
DataSources
{
datasources
[
ds
.
Name
]
=
map
[
string
]
interface
{}{
"type"
:
ds
.
Type
,
"url"
:
ds
.
Url
,
}
}
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/configuration/configuration.go
deleted
100644 → 0
View file @
ce947d47
package
configuration
type
Cfg
struct
{
Http
HttpCfg
}
type
HttpCfg
struct
{
Port
string
GoogleOAuth
OAuthCfg
GithubOAuth
OAuthCfg
}
type
OAuthCfg
struct
{
Enabled
bool
ClientId
string
ClientSecret
string
}
type
DashboardSourceCfg
struct
{
sourceType
string
path
string
}
func
NewCfg
(
port
string
)
*
Cfg
{
return
&
Cfg
{
Http
:
HttpCfg
{
Port
:
port
,
GoogleOAuth
:
OAuthCfg
{
Enabled
:
true
,
ClientId
:
"106011922963-4pvl05e9urtrm8bbqr0vouosj3e8p8kb.apps.googleusercontent.com"
,
ClientSecret
:
"K2evIa4QhfbhhAm3SO72t2Zv"
,
},
GithubOAuth
:
OAuthCfg
{
Enabled
:
true
,
ClientId
:
"de054205006b9baa2e17"
,
ClientSecret
:
"72b7ea52d9f1096fdf36cea95e95362a307e0322"
,
},
},
}
}
pkg/models/datasource.go
View file @
d69258e2
...
...
@@ -3,11 +3,11 @@ package models
import
"time"
const
(
DS_GRAPHITE
=
"
GRAPHITE
"
DS_INFLUXDB
=
"
INFLUXDB
"
DS_ES
=
"
ES
"
DS_ACCESS_DIRECT
=
"
DIRECT
"
DS_ACCESS_PROXY
=
"
PROXY
"
DS_GRAPHITE
=
"
graphite
"
DS_INFLUXDB
=
"
influxdb
"
DS_ES
=
"
es
"
DS_ACCESS_DIRECT
=
"
direct
"
DS_ACCESS_PROXY
=
"
proxy
"
)
type
DsType
string
...
...
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