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
2e010b92
Commit
2e010b92
authored
Apr 27, 2017
by
Daniel Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: sort search with dash folder first
parent
9cbaf072
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
17 deletions
+32
-17
pkg/services/search/handlers_test.go
+17
-14
pkg/services/search/models.go
+15
-3
No files found.
pkg/services/search/handlers_test.go
View file @
2e010b92
...
...
@@ -16,10 +16,11 @@ func TestSearch(t *testing.T) {
bus
.
AddHandler
(
"test"
,
func
(
query
*
FindPersistedDashboardsQuery
)
error
{
query
.
Result
=
HitList
{
&
Hit
{
Id
:
16
,
Title
:
"CCAA"
,
Tags
:
[]
string
{
"BB"
,
"AA"
}},
&
Hit
{
Id
:
10
,
Title
:
"AABB"
,
Tags
:
[]
string
{
"CC"
,
"AA"
}},
&
Hit
{
Id
:
15
,
Title
:
"BBAA"
,
Tags
:
[]
string
{
"EE"
,
"AA"
,
"BB"
}},
&
Hit
{
Id
:
17
,
Title
:
"FOLDER"
,
Dashboards
:
[]
Hit
{
&
Hit
{
Id
:
16
,
Title
:
"CCAA"
,
Type
:
"dash-db"
,
Tags
:
[]
string
{
"BB"
,
"AA"
}},
&
Hit
{
Id
:
10
,
Title
:
"AABB"
,
Type
:
"dash-db"
,
Tags
:
[]
string
{
"CC"
,
"AA"
}},
&
Hit
{
Id
:
15
,
Title
:
"BBAA"
,
Type
:
"dash-db"
,
Tags
:
[]
string
{
"EE"
,
"AA"
,
"BB"
}},
&
Hit
{
Id
:
25
,
Title
:
"bbAAa"
,
Type
:
"dash-db"
,
Tags
:
[]
string
{
"EE"
,
"AA"
,
"BB"
}},
&
Hit
{
Id
:
17
,
Title
:
"FOLDER"
,
Type
:
"dash-folder"
,
Dashboards
:
[]
Hit
{
{
Id
:
18
,
Title
:
"ZZAA"
,
Tags
:
[]
string
{
"ZZ"
}},
}},
}
...
...
@@ -36,15 +37,17 @@ func TestSearch(t *testing.T) {
So
(
err
,
ShouldBeNil
)
Convey
(
"should return sorted results"
,
func
()
{
So
(
query
.
Result
[
0
]
.
Title
,
ShouldEqual
,
"AABB"
)
So
(
query
.
Result
[
1
]
.
Title
,
ShouldEqual
,
"BBAA"
)
So
(
query
.
Result
[
2
]
.
Title
,
ShouldEqual
,
"CCAA"
)
So
(
query
.
Result
[
0
]
.
Title
,
ShouldEqual
,
"FOLDER"
)
So
(
query
.
Result
[
1
]
.
Title
,
ShouldEqual
,
"AABB"
)
So
(
query
.
Result
[
2
]
.
Title
,
ShouldEqual
,
"BBAA"
)
So
(
query
.
Result
[
3
]
.
Title
,
ShouldEqual
,
"bbAAa"
)
So
(
query
.
Result
[
4
]
.
Title
,
ShouldEqual
,
"CCAA"
)
})
Convey
(
"should return sorted tags"
,
func
()
{
So
(
query
.
Result
[
1
]
.
Tags
[
0
],
ShouldEqual
,
"AA"
)
So
(
query
.
Result
[
1
]
.
Tags
[
1
],
ShouldEqual
,
"BB"
)
So
(
query
.
Result
[
1
]
.
Tags
[
2
],
ShouldEqual
,
"EE"
)
So
(
query
.
Result
[
3
]
.
Tags
[
0
],
ShouldEqual
,
"AA"
)
So
(
query
.
Result
[
3
]
.
Tags
[
1
],
ShouldEqual
,
"BB"
)
So
(
query
.
Result
[
3
]
.
Tags
[
2
],
ShouldEqual
,
"EE"
)
})
})
...
...
@@ -54,9 +57,9 @@ func TestSearch(t *testing.T) {
So
(
err
,
ShouldBeNil
)
Convey
(
"should return correct results"
,
func
()
{
So
(
len
(
query
.
Result
),
ShouldEqual
,
2
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
3
)
So
(
query
.
Result
[
0
]
.
Title
,
ShouldEqual
,
"BBAA"
)
So
(
query
.
Result
[
1
]
.
Title
,
ShouldEqual
,
"CCAA"
)
So
(
query
.
Result
[
2
]
.
Title
,
ShouldEqual
,
"CCAA"
)
})
})
...
...
@@ -67,8 +70,8 @@ func TestSearch(t *testing.T) {
So
(
err
,
ShouldBeNil
)
Convey
(
"should return correct results"
,
func
()
{
So
(
query
.
Result
[
3
]
.
Title
,
ShouldEqual
,
"FOLDER"
)
So
(
len
(
query
.
Result
[
3
]
.
Dashboards
),
ShouldEqual
,
1
)
So
(
query
.
Result
[
0
]
.
Title
,
ShouldEqual
,
"FOLDER"
)
So
(
len
(
query
.
Result
[
0
]
.
Dashboards
),
ShouldEqual
,
1
)
})
})
...
...
pkg/services/search/models.go
View file @
2e010b92
package
search
import
"strings"
type
HitType
string
const
(
...
...
@@ -23,9 +25,19 @@ type Hit struct {
type
HitList
[]
*
Hit
func
(
s
HitList
)
Len
()
int
{
return
len
(
s
)
}
func
(
s
HitList
)
Swap
(
i
,
j
int
)
{
s
[
i
],
s
[
j
]
=
s
[
j
],
s
[
i
]
}
func
(
s
HitList
)
Less
(
i
,
j
int
)
bool
{
return
s
[
i
]
.
Title
<
s
[
j
]
.
Title
}
func
(
s
HitList
)
Len
()
int
{
return
len
(
s
)
}
func
(
s
HitList
)
Swap
(
i
,
j
int
)
{
s
[
i
],
s
[
j
]
=
s
[
j
],
s
[
i
]
}
func
(
s
HitList
)
Less
(
i
,
j
int
)
bool
{
if
s
[
i
]
.
Type
==
"dash-folder"
&&
s
[
j
]
.
Type
==
"dash-db"
{
return
true
}
if
s
[
i
]
.
Type
==
"dash-db"
&&
s
[
j
]
.
Type
==
"dash-folder"
{
return
false
}
return
strings
.
ToLower
(
s
[
i
]
.
Title
)
<
strings
.
ToLower
(
s
[
j
]
.
Title
)
}
type
Query
struct
{
Title
string
...
...
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