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
fc1d8416
Commit
fc1d8416
authored
Nov 20, 2017
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
working on dashboard search
parent
0fe42290
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
58 additions
and
58 deletions
+58
-58
pkg/api/search.go
+9
-2
pkg/services/search/handlers.go
+1
-1
pkg/services/search/models.go
+10
-11
pkg/services/sqlstore/dashboard.go
+2
-6
pkg/services/sqlstore/dashboard_test.go
+1
-1
pkg/services/sqlstore/migrations/dashboard_mig.go
+1
-1
pkg/services/sqlstore/search_builder.go
+7
-21
public/app/core/components/search/search.ts
+1
-1
public/app/core/services/search_srv.ts
+26
-14
No files found.
pkg/api/search.go
View file @
fc1d8416
...
@@ -15,7 +15,6 @@ func Search(c *middleware.Context) {
...
@@ -15,7 +15,6 @@ func Search(c *middleware.Context) {
starred
:=
c
.
Query
(
"starred"
)
starred
:=
c
.
Query
(
"starred"
)
limit
:=
c
.
QueryInt
(
"limit"
)
limit
:=
c
.
QueryInt
(
"limit"
)
dashboardType
:=
c
.
Query
(
"type"
)
dashboardType
:=
c
.
Query
(
"type"
)
folderId
:=
c
.
QueryInt64
(
"folderId"
)
if
limit
==
0
{
if
limit
==
0
{
limit
=
1000
limit
=
1000
...
@@ -29,6 +28,14 @@ func Search(c *middleware.Context) {
...
@@ -29,6 +28,14 @@ func Search(c *middleware.Context) {
}
}
}
}
folderIds
:=
make
([]
int64
,
0
)
for
_
,
id
:=
range
c
.
QueryStrings
(
"folderIds"
)
{
folderId
,
err
:=
strconv
.
ParseInt
(
id
,
10
,
64
)
if
err
==
nil
{
folderIds
=
append
(
folderIds
,
folderId
)
}
}
searchQuery
:=
search
.
Query
{
searchQuery
:=
search
.
Query
{
Title
:
query
,
Title
:
query
,
Tags
:
tags
,
Tags
:
tags
,
...
@@ -38,7 +45,7 @@ func Search(c *middleware.Context) {
...
@@ -38,7 +45,7 @@ func Search(c *middleware.Context) {
OrgId
:
c
.
OrgId
,
OrgId
:
c
.
OrgId
,
DashboardIds
:
dbids
,
DashboardIds
:
dbids
,
Type
:
dashboardType
,
Type
:
dashboardType
,
FolderId
:
folderId
,
FolderId
s
:
folderIds
,
}
}
err
:=
bus
.
Dispatch
(
&
searchQuery
)
err
:=
bus
.
Dispatch
(
&
searchQuery
)
...
...
pkg/services/search/handlers.go
View file @
fc1d8416
...
@@ -18,7 +18,7 @@ func searchHandler(query *Query) error {
...
@@ -18,7 +18,7 @@ func searchHandler(query *Query) error {
IsStarred
:
query
.
IsStarred
,
IsStarred
:
query
.
IsStarred
,
DashboardIds
:
query
.
DashboardIds
,
DashboardIds
:
query
.
DashboardIds
,
Type
:
query
.
Type
,
Type
:
query
.
Type
,
FolderId
:
query
.
FolderId
,
FolderId
s
:
query
.
FolderIds
,
Tags
:
query
.
Tags
,
Tags
:
query
.
Tags
,
Limit
:
query
.
Limit
,
Limit
:
query
.
Limit
,
}
}
...
...
pkg/services/search/models.go
View file @
fc1d8416
...
@@ -48,22 +48,21 @@ type Query struct {
...
@@ -48,22 +48,21 @@ type Query struct {
IsStarred
bool
IsStarred
bool
Type
string
Type
string
DashboardIds
[]
int64
DashboardIds
[]
int64
FolderId
int64
FolderId
s
[]
int64
Result
HitList
Result
HitList
}
}
type
FindPersistedDashboardsQuery
struct
{
type
FindPersistedDashboardsQuery
struct
{
Title
string
Title
string
OrgId
int64
OrgId
int64
SignedInUser
*
models
.
SignedInUser
SignedInUser
*
models
.
SignedInUser
IsStarred
bool
IsStarred
bool
DashboardIds
[]
int64
DashboardIds
[]
int64
Type
string
Type
string
FolderId
int64
FolderIds
[]
int64
Tags
[]
string
Tags
[]
string
ExpandedFolders
[]
int64
Limit
int
Limit
int
Result
HitList
Result
HitList
}
}
pkg/services/sqlstore/dashboard.go
View file @
fc1d8416
...
@@ -207,12 +207,8 @@ func findDashboards(query *search.FindPersistedDashboardsQuery) ([]DashboardSear
...
@@ -207,12 +207,8 @@ func findDashboards(query *search.FindPersistedDashboardsQuery) ([]DashboardSear
sb
.
WithType
(
query
.
Type
)
sb
.
WithType
(
query
.
Type
)
}
}
if
query
.
FolderId
>
0
{
if
len
(
query
.
FolderIds
)
>
0
{
sb
.
WithFolderId
(
query
.
FolderId
)
sb
.
WithFolderIds
(
query
.
FolderIds
)
}
if
len
(
query
.
ExpandedFolders
)
>
0
{
sb
.
WithExpandedFolders
(
query
.
ExpandedFolders
)
}
}
var
res
[]
DashboardSearchProjection
var
res
[]
DashboardSearchProjection
...
...
pkg/services/sqlstore/dashboard_test.go
View file @
fc1d8416
...
@@ -384,7 +384,7 @@ func TestDashboardDataAccess(t *testing.T) {
...
@@ -384,7 +384,7 @@ func TestDashboardDataAccess(t *testing.T) {
Convey
(
"and one folder is expanded, the other collapsed"
,
func
()
{
Convey
(
"and one folder is expanded, the other collapsed"
,
func
()
{
Convey
(
"should return dashboards in root and expanded folder"
,
func
()
{
Convey
(
"should return dashboards in root and expanded folder"
,
func
()
{
query
:=
&
search
.
FindPersistedDashboardsQuery
{
ExpandedFolder
s
:
[]
int64
{
folder1
.
Id
},
SignedInUser
:
&
m
.
SignedInUser
{
UserId
:
currentUser
.
Id
,
OrgId
:
1
},
OrgId
:
1
}
query
:=
&
search
.
FindPersistedDashboardsQuery
{
FolderId
s
:
[]
int64
{
folder1
.
Id
},
SignedInUser
:
&
m
.
SignedInUser
{
UserId
:
currentUser
.
Id
,
OrgId
:
1
},
OrgId
:
1
}
err
:=
SearchDashboards
(
query
)
err
:=
SearchDashboards
(
query
)
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
4
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
4
)
...
...
pkg/services/sqlstore/migrations/dashboard_mig.go
View file @
fc1d8416
...
@@ -139,7 +139,7 @@ func addDashboardMigration(mg *Migrator) {
...
@@ -139,7 +139,7 @@ func addDashboardMigration(mg *Migrator) {
// add column to store folder_id for dashboard folder structure
// add column to store folder_id for dashboard folder structure
mg
.
AddMigration
(
"Add column folder_id in dashboard"
,
NewAddColumnMigration
(
dashboardV2
,
&
Column
{
mg
.
AddMigration
(
"Add column folder_id in dashboard"
,
NewAddColumnMigration
(
dashboardV2
,
&
Column
{
Name
:
"folder_id"
,
Type
:
DB_BigInt
,
Nullable
:
true
,
Name
:
"folder_id"
,
Type
:
DB_BigInt
,
Nullable
:
false
,
Default
:
"0"
,
}))
}))
mg
.
AddMigration
(
"Add column isFolder in dashboard"
,
NewAddColumnMigration
(
dashboardV2
,
&
Column
{
mg
.
AddMigration
(
"Add column isFolder in dashboard"
,
NewAddColumnMigration
(
dashboardV2
,
&
Column
{
...
...
pkg/services/sqlstore/search_builder.go
View file @
fc1d8416
...
@@ -17,8 +17,7 @@ type SearchBuilder struct {
...
@@ -17,8 +17,7 @@ type SearchBuilder struct {
whereTitle
string
whereTitle
string
whereTypeFolder
bool
whereTypeFolder
bool
whereTypeDash
bool
whereTypeDash
bool
whereFolderId
int64
whereFolderIds
[]
int64
expandedFolders
[]
int64
sql
bytes
.
Buffer
sql
bytes
.
Buffer
params
[]
interface
{}
params
[]
interface
{}
}
}
...
@@ -72,14 +71,8 @@ func (sb *SearchBuilder) WithType(queryType string) *SearchBuilder {
...
@@ -72,14 +71,8 @@ func (sb *SearchBuilder) WithType(queryType string) *SearchBuilder {
return
sb
return
sb
}
}
func
(
sb
*
SearchBuilder
)
WithFolderId
(
folderId
int64
)
*
SearchBuilder
{
func
(
sb
*
SearchBuilder
)
WithFolderIds
(
folderIds
[]
int64
)
*
SearchBuilder
{
sb
.
whereFolderId
=
folderId
sb
.
whereFolderIds
=
folderIds
return
sb
}
func
(
sb
*
SearchBuilder
)
WithExpandedFolders
(
expandedFolders
[]
int64
)
*
SearchBuilder
{
sb
.
expandedFolders
=
expandedFolders
return
sb
return
sb
}
}
...
@@ -212,17 +205,10 @@ func (sb *SearchBuilder) buildSearchWhereClause() {
...
@@ -212,17 +205,10 @@ func (sb *SearchBuilder) buildSearchWhereClause() {
sb
.
sql
.
WriteString
(
" AND dashboard.is_folder = 0"
)
sb
.
sql
.
WriteString
(
" AND dashboard.is_folder = 0"
)
}
}
if
sb
.
whereFolderId
>
0
{
if
len
(
sb
.
whereFolderIds
)
>
0
{
sb
.
sql
.
WriteString
(
" AND dashboard.folder_id = ?"
)
sb
.
sql
.
WriteString
(
` AND dashboard.folder_id IN (?`
+
strings
.
Repeat
(
",?"
,
len
(
sb
.
whereFolderIds
)
-
1
)
+
`) `
)
sb
.
params
=
append
(
sb
.
params
,
sb
.
whereFolderId
)
for
_
,
id
:=
range
sb
.
whereFolderIds
{
}
sb
.
params
=
append
(
sb
.
params
,
id
)
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
)
}
}
}
}
}
}
public/app/core/components/search/search.ts
View file @
fc1d8416
...
@@ -37,7 +37,7 @@ export class SearchCtrl {
...
@@ -37,7 +37,7 @@ export class SearchCtrl {
this
.
giveSearchFocus
=
0
;
this
.
giveSearchFocus
=
0
;
this
.
selectedIndex
=
-
1
;
this
.
selectedIndex
=
-
1
;
this
.
results
=
[];
this
.
results
=
[];
this
.
query
=
{
query
:
''
,
tag
:
[],
starred
:
false
,
mode
:
'tree'
};
this
.
query
=
{
query
:
''
,
tag
:
[],
starred
:
false
};
this
.
currentSearchId
=
0
;
this
.
currentSearchId
=
0
;
this
.
ignoreClose
=
true
;
this
.
ignoreClose
=
true
;
...
...
public/app/core/services/search_srv.ts
View file @
fc1d8416
...
@@ -7,8 +7,12 @@ export class SearchSrv {
...
@@ -7,8 +7,12 @@ export class SearchSrv {
constructor
(
private
backendSrv
)
{
constructor
(
private
backendSrv
)
{
}
}
search
(
query
)
{
search
(
options
)
{
return
this
.
backendSrv
.
search
(
query
).
then
(
results
=>
{
if
(
!
options
.
query
)
{
options
.
folderIds
=
[
0
];
}
return
this
.
backendSrv
.
search
(
options
).
then
(
results
=>
{
let
sections
:
any
=
{};
let
sections
:
any
=
{};
...
@@ -34,22 +38,30 @@ export class SearchSrv {
...
@@ -34,22 +38,30 @@ export class SearchSrv {
// create folder index
// create folder index
for
(
let
hit
of
results
)
{
for
(
let
hit
of
results
)
{
let
section
=
sections
[
hit
.
folderId
];
if
(
hit
.
type
===
'dash-folder'
)
{
if
(
!
section
)
{
sections
[
hit
.
id
]
=
{
section
=
{
id
:
hit
.
id
,
id
:
hit
.
folderId
,
title
:
hit
.
title
,
title
:
hit
.
folderTitle
,
items
:
[],
items
:
[],
icon
:
'fa fa-folder-open'
icon
:
'fa fa-folder-open'
,
score
:
_
.
keys
(
sections
).
length
,
};
};
// handle root
if
(
!
hit
.
folderId
)
{
section
.
title
=
"Dashboards"
;
section
.
icon
=
"fa fa-circle-o"
;
}
sections
[
hit
.
folderId
]
=
section
;
}
}
}
sections
[
0
]
=
{
id
:
0
,
title
:
'Root'
,
items
:
[],
icon
:
'fa fa-folder-open'
,
score
:
_
.
keys
(
sections
).
length
,
};
for
(
let
hit
of
results
)
{
if
(
hit
.
type
===
'dash-folder'
)
{
continue
;
}
let
section
=
sections
[
hit
.
folderId
||
0
];
hit
.
url
=
'dashboard/'
+
hit
.
uri
;
hit
.
url
=
'dashboard/'
+
hit
.
uri
;
section
.
items
.
push
(
hit
);
section
.
items
.
push
(
hit
);
}
}
...
...
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