Merge branch 'develop' of github.com:grafana/grafana into develop

This commit is contained in:
Torkel Ödegaard 2017-11-27 12:15:58 +01:00
commit 0a1c8fdac4
3 changed files with 64 additions and 1 deletions

View File

@ -10,6 +10,7 @@ export class DashboardListCtrl {
navModel: any;
canDelete = false;
canMove = false;
hasFilters = false;
selectAllChecked = false;
starredFilterOptions = [{text: 'Filter by Starred', disabled: true}, {text: 'Yes'}, {text: 'No'}];
selectedStarredFilter: any;
@ -17,7 +18,7 @@ export class DashboardListCtrl {
/** @ngInject */
constructor(private backendSrv, navModelSrv, private $q, private searchSrv: SearchSrv) {
this.navModel = navModelSrv.getNav('dashboards', 'dashboards');
this.query = {query: '', mode: 'tree', tag: []};
this.query = {query: '', mode: 'tree', tag: [], starred: false};
this.selectedStarredFilter = this.starredFilterOptions[0];
this.getDashboards().then(() => {
@ -35,6 +36,7 @@ export class DashboardListCtrl {
this.canMove = false;
this.canDelete = false;
this.selectAllChecked = false;
this.hasFilters = this.query.query.length > 0 || this.query.tag.length > 0 || this.query.starred;
if (!result) {
this.sections = [];
@ -194,4 +196,11 @@ export class DashboardListCtrl {
this.selectionChanged();
}
clearFilters() {
this.query.query = '';
this.query.tag = [];
this.query.starred = false;
this.getDashboards();
}
}

View File

@ -32,6 +32,18 @@
</span>
</div>
<div class="gf-form">
<div class="gf-form-button-row"
ng-show="ctrl.hasFilters">
<button
type="button"
class="btn gf-form-button btn-inverse btn-small"
ng-click="ctrl.clearFilters()">
<i class="fa fa-close"></i> Clear current search query and filters
</button>
</div>
</div>
<div class="gf-form-group">
<div class="gf-form-button-row">
<button type="button"

View File

@ -124,6 +124,10 @@ describe('DashboardListCtrl', () => {
expect(ctrl.canDelete).toBeFalsy();
});
it('should have active filters', () => {
expect(ctrl.hasFilters).toBeTruthy();
});
describe('when select all is checked', () => {
beforeEach(() => {
ctrl.selectAllChecked = true;
@ -143,6 +147,16 @@ describe('DashboardListCtrl', () => {
it('should enable delete button', () => {
expect(ctrl.canDelete).toBeTruthy();
});
describe('when clearing filters', () => {
beforeEach(() => {
return ctrl.clearFilters();
});
it('should reset query filter', () => {
expect(ctrl.query.query).toEqual('');
});
});
});
});
@ -155,6 +169,20 @@ describe('DashboardListCtrl', () => {
expect(ctrl.sections.length).toEqual(1);
expect(ctrl.query.tag[0]).toEqual('test');
});
it('should have active filters', () => {
expect(ctrl.hasFilters).toBeTruthy();
});
describe('when clearing filters', () => {
beforeEach(() => {
return ctrl.clearFilters();
});
it('should reset tag filter', () => {
expect(ctrl.query.tag.length).toEqual(0);
});
});
});
describe('with starred filter', () => {
@ -169,6 +197,20 @@ describe('DashboardListCtrl', () => {
expect(ctrl.sections.length).toEqual(1);
expect(ctrl.query.starred).toEqual(true);
});
it('should have active filters', () => {
expect(ctrl.hasFilters).toBeTruthy();
});
describe('when clearing filters', () => {
beforeEach(() => {
return ctrl.clearFilters();
});
it('should reset starred filter', () => {
expect(ctrl.query.starred).toEqual(false);
});
});
});
});