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
9ace21b6
Commit
9ace21b6
authored
Nov 20, 2017
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improved search srv
parent
6c5e19c1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
92 additions
and
40 deletions
+92
-40
public/app/core/components/search/search.html
+1
-1
public/app/core/components/search/search.ts
+4
-0
public/app/core/services/search_srv.ts
+32
-29
public/app/core/specs/search_srv.jest.ts
+55
-10
No files found.
public/app/core/components/search/search.html
View file @
9ace21b6
...
...
@@ -56,7 +56,7 @@
<h6
ng-hide=
"ctrl.results.length"
>
No dashboards matching your query were found.
</h6>
<div
ng-repeat=
"section in ctrl.results"
class=
"search-section"
>
<a
class=
"search-section__header pointer"
ng-show=
"::section.title"
ng-click=
"
section.collapsed = !section.collapsed
"
>
<a
class=
"search-section__header pointer"
ng-show=
"::section.title"
ng-click=
"
ctrl.toggleFolder(section)
"
>
<i
class=
"search-section__header__icon"
ng-class=
"section.icon"
></i>
<span
class=
"search-section__header__text"
>
{{::section.title}}
</span>
<i
class=
"fa fa-minus search-section__header__toggle"
ng-hide=
"section.collapsed"
></i>
...
...
public/app/core/components/search/search.ts
View file @
9ace21b6
...
...
@@ -150,6 +150,10 @@ export class SearchCtrl {
this
.
selectedIndex
=
0
;
this
.
searchDashboards
();
}
// toggleFolder(section) {
// this.searchSrv.toggleFolder(section);
// }
}
export
function
searchDirective
()
{
...
...
public/app/core/services/search_srv.ts
View file @
9ace21b6
...
...
@@ -7,39 +7,15 @@ export class SearchSrv {
constructor
(
private
backendSrv
)
{
}
search
(
options
)
{
if
(
!
options
.
query
)
{
options
.
folderIds
=
[
0
];
}
else
{
options
.
folderIds
=
[];
options
.
type
=
'dash-db'
;
}
browse
()
{
let
query
=
{
folderIds
:
[
0
]
};
return
this
.
backendSrv
.
search
(
options
).
then
(
results
=>
{
return
this
.
backendSrv
.
search
(
query
).
then
(
results
=>
{
let
sections
:
any
=
{};
// sections["starred"] = {
// score: 0,
// icon: 'fa fa-star-o',
// title: "Starred dashboards",
// items: [
// {title: 'Frontend Nginx'},
// {title: 'Cassandra overview'}
// ]
// };
//
// sections["recent"] = {
// score: 1,
// icon: 'fa fa-clock-o',
// title: "Recent dashboards",
// items: [
// {title: 'Frontend Nginx'},
// {title: 'Cassandra overview'}
// ]
// };
// create folder index
for
(
let
hit
of
results
)
{
if
(
hit
.
type
===
'dash-folder'
)
{
sections
[
hit
.
id
]
=
{
...
...
@@ -73,6 +49,33 @@ export class SearchSrv {
});
}
search
(
options
)
{
if
(
!
options
.
query
)
{
return
this
.
browse
();
}
options
.
folderIds
=
[];
options
.
type
=
'dash-db'
;
return
this
.
backendSrv
.
search
(
options
).
then
(
results
=>
{
let
section
=
{
hideHeader
:
true
,
items
:
[],
};
for
(
let
hit
of
results
)
{
if
(
hit
.
type
===
'dash-folder'
)
{
continue
;
}
hit
.
url
=
'dashboard/'
+
hit
.
uri
;
section
.
items
.
push
(
hit
);
}
return
[
section
];
});
}
getDashboardTags
()
{
return
this
.
backendSrv
.
get
(
'/api/dashboards/tags'
);
}
...
...
public/app/core/specs/search_srv.jest.ts
View file @
9ace21b6
...
...
@@ -15,23 +15,27 @@ describe('SearchSrv', () => {
beforeEach
(()
=>
{
backendSrvMock
.
search
=
jest
.
fn
().
mockReturnValue
(
Promise
.
resolve
([
{
title
:
'folder1'
,
type
:
'dash-folder'
,
id
:
1
,
},
{
title
:
'dash with no folder'
,
type
:
'dash-db'
,
id
:
2
,
},
{
title
:
'dash in folder1 1'
,
folderId
:
1
,
folderTitle
:
'folder1'
type
:
'dash-db'
,
id
:
3
,
folderId
:
1
},
{
title
:
'dash in folder1 2'
,
folderId
:
1
,
folderTitle
:
'folder1'
type
:
'dash-db'
,
id
:
4
,
folderId
:
1
},
{
title
:
'dahs in folder2 1'
,
folderId
:
2
,
folderTitle
:
'folder2'
}
]));
return
searchSrv
.
search
({
query
:
''
}).
then
(
res
=>
{
...
...
@@ -40,7 +44,48 @@ describe('SearchSrv', () => {
});
it
(
"should create sections for each folder and root"
,
()
=>
{
expect
(
results
).
toHaveLength
(
3
);
expect
(
results
).
toHaveLength
(
2
);
});
it
(
'should place folders first'
,
()
=>
{
expect
(
results
[
0
].
title
).
toBe
(
'folder1'
);
});
});
describe
(
"with query string and dashboards with folders returned"
,
()
=>
{
let
results
;
beforeEach
(()
=>
{
backendSrvMock
.
search
=
jest
.
fn
();
backendSrvMock
.
search
.
mockReturnValue
(
Promise
.
resolve
([
{
id
:
2
,
title
:
'dash with no folder'
,
type
:
'dash-db'
,
},
{
id
:
3
,
title
:
'dash in folder1 1'
,
type
:
'dash-db'
,
folderId
:
1
,
folderTitle
:
'folder1'
,
},
]));
return
searchSrv
.
search
({
query
:
'search'
}).
then
(
res
=>
{
results
=
res
;
});
});
it
(
"should not specify folder ids"
,
()
=>
{
expect
(
backendSrvMock
.
search
.
mock
.
calls
[
0
][
0
].
folderIds
).
toHaveLength
(
0
);
});
it
(
'should place all results in a single section'
,
()
=>
{
expect
(
results
).
toHaveLength
(
1
);
expect
(
results
[
0
].
hideHeader
).
toBe
(
true
);
});
});
...
...
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