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
7c741111
Commit
7c741111
authored
Nov 17, 2017
by
Daniel Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
search: add expanded folders
parent
f47673ab
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
10 deletions
+46
-10
pkg/services/search/models.go
+10
-9
pkg/services/sqlstore/dashboard.go
+7
-1
pkg/services/sqlstore/dashboard_test.go
+13
-0
pkg/services/sqlstore/search_builder.go
+16
-0
No files found.
pkg/services/search/models.go
View file @
7c741111
...
...
@@ -54,15 +54,16 @@ type Query struct {
}
type
FindPersistedDashboardsQuery
struct
{
Title
string
OrgId
int64
SignedInUser
*
models
.
SignedInUser
IsStarred
bool
DashboardIds
[]
int64
Type
string
FolderId
int64
Tags
[]
string
Limit
int
Title
string
OrgId
int64
SignedInUser
*
models
.
SignedInUser
IsStarred
bool
DashboardIds
[]
int64
Type
string
FolderId
int64
Tags
[]
string
ExpandedFolders
[]
int64
Limit
int
Result
HitList
}
pkg/services/sqlstore/dashboard.go
View file @
7c741111
...
...
@@ -191,7 +191,9 @@ func findDashboards(query *search.FindPersistedDashboardsQuery) ([]DashboardSear
limit
=
1000
}
sb
:=
NewSearchBuilder
(
query
.
SignedInUser
,
limit
)
.
WithTags
(
query
.
Tags
)
.
WithDashboardIdsIn
(
query
.
DashboardIds
)
sb
:=
NewSearchBuilder
(
query
.
SignedInUser
,
limit
)
.
WithTags
(
query
.
Tags
)
.
WithDashboardIdsIn
(
query
.
DashboardIds
)
if
query
.
IsStarred
{
sb
.
IsStarred
()
...
...
@@ -209,6 +211,10 @@ func findDashboards(query *search.FindPersistedDashboardsQuery) ([]DashboardSear
sb
.
WithFolderId
(
query
.
FolderId
)
}
if
len
(
query
.
ExpandedFolders
)
>
0
{
sb
.
WithExpandedFolders
(
query
.
ExpandedFolders
)
}
var
res
[]
DashboardSearchProjection
sql
,
params
:=
sb
.
ToSql
()
...
...
pkg/services/sqlstore/dashboard_test.go
View file @
7c741111
...
...
@@ -382,6 +382,19 @@ func TestDashboardDataAccess(t *testing.T) {
currentUser
:=
createUser
(
"viewer"
,
"Viewer"
,
false
)
Convey
(
"and one folder is expanded, the other collapsed"
,
func
()
{
Convey
(
"should return dashboards in root and expanded folder"
,
func
()
{
query
:=
&
search
.
FindPersistedDashboardsQuery
{
ExpandedFolders
:
[]
int64
{
folder1
.
Id
},
SignedInUser
:
&
m
.
SignedInUser
{
UserId
:
currentUser
.
Id
,
OrgId
:
1
},
OrgId
:
1
}
err
:=
SearchDashboards
(
query
)
So
(
err
,
ShouldBeNil
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
4
)
So
(
query
.
Result
[
0
]
.
Id
,
ShouldEqual
,
folder1
.
Id
)
So
(
query
.
Result
[
1
]
.
Id
,
ShouldEqual
,
folder2
.
Id
)
So
(
query
.
Result
[
2
]
.
Id
,
ShouldEqual
,
childDash1
.
Id
)
So
(
query
.
Result
[
3
]
.
Id
,
ShouldEqual
,
dashInRoot
.
Id
)
})
})
Convey
(
"and acl is set for one dashboard folder"
,
func
()
{
var
otherUser
int64
=
999
updateTestDashboardWithAcl
(
folder1
.
Id
,
otherUser
,
m
.
PERMISSION_EDIT
)
...
...
pkg/services/sqlstore/search_builder.go
View file @
7c741111
...
...
@@ -18,6 +18,7 @@ type SearchBuilder struct {
whereTypeFolder
bool
whereTypeDash
bool
whereFolderId
int64
expandedFolders
[]
int64
sql
bytes
.
Buffer
params
[]
interface
{}
}
...
...
@@ -77,6 +78,12 @@ func (sb *SearchBuilder) WithFolderId(folderId int64) *SearchBuilder {
return
sb
}
func
(
sb
*
SearchBuilder
)
WithExpandedFolders
(
expandedFolders
[]
int64
)
*
SearchBuilder
{
sb
.
expandedFolders
=
expandedFolders
return
sb
}
// ToSql builds the sql and returns it as a string, together with the params.
func
(
sb
*
SearchBuilder
)
ToSql
()
(
string
,
[]
interface
{})
{
sb
.
params
=
make
([]
interface
{},
0
)
...
...
@@ -209,4 +216,13 @@ func (sb *SearchBuilder) buildSearchWhereClause() {
sb
.
sql
.
WriteString
(
" AND dashboard.folder_id = ?"
)
sb
.
params
=
append
(
sb
.
params
,
sb
.
whereFolderId
)
}
if
len
(
sb
.
expandedFolders
)
>
0
{
sb
.
sql
.
WriteString
(
` AND (dashboard.folder_id IN (?`
+
strings
.
Repeat
(
",?"
,
len
(
sb
.
expandedFolders
)
-
1
)
+
`) `
)
sb
.
sql
.
WriteString
(
` OR dashboard.folder_id IS NULL OR dashboard.folder_id = 0)`
)
for
_
,
ef
:=
range
sb
.
expandedFolders
{
sb
.
params
=
append
(
sb
.
params
,
ef
)
}
}
}
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