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
eb2c0788
Commit
eb2c0788
authored
Nov 20, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Progres on move to sql from rethinkdb
parent
9b68911d
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
118 additions
and
62 deletions
+118
-62
grafana
+1
-1
pkg/cmd/web.go
+1
-2
pkg/middleware/auth.go
+2
-2
pkg/middleware/middleware.go
+1
-1
pkg/models/account.go
+16
-16
pkg/models/dashboards.go
+16
-13
pkg/routes/api/api_dashboard.go
+1
-1
pkg/routes/api/api_render.go
+1
-1
pkg/routes/index.go
+0
-3
pkg/routes/login/login_oauth.go
+2
-0
pkg/stores/sqlstore/sqlstore.go
+10
-8
pkg/stores/sqlstore/sqlstore_accounts.go
+29
-14
pkg/stores/sqlstore/sqlstore_dashboards.go
+38
-0
No files found.
grafana
@
4b5eadf7
Subproject commit
2423f470ef62145c26e74511121eac01e554c363
Subproject commit
4b5eadf7b59898e6622a75e0a57081103dd78b2a
pkg/cmd/web.go
View file @
eb2c0788
...
@@ -17,7 +17,6 @@ import (
...
@@ -17,7 +17,6 @@ import (
"github.com/torkelo/grafana-pro/pkg/routes"
"github.com/torkelo/grafana-pro/pkg/routes"
"github.com/torkelo/grafana-pro/pkg/setting"
"github.com/torkelo/grafana-pro/pkg/setting"
"github.com/torkelo/grafana-pro/pkg/social"
"github.com/torkelo/grafana-pro/pkg/social"
"github.com/torkelo/grafana-pro/pkg/stores/rethink"
"github.com/torkelo/grafana-pro/pkg/stores/sqlstore"
"github.com/torkelo/grafana-pro/pkg/stores/sqlstore"
)
)
...
@@ -66,7 +65,7 @@ func mapStatic(m *macaron.Macaron, dir string, prefix string) {
...
@@ -66,7 +65,7 @@ func mapStatic(m *macaron.Macaron, dir string, prefix string) {
func
runWeb
(
*
cli
.
Context
)
{
func
runWeb
(
*
cli
.
Context
)
{
setting
.
NewConfigContext
()
setting
.
NewConfigContext
()
setting
.
InitServices
()
setting
.
InitServices
()
rethink
.
Init
()
sqlstore
.
Init
()
social
.
NewOAuthService
()
social
.
NewOAuthService
()
// init database
// init database
...
...
pkg/middleware/auth.go
View file @
eb2c0788
...
@@ -9,7 +9,7 @@ import (
...
@@ -9,7 +9,7 @@ import (
"github.com/torkelo/grafana-pro/pkg/models"
"github.com/torkelo/grafana-pro/pkg/models"
)
)
func
authGetRequestAccountId
(
c
*
Context
,
sess
session
.
Store
)
(
int
,
error
)
{
func
authGetRequestAccountId
(
c
*
Context
,
sess
session
.
Store
)
(
int
64
,
error
)
{
accountId
:=
sess
.
Get
(
"accountId"
)
accountId
:=
sess
.
Get
(
"accountId"
)
urlQuery
:=
c
.
Req
.
URL
.
Query
()
urlQuery
:=
c
.
Req
.
URL
.
Query
()
...
@@ -23,7 +23,7 @@ func authGetRequestAccountId(c *Context, sess session.Store) (int, error) {
...
@@ -23,7 +23,7 @@ func authGetRequestAccountId(c *Context, sess session.Store) (int, error) {
return
-
1
,
errors
.
New
(
"Auth: session account id not found"
)
return
-
1
,
errors
.
New
(
"Auth: session account id not found"
)
}
}
return
accountId
.
(
int
),
nil
return
accountId
.
(
int
64
),
nil
}
}
func
authDenied
(
c
*
Context
)
{
func
authDenied
(
c
*
Context
)
{
...
...
pkg/middleware/middleware.go
View file @
eb2c0788
...
@@ -21,7 +21,7 @@ type Context struct {
...
@@ -21,7 +21,7 @@ type Context struct {
IsSigned
bool
IsSigned
bool
}
}
func
(
c
*
Context
)
GetAccountId
()
int
{
func
(
c
*
Context
)
GetAccountId
()
int
64
{
return
c
.
Account
.
Id
return
c
.
Account
.
Id
}
}
...
...
pkg/models/account.go
View file @
eb2c0788
...
@@ -9,8 +9,8 @@ var (
...
@@ -9,8 +9,8 @@ var (
CreateAccount
func
(
acccount
*
Account
)
error
CreateAccount
func
(
acccount
*
Account
)
error
UpdateAccount
func
(
acccount
*
Account
)
error
UpdateAccount
func
(
acccount
*
Account
)
error
GetAccountByLogin
func
(
emailOrName
string
)
(
*
Account
,
error
)
GetAccountByLogin
func
(
emailOrName
string
)
(
*
Account
,
error
)
GetAccount
func
(
accountId
int
)
(
*
Account
,
error
)
GetAccount
func
(
accountId
int
64
)
(
*
Account
,
error
)
GetOtherAccountsFor
func
(
accountId
int
)
([]
*
OtherAccount
,
error
)
GetOtherAccountsFor
func
(
accountId
int
64
)
([]
*
OtherAccount
,
error
)
)
)
// Typed errors
// Typed errors
...
@@ -19,7 +19,7 @@ var (
...
@@ -19,7 +19,7 @@ var (
)
)
type
CollaboratorLink
struct
{
type
CollaboratorLink
struct
{
AccountId
int
AccountId
int
64
Role
string
Role
string
Email
string
Email
string
ModifiedOn
time
.
Time
ModifiedOn
time
.
Time
...
@@ -33,20 +33,20 @@ type OtherAccount struct {
...
@@ -33,20 +33,20 @@ type OtherAccount struct {
}
}
type
Account
struct
{
type
Account
struct
{
Id
int
`gorethink:"id"`
Id
int
64
Version
int
Login
string
`xorm:"UNIQUE NOT NULL"`
Login
string
Email
string
`xorm:"UNIQUE NOT NULL"`
Email
string
Name
string
`xorm:"UNIQUE NOT NULL"`
AccountName
string
FullName
string
Password
string
Password
string
Name
string
IsAdmin
bool
Salt
string
`xorm:"VARCHAR(10)"`
Company
string
Company
string
NextDashboardId
int
NextDashboardId
int
UsingAccountId
int
UsingAccountId
int64
Collaborators
[]
CollaboratorLink
Collaborators
[]
CollaboratorLink
`xorm:"-"`
CreatedOn
time
.
Time
Created
time
.
Time
`xorm:"CREATED"`
ModifiedOn
time
.
Time
Updated
time
.
Time
`xorm:"UPDATED"`
LastLoginOn
time
.
Time
}
}
func
(
account
*
Account
)
AddCollaborator
(
newCollaborator
*
Account
)
error
{
func
(
account
*
Account
)
AddCollaborator
(
newCollaborator
*
Account
)
error
{
...
@@ -67,7 +67,7 @@ func (account *Account) AddCollaborator(newCollaborator *Account) error {
...
@@ -67,7 +67,7 @@ func (account *Account) AddCollaborator(newCollaborator *Account) error {
return
nil
return
nil
}
}
func
(
account
*
Account
)
RemoveCollaborator
(
accountId
int
)
{
func
(
account
*
Account
)
RemoveCollaborator
(
accountId
int
64
)
{
list
:=
account
.
Collaborators
list
:=
account
.
Collaborators
for
i
,
collaborator
:=
range
list
{
for
i
,
collaborator
:=
range
list
{
if
collaborator
.
AccountId
==
accountId
{
if
collaborator
.
AccountId
==
accountId
{
...
@@ -77,7 +77,7 @@ func (account *Account) RemoveCollaborator(accountId int) {
...
@@ -77,7 +77,7 @@ func (account *Account) RemoveCollaborator(accountId int) {
}
}
}
}
func
(
account
*
Account
)
HasCollaborator
(
accountId
int
)
bool
{
func
(
account
*
Account
)
HasCollaborator
(
accountId
int
64
)
bool
{
for
_
,
collaborator
:=
range
account
.
Collaborators
{
for
_
,
collaborator
:=
range
account
.
Collaborators
{
if
collaborator
.
AccountId
==
accountId
{
if
collaborator
.
AccountId
==
accountId
{
return
true
return
true
...
...
pkg/models/dashboards.go
View file @
eb2c0788
...
@@ -2,6 +2,7 @@ package models
...
@@ -2,6 +2,7 @@ package models
import
(
import
(
"encoding/json"
"encoding/json"
"errors"
"io"
"io"
"regexp"
"regexp"
"strings"
"strings"
...
@@ -9,19 +10,24 @@ import (
...
@@ -9,19 +10,24 @@ import (
)
)
var
(
var
(
GetDashboard
func
(
slug
string
,
accountId
int
)
(
*
Dashboard
,
error
)
GetDashboard
func
(
slug
string
,
accountId
int
64
)
(
*
Dashboard
,
error
)
SaveDashboard
func
(
dash
*
Dashboard
)
error
SaveDashboard
func
(
dash
*
Dashboard
)
error
DeleteDashboard
func
(
slug
string
,
accountId
int
)
error
DeleteDashboard
func
(
slug
string
,
accountId
int64
)
error
SearchQuery
func
(
query
string
,
acccountId
int
)
([]
*
SearchResult
,
error
)
SearchQuery
func
(
query
string
,
acccountId
int64
)
([]
*
SearchResult
,
error
)
)
// Typed errors
var
(
ErrDashboardNotFound
=
errors
.
New
(
"Account not found"
)
)
)
type
Dashboard
struct
{
type
Dashboard
struct
{
Id
string
`gorethink:"id,omitempty"`
Id
int64
Slug
string
Slug
string
`xorm:"index(IX_AccountIdSlug)"`
AccountId
int
AccountId
int64
`xorm:"index(IX_AccountIdSlug)"`
LastModifiedByUserId
string
LastModifiedByDate
time
.
Time
Created
time
.
Time
`xorm:"CREATED"`
CreatedDate
time
.
Time
Updated
time
.
Time
`xorm:"UPDATED"`
Title
string
Title
string
Tags
[]
string
Tags
[]
string
...
@@ -36,10 +42,7 @@ type SearchResult struct {
...
@@ -36,10 +42,7 @@ type SearchResult struct {
func
NewDashboard
(
title
string
)
*
Dashboard
{
func
NewDashboard
(
title
string
)
*
Dashboard
{
dash
:=
&
Dashboard
{}
dash
:=
&
Dashboard
{}
dash
.
Id
=
""
dash
.
Id
=
0
dash
.
LastModifiedByDate
=
time
.
Now
()
dash
.
CreatedDate
=
time
.
Now
()
dash
.
LastModifiedByUserId
=
"123"
dash
.
Data
=
make
(
map
[
string
]
interface
{})
dash
.
Data
=
make
(
map
[
string
]
interface
{})
dash
.
Data
[
"title"
]
=
title
dash
.
Data
[
"title"
]
=
title
dash
.
Title
=
title
dash
.
Title
=
title
...
...
pkg/routes/api/api_dashboard.go
View file @
eb2c0788
...
@@ -69,7 +69,7 @@ func PostDashboard(c *middleware.Context) {
...
@@ -69,7 +69,7 @@ func PostDashboard(c *middleware.Context) {
dashboard
.
UpdateSlug
()
dashboard
.
UpdateSlug
()
if
dashboard
.
Data
[
"id"
]
!=
nil
{
if
dashboard
.
Data
[
"id"
]
!=
nil
{
dashboard
.
Id
=
dashboard
.
Data
[
"id"
]
.
(
string
)
dashboard
.
Id
=
int64
(
dashboard
.
Data
[
"id"
]
.
(
float64
)
)
}
}
err
:=
models
.
SaveDashboard
(
dashboard
)
err
:=
models
.
SaveDashboard
(
dashboard
)
...
...
pkg/routes/api/api_render.go
View file @
eb2c0788
...
@@ -12,7 +12,7 @@ import (
...
@@ -12,7 +12,7 @@ import (
func
RenderToPng
(
c
*
middleware
.
Context
)
{
func
RenderToPng
(
c
*
middleware
.
Context
)
{
accountId
:=
c
.
GetAccountId
()
accountId
:=
c
.
GetAccountId
()
queryReader
:=
utils
.
NewUrlQueryReader
(
c
.
Req
.
URL
)
queryReader
:=
utils
.
NewUrlQueryReader
(
c
.
Req
.
URL
)
queryParams
:=
"?render&accountId="
+
strconv
.
Itoa
(
accountId
)
+
"&"
+
c
.
Req
.
URL
.
RawQuery
queryParams
:=
"?render&accountId="
+
strconv
.
FormatInt
(
accountId
,
10
)
+
"&"
+
c
.
Req
.
URL
.
RawQuery
renderOpts
:=
&
renderer
.
RenderOpts
{
renderOpts
:=
&
renderer
.
RenderOpts
{
Url
:
c
.
Params
(
"*"
)
+
queryParams
,
Url
:
c
.
Params
(
"*"
)
+
queryParams
,
...
...
pkg/routes/index.go
View file @
eb2c0788
...
@@ -6,7 +6,6 @@ import (
...
@@ -6,7 +6,6 @@ import (
"github.com/torkelo/grafana-pro/pkg/routes/api"
"github.com/torkelo/grafana-pro/pkg/routes/api"
"github.com/torkelo/grafana-pro/pkg/routes/apimodel"
"github.com/torkelo/grafana-pro/pkg/routes/apimodel"
"github.com/torkelo/grafana-pro/pkg/routes/login"
"github.com/torkelo/grafana-pro/pkg/routes/login"
"github.com/torkelo/grafana-pro/pkg/stores/sqlstore"
)
)
func
Register
(
m
*
macaron
.
Macaron
)
{
func
Register
(
m
*
macaron
.
Macaron
)
{
...
@@ -33,8 +32,6 @@ func Register(m *macaron.Macaron) {
...
@@ -33,8 +32,6 @@ func Register(m *macaron.Macaron) {
}
}
func
Index
(
ctx
*
middleware
.
Context
)
{
func
Index
(
ctx
*
middleware
.
Context
)
{
sqlstore
.
GetAccounts
()
ctx
.
Data
[
"User"
]
=
apimodel
.
NewCurrentUserDto
(
ctx
.
UserAccount
)
ctx
.
Data
[
"User"
]
=
apimodel
.
NewCurrentUserDto
(
ctx
.
UserAccount
)
ctx
.
HTML
(
200
,
"index"
)
ctx
.
HTML
(
200
,
"index"
)
}
}
...
...
pkg/routes/login/login_oauth.go
View file @
eb2c0788
...
@@ -63,6 +63,8 @@ func OAuthLogin(ctx *middleware.Context) {
...
@@ -63,6 +63,8 @@ func OAuthLogin(ctx *middleware.Context) {
ctx
.
Handle
(
500
,
"Failed to create account"
,
err
)
ctx
.
Handle
(
500
,
"Failed to create account"
,
err
)
return
return
}
}
}
else
if
err
!=
nil
{
ctx
.
Handle
(
500
,
"Unexpected error"
,
err
)
}
}
// login
// login
...
...
pkg/stores/sqlstore/sqlstore.go
View file @
eb2c0788
...
@@ -6,9 +6,11 @@ import (
...
@@ -6,9 +6,11 @@ import (
"path"
"path"
"strings"
"strings"
"github.com/torkelo/grafana-pro/pkg/models"
"github.com/torkelo/grafana-pro/pkg/setting"
"github.com/go-xorm/xorm"
"github.com/go-xorm/xorm"
_
"github.com/mattn/go-sqlite3"
_
"github.com/mattn/go-sqlite3"
"github.com/torkelo/grafana-pro/pkg/setting"
)
)
var
(
var
(
...
@@ -24,14 +26,14 @@ var (
...
@@ -24,14 +26,14 @@ var (
UseSQLite3
bool
UseSQLite3
bool
)
)
type
AccountDto
struct
{
func
Init
()
{
Id
int64
tables
=
append
(
tables
,
new
(
models
.
Account
),
new
(
models
.
Dashboard
))
Email
string
`xorm:"UNIQUE NOT NULL"`
Passwd
string
`xorm:"NOT NULL"`
}
func
init
()
{
models
.
CreateAccount
=
CreateAccount
tables
=
append
(
tables
,
new
(
AccountDto
))
models
.
GetAccount
=
GetAccount
models
.
GetAccountByLogin
=
GetAccountByLogin
models
.
GetDashboard
=
GetDashboard
models
.
SaveDashboard
=
SaveDashboard
}
}
func
LoadModelsConfig
()
{
func
LoadModelsConfig
()
{
...
...
pkg/stores/sqlstore/sqlstore_accounts.go
View file @
eb2c0788
package
sqlstore
package
sqlstore
import
"github.com/torkelo/grafana-pro/pkg/log"
import
(
"github.com/torkelo/grafana-pro/pkg/models"
)
func
SaveAccount
(
)
error
{
func
CreateAccount
(
account
*
models
.
Account
)
error
{
var
err
error
var
err
error
sess
:=
x
.
NewSession
()
sess
:=
x
.
NewSession
()
...
@@ -12,12 +14,7 @@ func SaveAccount() error {
...
@@ -12,12 +14,7 @@ func SaveAccount() error {
return
err
return
err
}
}
u
:=
&
AccountDto
{
if
_
,
err
=
sess
.
Insert
(
account
);
err
!=
nil
{
Email
:
"asdasdas"
,
Passwd
:
"MyPassWd"
,
}
if
_
,
err
=
sess
.
Insert
(
u
);
err
!=
nil
{
sess
.
Rollback
()
sess
.
Rollback
()
return
err
return
err
}
else
if
err
=
sess
.
Commit
();
err
!=
nil
{
}
else
if
err
=
sess
.
Commit
();
err
!=
nil
{
...
@@ -27,14 +24,32 @@ func SaveAccount() error {
...
@@ -27,14 +24,32 @@ func SaveAccount() error {
return
nil
return
nil
}
}
func
GetAccounts
()
{
func
GetAccount
(
id
int64
)
(
*
models
.
Account
,
error
)
{
var
resp
=
make
([]
*
AccountDto
,
1
)
var
err
error
err
:=
x
.
Find
(
&
resp
)
account
:=
&
models
.
Account
{
Id
:
id
}
has
,
err
:=
x
.
Get
(
account
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Error
(
4
,
"Error"
,
err
)
return
nil
,
err
}
else
if
has
==
false
{
return
nil
,
models
.
ErrAccountNotFound
}
}
for
_
,
i
:=
range
resp
{
return
account
,
nil
log
.
Info
(
"Item %v"
,
i
)
}
func
GetAccountByLogin
(
emailOrLogin
string
)
(
*
models
.
Account
,
error
)
{
var
err
error
account
:=
&
models
.
Account
{
Login
:
emailOrLogin
}
has
,
err
:=
x
.
Get
(
account
)
if
err
!=
nil
{
return
nil
,
err
}
else
if
has
==
false
{
return
nil
,
models
.
ErrAccountNotFound
}
}
return
account
,
nil
}
}
pkg/stores/sqlstore/sqlstore_dashboards.go
0 → 100644
View file @
eb2c0788
package
sqlstore
import
(
"github.com/torkelo/grafana-pro/pkg/models"
)
func
SaveDashboard
(
dash
*
models
.
Dashboard
)
error
{
var
err
error
sess
:=
x
.
NewSession
()
defer
sess
.
Close
()
if
err
=
sess
.
Begin
();
err
!=
nil
{
return
err
}
if
_
,
err
=
sess
.
Insert
(
dash
);
err
!=
nil
{
sess
.
Rollback
()
return
err
}
else
if
err
=
sess
.
Commit
();
err
!=
nil
{
return
err
}
return
nil
}
func
GetDashboard
(
slug
string
,
accountId
int64
)
(
*
models
.
Dashboard
,
error
)
{
dashboard
:=
models
.
Dashboard
{
Slug
:
slug
,
AccountId
:
accountId
}
has
,
err
:=
x
.
Get
(
&
dashboard
)
if
err
!=
nil
{
return
nil
,
err
}
else
if
has
==
false
{
return
nil
,
models
.
ErrDashboardNotFound
}
return
&
dashboard
,
nil
}
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