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
41a3431c
Commit
41a3431c
authored
Nov 22, 2017
by
Daniel Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashlist: starred filter search
parent
2d2015d3
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
112 additions
and
34 deletions
+112
-34
public/app/core/services/search_srv.ts
+6
-2
public/app/core/specs/search_srv.jest.ts
+26
-0
public/app/features/dashboard/dashboard_list_ctrl.ts
+19
-8
public/app/features/dashboard/partials/dashboardList.html
+14
-8
public/app/features/dashboard/specs/dashboard_list_ctrl.jest.ts
+47
-16
No files found.
public/app/core/services/search_srv.ts
View file @
41a3431c
...
...
@@ -8,8 +8,10 @@ export class SearchSrv {
}
browse
()
{
const
rootFolderId
=
0
;
let
query
=
{
folderIds
:
[
0
]
folderIds
:
[
rootFolderId
]
};
return
this
.
backendSrv
.
search
(
query
).
then
(
results
=>
{
...
...
@@ -52,7 +54,9 @@ export class SearchSrv {
}
search
(
options
)
{
if
(
!
options
.
query
&&
!
options
.
tag
)
{
if
(
!
options
.
query
&&
(
!
options
.
tag
||
options
.
tag
.
length
===
0
)
&&
!
options
.
starred
)
{
return
this
.
browse
();
}
...
...
public/app/core/specs/search_srv.jest.ts
View file @
41a3431c
...
...
@@ -90,4 +90,30 @@ describe('SearchSrv', () => {
});
describe
(
"with tags"
,
()
=>
{
beforeEach
(()
=>
{
backendSrvMock
.
search
=
jest
.
fn
();
backendSrvMock
.
search
.
mockReturnValue
(
Promise
.
resolve
([]));
return
searchSrv
.
search
({
tag
:
[
'atag'
]}).
then
(()
=>
{});
});
it
(
"should send tags query to backend search"
,
()
=>
{
expect
(
backendSrvMock
.
search
.
mock
.
calls
[
0
][
0
].
tag
).
toHaveLength
(
1
);
});
});
describe
(
"with starred"
,
()
=>
{
beforeEach
(()
=>
{
backendSrvMock
.
search
=
jest
.
fn
();
backendSrvMock
.
search
.
mockReturnValue
(
Promise
.
resolve
([]));
return
searchSrv
.
search
({
starred
:
true
}).
then
(()
=>
{});
});
it
(
"should send starred query to backend search"
,
()
=>
{
expect
(
backendSrvMock
.
search
.
mock
.
calls
[
0
][
0
].
starred
).
toEqual
(
true
);
});
});
});
public/app/features/dashboard/dashboard_list_ctrl.ts
View file @
41a3431c
...
...
@@ -4,17 +4,20 @@ import { SearchSrv } from 'app/core/services/search_srv';
export
class
DashboardListCtrl
{
public
sections
:
any
[];
tags
:
any
[];
tag
FilterOption
s
:
any
[];
selectedTagFilter
:
any
;
query
:
any
;
navModel
:
any
;
canDelete
=
false
;
canMove
=
false
;
starredFilterOptions
=
[{
text
:
'Filter by Starred'
,
disabled
:
true
},
{
text
:
'Yes'
},
{
text
:
'No'
}];
selectedStarredFilter
:
any
;
/** @ngInject */
constructor
(
private
backendSrv
,
navModelSrv
,
private
$q
,
private
searchSrv
:
SearchSrv
)
{
this
.
navModel
=
navModelSrv
.
getNav
(
'dashboards'
,
'dashboards'
);
this
.
query
=
{
query
:
''
,
mode
:
'tree'
,
tag
:
[]};
this
.
selectedStarredFilter
=
this
.
starredFilterOptions
[
0
];
this
.
getDashboards
().
then
(()
=>
{
this
.
getTags
();
...
...
@@ -22,7 +25,9 @@ export class DashboardListCtrl {
}
getDashboards
()
{
if
(
this
.
query
.
query
.
length
===
0
&&
this
.
query
.
tag
.
length
===
0
)
{
if
(
this
.
query
.
query
.
length
===
0
&&
this
.
query
.
tag
.
length
===
0
&&
!
this
.
query
.
starred
)
{
return
this
.
searchSrv
.
browse
().
then
((
result
)
=>
{
return
this
.
initDashboardList
(
result
);
});
...
...
@@ -139,24 +144,25 @@ export class DashboardListCtrl {
getTags
()
{
return
this
.
searchSrv
.
getDashboardTags
().
then
((
results
)
=>
{
this
.
tags
=
[{
term
:
'Filter By Tag'
,
disabled
:
true
}].
concat
(
results
);
this
.
selectedTagFilter
=
this
.
tags
[
0
];
this
.
tag
FilterOption
s
=
[{
term
:
'Filter By Tag'
,
disabled
:
true
}].
concat
(
results
);
this
.
selectedTagFilter
=
this
.
tag
FilterOption
s
[
0
];
});
}
filterByTag
(
tag
,
evt
)
{
this
.
query
.
tag
.
push
(
tag
);
this
.
getDashboards
();
if
(
evt
)
{
evt
.
stopPropagation
();
evt
.
preventDefault
();
}
return
this
.
getDashboards
();
}
f
ilterChange
()
{
onTagF
ilterChange
()
{
this
.
query
.
tag
.
push
(
this
.
selectedTagFilter
.
term
);
this
.
selectedTagFilter
=
this
.
tags
[
0
];
this
.
getDashboards
();
this
.
selectedTagFilter
=
this
.
tag
FilterOption
s
[
0
];
return
this
.
getDashboards
();
}
removeTag
(
tag
,
evt
)
{
...
...
@@ -167,4 +173,9 @@ export class DashboardListCtrl {
evt
.
preventDefault
();
}
}
onStarredFilterChange
()
{
this
.
query
.
starred
=
this
.
selectedStarredFilter
.
text
===
'Yes'
;
return
this
.
getDashboards
();
}
}
public/app/features/dashboard/partials/dashboardList.html
View file @
41a3431c
...
...
@@ -52,16 +52,22 @@
</div>
<div
class=
"admin-list-table"
style=
"height: 80%"
>
<div>
<select
class=
"gf-form-input"
ng-model=
"ctrl.selectedStarredFilter"
ng-options=
"t.text disable when t.disabled for t in ctrl.starredFilterOptions"
ng-change=
"ctrl.onStarredFilterChange()"
/>
<select
class=
"gf-form-input"
ng-model=
"ctrl.selectedTagFilter"
ng-options=
"t.term disable when t.disabled for t in ctrl.tagFilterOptions"
ng-change=
"ctrl.onTagFilterChange()"
/>
</div>
<div
gemini-scrollbar
>
<div
ng-show=
"ctrl.sections.length > 0"
>
<div>
<select
class=
"gf-form-input"
ng-model=
"ctrl.selectedTagFilter"
ng-options=
"t.term disable when t.disabled for t in ctrl.tags"
ng-change=
"ctrl.filterChange(tag, $index)"
/>
</div>
<div
ng-repeat=
"section in ctrl.sections"
class=
"search-section"
>
<div
class=
"search-section__header pointer"
ng-show=
"::section.title"
>
...
...
public/app/features/dashboard/specs/dashboard_list_ctrl.jest.ts
View file @
41a3431c
import
{
DashboardListCtrl
}
from
'../dashboard_list_ctrl'
;
import
{
DashboardListCtrl
}
from
'../dashboard_list_ctrl'
;
import
{
SearchSrv
}
from
'app/core/services/search_srv'
;
import
q
from
'q'
;
...
...
@@ -104,20 +104,51 @@ describe('DashboardListCtrl', () => {
isStarred
:
false
,
}
];
ctrl
=
createCtrlWithStubs
(
response
);
ctrl
.
query
.
query
=
'd'
;
return
ctrl
.
getDashboards
();
ctrl
=
createCtrlWithStubs
([],
response
);
});
it
(
'should set checked to false on all sections and children'
,
()
=>
{
expect
(
ctrl
.
sections
.
length
).
toEqual
(
2
);
expect
(
ctrl
.
sections
[
0
].
checked
).
toEqual
(
false
);
expect
(
ctrl
.
sections
[
0
].
items
[
0
].
checked
).
toEqual
(
false
);
expect
(
ctrl
.
sections
[
1
].
checked
).
toEqual
(
false
);
expect
(
ctrl
.
sections
[
1
].
items
[
0
].
checked
).
toEqual
(
false
);
describe
(
'with no filter'
,
()
=>
{
beforeEach
(()
=>
{
ctrl
.
query
.
query
=
'd'
;
return
ctrl
.
getDashboards
();
});
it
(
'should set checked to false on all sections and children'
,
()
=>
{
expect
(
ctrl
.
sections
.
length
).
toEqual
(
2
);
expect
(
ctrl
.
sections
[
0
].
checked
).
toEqual
(
false
);
expect
(
ctrl
.
sections
[
0
].
items
[
0
].
checked
).
toEqual
(
false
);
expect
(
ctrl
.
sections
[
1
].
checked
).
toEqual
(
false
);
expect
(
ctrl
.
sections
[
1
].
items
[
0
].
checked
).
toEqual
(
false
);
});
});
describe
(
'with tag filter'
,
()
=>
{
beforeEach
(()
=>
{
return
ctrl
.
filterByTag
(
'test'
);
});
it
(
'should set tag filter'
,
()
=>
{
expect
(
ctrl
.
sections
.
length
).
toEqual
(
2
);
expect
(
ctrl
.
query
.
tag
[
0
]).
toEqual
(
'test'
);
});
});
describe
(
'with starred filter'
,
()
=>
{
beforeEach
(()
=>
{
const
yesOption
:
any
=
ctrl
.
starredFilterOptions
[
1
];
ctrl
.
selectedStarredFilter
=
yesOption
;
return
ctrl
.
onStarredFilterChange
();
});
it
(
'should set starred filter'
,
()
=>
{
expect
(
ctrl
.
sections
.
length
).
toEqual
(
2
);
expect
(
ctrl
.
query
.
starred
).
toEqual
(
true
);
});
});
});
describe
(
'when selecting dashboards'
,
()
=>
{
let
ctrl
;
...
...
@@ -362,21 +393,21 @@ describe('DashboardListCtrl', () => {
});
});
function
createCtrlWithStubs
(
response
:
any
)
{
function
createCtrlWithStubs
(
browseResponse
:
any
,
searchResponse
?:
any
,
tags
?
:
any
)
{
const
searchSrvStub
=
{
browse
:
()
=>
{
return
q
.
resolve
(
r
esponse
);
return
q
.
resolve
(
browseR
esponse
);
},
search
:
(
options
:
any
)
=>
{
return
q
.
resolve
(
r
esponse
);
return
q
.
resolve
(
searchR
esponse
);
},
toggleFolder
:
(
section
)
=>
{
return
q
.
resolve
(
response
)
;
return
;
},
getDashboardTags
:
()
=>
{
return
q
.
resolve
(
[]);
return
q
.
resolve
(
tags
||
[]);
}
};
return
new
DashboardListCtrl
({},
{
getNav
:
()
=>
{}
},
q
,
<
SearchSrv
>
searchSrvStub
);
return
new
DashboardListCtrl
({},
{
getNav
:
()
=>
{
}
},
q
,
<
SearchSrv
>
searchSrvStub
);
}
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