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
60541a45
Commit
60541a45
authored
Feb 04, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Worked on search filter flag IsStarred, and updated frontend with new dashboard list panel
parent
f0b13153
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
93 additions
and
27 deletions
+93
-27
grafana
+1
-1
pkg/api/search.go
+9
-0
pkg/models/search.go
+3
-0
pkg/services/sqlstore/account_users.go
+2
-1
pkg/services/sqlstore/dashboard.go
+32
-8
pkg/services/sqlstore/dashboard_test.go
+36
-12
pkg/services/sqlstore/migrations.go
+1
-1
pkg/services/sqlstore/migrator/dialect.go
+1
-1
pkg/services/sqlstore/star.go
+2
-3
pkg/services/sqlstore/user.go
+2
-0
pkg/setting/setting.go
+4
-0
No files found.
grafana
@
882ee4d4
Subproject commit
df51be02bf4fa72ac4f1bcb15006f08f8b93ce8d
Subproject commit
882ee4d49f1df4550e898a914b4d17d40add4ddf
pkg/api/search.go
View file @
60541a45
...
@@ -7,10 +7,13 @@ import (
...
@@ -7,10 +7,13 @@ import (
"github.com/torkelo/grafana-pro/pkg/bus"
"github.com/torkelo/grafana-pro/pkg/bus"
"github.com/torkelo/grafana-pro/pkg/middleware"
"github.com/torkelo/grafana-pro/pkg/middleware"
m
"github.com/torkelo/grafana-pro/pkg/models"
m
"github.com/torkelo/grafana-pro/pkg/models"
"github.com/torkelo/grafana-pro/pkg/setting"
)
)
func
Search
(
c
*
middleware
.
Context
)
{
func
Search
(
c
*
middleware
.
Context
)
{
queryText
:=
c
.
Query
(
"q"
)
queryText
:=
c
.
Query
(
"q"
)
starred
:=
c
.
Query
(
"starred"
)
result
:=
m
.
SearchResult
{
result
:=
m
.
SearchResult
{
Dashboards
:
[]
*
m
.
DashboardSearchHit
{},
Dashboards
:
[]
*
m
.
DashboardSearchHit
{},
Tags
:
[]
*
m
.
DashboardTagCloudItem
{},
Tags
:
[]
*
m
.
DashboardTagCloudItem
{},
...
@@ -31,6 +34,8 @@ func Search(c *middleware.Context) {
...
@@ -31,6 +34,8 @@ func Search(c *middleware.Context) {
query
:=
m
.
SearchDashboardsQuery
{
query
:=
m
.
SearchDashboardsQuery
{
Title
:
matches
[
3
],
Title
:
matches
[
3
],
Tag
:
matches
[
2
],
Tag
:
matches
[
2
],
UserId
:
c
.
UserId
,
IsStarred
:
starred
==
"1"
,
AccountId
:
c
.
AccountId
,
AccountId
:
c
.
AccountId
,
}
}
err
:=
bus
.
Dispatch
(
&
query
)
err
:=
bus
.
Dispatch
(
&
query
)
...
@@ -38,7 +43,11 @@ func Search(c *middleware.Context) {
...
@@ -38,7 +43,11 @@ func Search(c *middleware.Context) {
c
.
JsonApiErr
(
500
,
"Search failed"
,
err
)
c
.
JsonApiErr
(
500
,
"Search failed"
,
err
)
return
return
}
}
result
.
Dashboards
=
query
.
Result
result
.
Dashboards
=
query
.
Result
for
_
,
dash
:=
range
result
.
Dashboards
{
dash
.
Url
=
setting
.
AbsUrlTo
(
"dashboard/db/"
+
dash
.
Slug
)
}
}
}
c
.
JSON
(
200
,
result
)
c
.
JSON
(
200
,
result
)
...
...
pkg/models/search.go
View file @
60541a45
...
@@ -11,6 +11,7 @@ type DashboardSearchHit struct {
...
@@ -11,6 +11,7 @@ type DashboardSearchHit struct {
Title
string
`json:"title"`
Title
string
`json:"title"`
Slug
string
`json:"slug"`
Slug
string
`json:"slug"`
Tags
[]
string
`json:"tags"`
Tags
[]
string
`json:"tags"`
Url
string
`json:"url"`
}
}
type
DashboardTagCloudItem
struct
{
type
DashboardTagCloudItem
struct
{
...
@@ -22,6 +23,8 @@ type SearchDashboardsQuery struct {
...
@@ -22,6 +23,8 @@ type SearchDashboardsQuery struct {
Title
string
Title
string
Tag
string
Tag
string
AccountId
int64
AccountId
int64
UserId
int64
IsStarred
bool
Result
[]
*
DashboardSearchHit
Result
[]
*
DashboardSearchHit
}
}
...
...
pkg/services/sqlstore/account_users.go
View file @
60541a45
package
sqlstore
package
sqlstore
import
(
import
(
"fmt"
"time"
"time"
"github.com/go-xorm/xorm"
"github.com/go-xorm/xorm"
...
@@ -34,7 +35,7 @@ func AddAccountUser(cmd *m.AddAccountUserCommand) error {
...
@@ -34,7 +35,7 @@ func AddAccountUser(cmd *m.AddAccountUserCommand) error {
func
GetAccountUsers
(
query
*
m
.
GetAccountUsersQuery
)
error
{
func
GetAccountUsers
(
query
*
m
.
GetAccountUsersQuery
)
error
{
query
.
Result
=
make
([]
*
m
.
AccountUserDTO
,
0
)
query
.
Result
=
make
([]
*
m
.
AccountUserDTO
,
0
)
sess
:=
x
.
Table
(
"account_user"
)
sess
:=
x
.
Table
(
"account_user"
)
sess
.
Join
(
"INNER"
,
"user"
,
"account_user.user_id=user.id"
)
sess
.
Join
(
"INNER"
,
"user"
,
fmt
.
Sprintf
(
"account_user.user_id=%s.id"
,
x
.
Dialect
()
.
Quote
(
"user"
))
)
sess
.
Where
(
"account_user.account_id=?"
,
query
.
AccountId
)
sess
.
Where
(
"account_user.account_id=?"
,
query
.
AccountId
)
sess
.
Cols
(
"account_user.account_id"
,
"account_user.user_id"
,
"user.email"
,
"user.login"
,
"account_user.role"
)
sess
.
Cols
(
"account_user.account_id"
,
"account_user.user_id"
,
"user.email"
,
"user.login"
,
"account_user.role"
)
sess
.
Asc
(
"user.email"
,
"user.login"
)
sess
.
Asc
(
"user.email"
,
"user.login"
)
...
...
pkg/services/sqlstore/dashboard.go
View file @
60541a45
package
sqlstore
package
sqlstore
import
(
import
(
"bytes"
"github.com/go-xorm/xorm"
"github.com/go-xorm/xorm"
"github.com/torkelo/grafana-pro/pkg/bus"
"github.com/torkelo/grafana-pro/pkg/bus"
m
"github.com/torkelo/grafana-pro/pkg/models"
m
"github.com/torkelo/grafana-pro/pkg/models"
...
@@ -80,20 +82,42 @@ type DashboardSearchProjection struct {
...
@@ -80,20 +82,42 @@ type DashboardSearchProjection struct {
}
}
func
SearchDashboards
(
query
*
m
.
SearchDashboardsQuery
)
error
{
func
SearchDashboards
(
query
*
m
.
SearchDashboardsQuery
)
error
{
titleQuery
:=
"%"
+
query
.
Title
+
"%"
var
sql
bytes
.
Buffer
params
:=
make
([]
interface
{},
0
)
sql
.
WriteString
(
`SELECT
dashboard.id,
dashboard.title,
dashboard.slug,
dashboard_tag.term
FROM dashboard
LEFT OUTER JOIN dashboard_tag on dashboard_tag.dashboard_id = dashboard.id`
)
if
query
.
IsStarred
{
sql
.
WriteString
(
" INNER JOIN star on star.dashboard_id = dashboard.id"
)
}
sql
.
WriteString
(
` WHERE dashboard.account_id=?`
)
sess
:=
x
.
Table
(
"dashboard"
)
params
=
append
(
params
,
query
.
AccountId
)
sess
.
Join
(
"LEFT OUTER"
,
"dashboard_tag"
,
"dashboard.id=dashboard_tag.dashboard_id"
)
sess
.
Where
(
"account_id=? AND title LIKE ?"
,
query
.
AccountId
,
titleQuery
)
if
query
.
IsStarred
{
sess
.
Cols
(
"dashboard.id"
,
"dashboard.title"
,
"dashboard.slug"
,
"dashboard_tag.term"
)
sql
.
WriteString
(
` AND star.user_id=?`
)
sess
.
Limit
(
100
,
0
)
params
=
append
(
params
,
query
.
UserId
)
}
if
len
(
query
.
Title
)
>
0
{
sql
.
WriteString
(
" AND dashboard.title LIKE ?"
)
params
=
append
(
params
,
"%"
+
query
.
Title
+
"%"
)
}
if
len
(
query
.
Tag
)
>
0
{
if
len
(
query
.
Tag
)
>
0
{
sess
.
And
(
"dashboard_tag.term=?"
,
query
.
Tag
)
sql
.
WriteString
(
" AND dashboard_tag.term=?"
)
params
=
append
(
params
,
query
.
Tag
)
}
}
var
res
[]
DashboardSearchProjection
var
res
[]
DashboardSearchProjection
err
:=
sess
.
Find
(
&
res
)
err
:=
x
.
Sql
(
sql
.
String
(),
params
...
)
.
Find
(
&
res
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
pkg/services/sqlstore/dashboard_test.go
View file @
60541a45
...
@@ -8,27 +8,29 @@ import (
...
@@ -8,27 +8,29 @@ import (
m
"github.com/torkelo/grafana-pro/pkg/models"
m
"github.com/torkelo/grafana-pro/pkg/models"
)
)
func
TestDashboardDataAccess
(
t
*
testing
.
T
)
{
func
insertTestDashboard
(
title
string
,
accountId
int64
,
tags
...
interface
{})
*
m
.
Dashboard
{
Convey
(
"Testing DB"
,
t
,
func
()
{
InitTestDB
(
t
)
Convey
(
"Given saved dashboard"
,
func
()
{
var
savedDash
*
m
.
Dashboard
cmd
:=
m
.
SaveDashboardCommand
{
cmd
:=
m
.
SaveDashboardCommand
{
AccountId
:
1
,
AccountId
:
accountId
,
Dashboard
:
map
[
string
]
interface
{}{
Dashboard
:
map
[
string
]
interface
{}{
"id"
:
nil
,
"id"
:
nil
,
"title"
:
"test dash 23"
,
"title"
:
title
,
"tags"
:
[]
interface
{}{
"prod"
,
"webapp"
}
,
"tags"
:
tags
,
},
},
}
}
err
:=
SaveDashboard
(
&
cmd
)
err
:=
SaveDashboard
(
&
cmd
)
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
savedDash
=
cmd
.
Result
return
cmd
.
Result
}
func
TestDashboardDataAccess
(
t
*
testing
.
T
)
{
Convey
(
"Testing DB"
,
t
,
func
()
{
InitTestDB
(
t
)
Convey
(
"Given saved dashboard"
,
func
()
{
savedDash
:=
insertTestDashboard
(
"test dash 23"
,
1
,
"prod"
,
"webapp"
)
Convey
(
"Should return dashboard model"
,
func
()
{
Convey
(
"Should return dashboard model"
,
func
()
{
So
(
savedDash
.
Title
,
ShouldEqual
,
"test dash 23"
)
So
(
savedDash
.
Title
,
ShouldEqual
,
"test dash 23"
)
...
@@ -97,6 +99,28 @@ func TestDashboardDataAccess(t *testing.T) {
...
@@ -97,6 +99,28 @@ func TestDashboardDataAccess(t *testing.T) {
So
(
len
(
query
.
Result
),
ShouldEqual
,
2
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
2
)
})
})
Convey
(
"Given two dashboards, one is starred dashboard by user 10, other starred by user 1"
,
func
()
{
starredDash
:=
insertTestDashboard
(
"starred dash"
,
1
)
StarDashboard
(
&
m
.
StarDashboardCommand
{
DashboardId
:
starredDash
.
Id
,
UserId
:
10
,
})
StarDashboard
(
&
m
.
StarDashboardCommand
{
DashboardId
:
savedDash
.
Id
,
UserId
:
1
,
})
Convey
(
"Should be able to search for starred dashboards"
,
func
()
{
query
:=
m
.
SearchDashboardsQuery
{
AccountId
:
1
,
UserId
:
10
,
IsStarred
:
true
}
err
:=
SearchDashboards
(
&
query
)
So
(
err
,
ShouldBeNil
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
1
)
So
(
query
.
Result
[
0
]
.
Title
,
ShouldEqual
,
"starred dash"
)
})
})
})
})
})
})
}
}
pkg/services/sqlstore/migrations.go
View file @
60541a45
...
@@ -36,7 +36,7 @@ func addUserMigrations(mg *Migrator) {
...
@@ -36,7 +36,7 @@ func addUserMigrations(mg *Migrator) {
&
Column
{
Name
:
"login"
,
Type
:
DB_NVarchar
,
Length
:
255
,
Nullable
:
false
},
&
Column
{
Name
:
"login"
,
Type
:
DB_NVarchar
,
Length
:
255
,
Nullable
:
false
},
&
Column
{
Name
:
"email"
,
Type
:
DB_NVarchar
,
Length
:
255
,
Nullable
:
false
},
&
Column
{
Name
:
"email"
,
Type
:
DB_NVarchar
,
Length
:
255
,
Nullable
:
false
},
&
Column
{
Name
:
"name"
,
Type
:
DB_NVarchar
,
Length
:
255
,
Nullable
:
true
},
&
Column
{
Name
:
"name"
,
Type
:
DB_NVarchar
,
Length
:
255
,
Nullable
:
true
},
&
Column
{
Name
:
"password"
,
Type
:
DB_NVarchar
,
Length
:
50
,
Nullable
:
true
},
&
Column
{
Name
:
"password"
,
Type
:
DB_NVarchar
,
Length
:
255
,
Nullable
:
true
},
&
Column
{
Name
:
"salt"
,
Type
:
DB_NVarchar
,
Length
:
50
,
Nullable
:
true
},
&
Column
{
Name
:
"salt"
,
Type
:
DB_NVarchar
,
Length
:
50
,
Nullable
:
true
},
&
Column
{
Name
:
"company"
,
Type
:
DB_NVarchar
,
Length
:
255
,
Nullable
:
true
},
&
Column
{
Name
:
"company"
,
Type
:
DB_NVarchar
,
Length
:
255
,
Nullable
:
true
},
&
Column
{
Name
:
"account_id"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
&
Column
{
Name
:
"account_id"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
...
...
pkg/services/sqlstore/migrator/dialect.go
View file @
60541a45
...
@@ -95,7 +95,7 @@ func (b *BaseDialect) CreateTableSql(table *Table) string {
...
@@ -95,7 +95,7 @@ func (b *BaseDialect) CreateTableSql(table *Table) string {
}
}
func
(
db
*
BaseDialect
)
AddColumnSql
(
tableName
string
,
col
*
Column
)
string
{
func
(
db
*
BaseDialect
)
AddColumnSql
(
tableName
string
,
col
*
Column
)
string
{
return
fmt
.
Sprintf
(
"alter table %s ADD COLUMN %s"
,
tableName
,
col
.
StringNoPk
(
db
.
dialect
))
return
fmt
.
Sprintf
(
"alter table %s ADD COLUMN %s"
,
db
.
dialect
.
Quote
(
tableName
)
,
col
.
StringNoPk
(
db
.
dialect
))
}
}
func
(
db
*
BaseDialect
)
CreateIndexSql
(
tableName
string
,
index
*
Index
)
string
{
func
(
db
*
BaseDialect
)
CreateIndexSql
(
tableName
string
,
index
*
Index
)
string
{
...
...
pkg/services/sqlstore/star.go
View file @
60541a45
package
sqlstore
package
sqlstore
import
(
import
(
"strconv"
"github.com/go-xorm/xorm"
"github.com/go-xorm/xorm"
"github.com/torkelo/grafana-pro/pkg/bus"
"github.com/torkelo/grafana-pro/pkg/bus"
...
@@ -23,11 +21,12 @@ func IsStarredByUser(query *m.IsStarredByUserQuery) error {
...
@@ -23,11 +21,12 @@ func IsStarredByUser(query *m.IsStarredByUserQuery) error {
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
len
(
results
)
==
0
{
if
len
(
results
)
==
0
{
return
nil
return
nil
}
}
query
.
Result
,
_
=
strconv
.
ParseBool
(
string
(
results
[
0
][
"1"
]))
query
.
Result
=
true
return
nil
return
nil
}
}
...
...
pkg/services/sqlstore/user.go
View file @
60541a45
...
@@ -69,9 +69,11 @@ func CreateUser(cmd *m.CreateUserCommand) error {
...
@@ -69,9 +69,11 @@ func CreateUser(cmd *m.CreateUserCommand) error {
Updated
:
time
.
Now
(),
Updated
:
time
.
Now
(),
}
}
if
len
(
cmd
.
Password
)
>
0
{
user
.
Salt
=
util
.
GetRandomString
(
10
)
user
.
Salt
=
util
.
GetRandomString
(
10
)
user
.
Rands
=
util
.
GetRandomString
(
10
)
user
.
Rands
=
util
.
GetRandomString
(
10
)
user
.
Password
=
util
.
EncodePassword
(
cmd
.
Password
,
user
.
Salt
)
user
.
Password
=
util
.
EncodePassword
(
cmd
.
Password
,
user
.
Salt
)
}
sess
.
UseBool
(
"is_admin"
)
sess
.
UseBool
(
"is_admin"
)
...
...
pkg/setting/setting.go
View file @
60541a45
...
@@ -148,6 +148,10 @@ func parseAppUrlAndSubUrl(section *ini.Section) (string, string) {
...
@@ -148,6 +148,10 @@ func parseAppUrlAndSubUrl(section *ini.Section) (string, string) {
return
appUrl
,
appSubUrl
return
appUrl
,
appSubUrl
}
}
func
AbsUrlTo
(
relativeUrl
string
)
string
{
return
AppUrl
+
relativeUrl
}
func
NewConfigContext
()
{
func
NewConfigContext
()
{
configFiles
:=
findConfigFiles
()
configFiles
:=
findConfigFiles
()
...
...
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