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
d562dcd9
Commit
d562dcd9
authored
Jan 09, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Default datasource and event system test
parent
f99e1ba4
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
140 additions
and
97 deletions
+140
-97
pkg/api/datasources.go
+3
-2
pkg/models/account.go
+45
-35
pkg/models/dashboards.go
+27
-49
pkg/models/datasource.go
+23
-10
pkg/models/search.go
+31
-0
pkg/services/account/handlers.go
+9
-0
pkg/stores/sqlstore/datasource.go
+2
-1
No files found.
pkg/api/datasources.go
View file @
d562dcd9
...
@@ -64,12 +64,13 @@ func AddDataSource(c *middleware.Context) {
...
@@ -64,12 +64,13 @@ func AddDataSource(c *middleware.Context) {
cmd
.
AccountId
=
c
.
Account
.
Id
cmd
.
AccountId
=
c
.
Account
.
Id
err
:=
bus
.
Dispatch
(
&
cmd
)
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
if
err
!=
nil
{
c
.
JsonApiErr
(
500
,
"Failed to add datasource"
,
err
)
c
.
JsonApiErr
(
500
,
"Failed to add datasource"
,
err
)
return
return
}
}
//bus.Publish(&m.DataSourceCreatedEvent{Account: c.GetAccountId(), })
c
.
JsonOK
(
"Datasource added"
)
c
.
JsonOK
(
"Datasource added"
)
}
}
...
...
pkg/models/account.go
View file @
d562dcd9
...
@@ -6,49 +6,31 @@ import (
...
@@ -6,49 +6,31 @@ import (
)
)
// Typed errors
// Typed errors
var
(
var
(
ErrAccountNotFound
=
errors
.
New
(
"Account not found"
)
ErrAccountNotFound
=
errors
.
New
(
"Account not found"
)
)
)
type
Account
struct
{
type
Account
struct
{
Id
int64
Id
int64
Login
string
`xorm:"UNIQUE NOT NULL"`
Login
string
`xorm:"UNIQUE NOT NULL"`
Email
string
`xorm:"UNIQUE NOT NULL"`
Email
string
`xorm:"UNIQUE NOT NULL"`
Name
string
Name
string
FullName
string
FullName
string
Password
string
Password
string
IsAdmin
bool
IsAdmin
bool
Rands
string
`xorm:"VARCHAR(10)"`
Salt
string
`xorm:"VARCHAR(10)"`
Salt
string
`xorm:"VARCHAR(10)"`
Company
string
Company
string
NextDashboardId
int
NextDashboardId
int
UsingAccountId
int64
UsingAccountId
int64
DefaultDataSourceId
int64
Created
time
.
Time
Created
time
.
Time
Updated
time
.
Time
Updated
time
.
Time
}
}
// api projection
// ---------------------
type
OtherAccountDTO
struct
{
// COMMANDS
Id
int64
`json:"id"`
Email
string
`json:"email"`
Role
string
`json:"role"`
IsUsing
bool
`json:"isUsing"`
}
// api projection model
type
CollaboratorDTO
struct
{
AccountId
int64
`json:"accountId"`
Email
string
`json:"email"`
Role
string
`json:"role"`
}
// api view projection
type
AccountDTO
struct
{
Email
string
`json:"email"`
Name
string
`json:"name"`
Collaborators
[]
*
CollaboratorDTO
`json:"collaborators"`
}
type
CreateAccountCommand
struct
{
type
CreateAccountCommand
struct
{
Email
string
`json:"email" binding:"required"`
Email
string
`json:"email" binding:"required"`
...
@@ -66,13 +48,19 @@ type SetUsingAccountCommand struct {
...
@@ -66,13 +48,19 @@ type SetUsingAccountCommand struct {
UsingAccountId
int64
UsingAccountId
int64
}
}
// returns a view projection
type
SetDefaultDataSourceCommand
struct
{
AccountId
int64
DataSourceId
int64
}
// ----------------------
// QUERIES
type
GetAccountInfoQuery
struct
{
type
GetAccountInfoQuery
struct
{
Id
int64
Id
int64
Result
AccountDTO
Result
AccountDTO
}
}
// returns a view projection
type
GetOtherAccountsQuery
struct
{
type
GetOtherAccountsQuery
struct
{
AccountId
int64
AccountId
int64
Result
[]
*
OtherAccountDTO
Result
[]
*
OtherAccountDTO
...
@@ -87,3 +75,25 @@ type GetAccountByLoginQuery struct {
...
@@ -87,3 +75,25 @@ type GetAccountByLoginQuery struct {
Login
string
Login
string
Result
*
Account
Result
*
Account
}
}
// ------------------------
// DTO & Projections
type
OtherAccountDTO
struct
{
Id
int64
`json:"id"`
Email
string
`json:"email"`
Role
string
`json:"role"`
IsUsing
bool
`json:"isUsing"`
}
type
CollaboratorDTO
struct
{
AccountId
int64
`json:"accountId"`
Email
string
`json:"email"`
Role
string
`json:"role"`
}
type
AccountDTO
struct
{
Email
string
`json:"email"`
Name
string
`json:"name"`
Collaborators
[]
*
CollaboratorDTO
`json:"collaborators"`
}
pkg/models/dashboards.go
View file @
d562dcd9
...
@@ -25,55 +25,6 @@ type Dashboard struct {
...
@@ -25,55 +25,6 @@ type Dashboard struct {
Data
map
[
string
]
interface
{}
Data
map
[
string
]
interface
{}
}
}
type
SearchResult
struct
{
Dashboards
[]
*
DashboardSearchHit
`json:"dashboards"`
Tags
[]
*
DashboardTagCloudItem
`json:"tags"`
TagsOnly
bool
`json:"tagsOnly"`
}
type
DashboardSearchHit
struct
{
Title
string
`json:"title"`
Slug
string
`json:"slug"`
Tags
[]
string
`json:"tags"`
}
type
DashboardTagCloudItem
struct
{
Term
string
`json:"term"`
Count
int
`json:"count"`
}
type
SearchDashboardsQuery
struct
{
Title
string
Tag
string
AccountId
int64
Result
[]
*
DashboardSearchHit
}
type
GetDashboardTagsQuery
struct
{
AccountId
int64
Result
[]
*
DashboardTagCloudItem
}
type
SaveDashboardCommand
struct
{
Dashboard
map
[
string
]
interface
{}
`json:"dashboard"`
AccountId
int64
`json:"-"`
Result
*
Dashboard
}
type
DeleteDashboardCommand
struct
{
Slug
string
AccountId
int64
}
type
GetDashboardQuery
struct
{
Slug
string
AccountId
int64
Result
*
Dashboard
}
func
NewDashboard
(
title
string
)
*
Dashboard
{
func
NewDashboard
(
title
string
)
*
Dashboard
{
dash
:=
&
Dashboard
{}
dash
:=
&
Dashboard
{}
dash
.
Data
=
make
(
map
[
string
]
interface
{})
dash
.
Data
=
make
(
map
[
string
]
interface
{})
...
@@ -121,3 +72,30 @@ func (dash *Dashboard) UpdateSlug() {
...
@@ -121,3 +72,30 @@ func (dash *Dashboard) UpdateSlug() {
re2
:=
regexp
.
MustCompile
(
"
\\
s"
)
re2
:=
regexp
.
MustCompile
(
"
\\
s"
)
dash
.
Slug
=
re2
.
ReplaceAllString
(
re
.
ReplaceAllString
(
title
,
""
),
"-"
)
dash
.
Slug
=
re2
.
ReplaceAllString
(
re
.
ReplaceAllString
(
title
,
""
),
"-"
)
}
}
//
// COMMANDS
//
type
SaveDashboardCommand
struct
{
Dashboard
map
[
string
]
interface
{}
`json:"dashboard"`
AccountId
int64
`json:"-"`
Result
*
Dashboard
}
type
DeleteDashboardCommand
struct
{
Slug
string
AccountId
int64
}
//
// QUERIES
//
type
GetDashboardQuery
struct
{
Slug
string
AccountId
int64
Result
*
Dashboard
}
pkg/models/datasource.go
View file @
d562dcd9
...
@@ -38,16 +38,8 @@ type DataSource struct {
...
@@ -38,16 +38,8 @@ type DataSource struct {
Updated
time
.
Time
Updated
time
.
Time
}
}
type
GetDataSourcesQuery
struct
{
// ----------------------
AccountId
int64
// COMMANDS
Result
[]
*
DataSource
}
type
GetDataSourceByIdQuery
struct
{
Id
int64
AccountId
int64
Result
DataSource
}
type
AddDataSourceCommand
struct
{
type
AddDataSourceCommand
struct
{
AccountId
int64
AccountId
int64
...
@@ -58,6 +50,8 @@ type AddDataSourceCommand struct {
...
@@ -58,6 +50,8 @@ type AddDataSourceCommand struct {
Password
string
Password
string
Database
string
Database
string
User
string
User
string
Result
*
DataSource
}
}
type
UpdateDataSourceCommand
struct
{
type
UpdateDataSourceCommand
struct
{
...
@@ -76,3 +70,22 @@ type DeleteDataSourceCommand struct {
...
@@ -76,3 +70,22 @@ type DeleteDataSourceCommand struct {
Id
int64
Id
int64
AccountId
int64
AccountId
int64
}
}
// ---------------------
// QUERIES
type
GetDataSourcesQuery
struct
{
AccountId
int64
Result
[]
*
DataSource
}
type
GetDataSourceByIdQuery
struct
{
Id
int64
AccountId
int64
Result
DataSource
}
// ---------------------
// EVENTS
type
DataSourceCreatedEvent
struct
{
}
pkg/models/search.go
0 → 100644
View file @
d562dcd9
package
models
type
SearchResult
struct
{
Dashboards
[]
*
DashboardSearchHit
`json:"dashboards"`
Tags
[]
*
DashboardTagCloudItem
`json:"tags"`
TagsOnly
bool
`json:"tagsOnly"`
}
type
DashboardSearchHit
struct
{
Title
string
`json:"title"`
Slug
string
`json:"slug"`
Tags
[]
string
`json:"tags"`
}
type
DashboardTagCloudItem
struct
{
Term
string
`json:"term"`
Count
int
`json:"count"`
}
type
SearchDashboardsQuery
struct
{
Title
string
Tag
string
AccountId
int64
Result
[]
*
DashboardSearchHit
}
type
GetDashboardTagsQuery
struct
{
AccountId
int64
Result
[]
*
DashboardTagCloudItem
}
pkg/services/account/handlers.go
0 → 100644
View file @
d562dcd9
package
account
import
(
"github.com/torkelo/grafana-pro/pkg/bus"
)
func
InitAccountService
()
{
bus
.
ListenTo
()
}
pkg/stores/sqlstore/datasource.go
View file @
d562dcd9
...
@@ -60,7 +60,8 @@ func AddDataSource(cmd *m.AddDataSourceCommand) error {
...
@@ -60,7 +60,8 @@ func AddDataSource(cmd *m.AddDataSourceCommand) error {
Updated
:
time
.
Now
(),
Updated
:
time
.
Now
(),
}
}
_
,
err
=
sess
.
Insert
(
ds
)
_
,
err
=
sess
.
Insert
(
&
ds
)
cmd
.
Result
=
&
ds
return
err
return
err
})
})
...
...
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