diff --git a/pkg/services/sqlstore/dashboard_test.go b/pkg/services/sqlstore/dashboard_test.go index e6734fd5ee3..b8f915f7245 100644 --- a/pkg/services/sqlstore/dashboard_test.go +++ b/pkg/services/sqlstore/dashboard_test.go @@ -381,10 +381,11 @@ func TestDashboardDataAccess(t *testing.T) { childDash2 := insertTestDashboard("child dash 2", 1, folder2.Id, false, "prod") currentUser := createUser("viewer", "Viewer", false) + var rootFolderId int64 = 0 Convey("and one folder is expanded, the other collapsed", func() { Convey("should return dashboards in root and expanded folder", func() { - query := &search.FindPersistedDashboardsQuery{FolderIds: []int64{folder1.Id}, SignedInUser: &m.SignedInUser{UserId: currentUser.Id, OrgId: 1}, OrgId: 1} + query := &search.FindPersistedDashboardsQuery{FolderIds: []int64{rootFolderId, folder1.Id}, SignedInUser: &m.SignedInUser{UserId: currentUser.Id, OrgId: 1}, OrgId: 1} err := SearchDashboards(query) So(err, ShouldBeNil) So(len(query.Result), ShouldEqual, 4) diff --git a/public/app/core/services/search_srv.ts b/public/app/core/services/search_srv.ts index 4b32c2735bf..3d85cb20005 100644 --- a/public/app/core/services/search_srv.ts +++ b/public/app/core/services/search_srv.ts @@ -52,7 +52,7 @@ export class SearchSrv { } search(options) { - if (!options.query) { + if (!options.query && !options.tag) { return this.browse(); } diff --git a/public/app/features/dashboard/dashboard_list_ctrl.ts b/public/app/features/dashboard/dashboard_list_ctrl.ts index 032e8d7ffa0..ace7d8065a7 100644 --- a/public/app/features/dashboard/dashboard_list_ctrl.ts +++ b/public/app/features/dashboard/dashboard_list_ctrl.ts @@ -5,6 +5,7 @@ import { SearchSrv } from 'app/core/services/search_srv'; export class DashboardListCtrl { public sections: any []; tags: any []; + selectedTagFilter: any; query: any; navModel: any; canDelete = false; @@ -15,27 +16,40 @@ export class DashboardListCtrl { this.navModel = navModelSrv.getNav('dashboards', 'dashboards'); this.query = {query: '', mode: 'tree', tag: []}; - this.getDashboards(); - // this.getDashboards().then(() => { - // this.getTags(); - // }); + this.getDashboards().then(() => { + this.getTags(); + }); } getDashboards() { - return this.searchSrv.browse().then((result) => { + if (this.query.query.length === 0 && this.query.tag.length === 0) { + return this.searchSrv.browse().then((result) => { + return this.initDashboardList(result); + }); + } - this.sections = result; - - for (let section of this.sections) { - section.checked = false; - - for (let dashboard of section.items) { - dashboard.checked = false; - } - } + return this.searchSrv.search(this.query).then((result) => { + return this.initDashboardList(result); }); } + initDashboardList(result: any) { + if (!result) { + this.sections = []; + return; + } + + this.sections = result; + + for (let section of this.sections) { + section.checked = false; + + for (let dashboard of section.items) { + dashboard.checked = false; + } + } + } + selectionChanged() { let selectedDashboards = 0; @@ -119,11 +133,16 @@ export class DashboardListCtrl { }); } - // getTags() { - // return this.backendSrv.get('/api/dashboards/tags').then((results) => { - // this.tags = results; - // }); - // } + toggleFolder(section) { + return this.searchSrv.toggleFolder(section); + } + + getTags() { + return this.searchSrv.getDashboardTags().then((results) => { + this.tags = [{ term: 'Filter By Tag', disabled: true }].concat(results); + this.selectedTagFilter = this.tags[0]; + }); + } filterByTag(tag, evt) { this.query.tag.push(tag); @@ -134,6 +153,12 @@ export class DashboardListCtrl { } } + filterChange() { + this.query.tag.push(this.selectedTagFilter.term); + this.selectedTagFilter = this.tags[0]; + this.getDashboards(); + } + removeTag(tag, evt) { this.query.tag = _.without(this.query.tag, tag); this.getDashboards(); diff --git a/public/app/features/dashboard/partials/dashboardList.html b/public/app/features/dashboard/partials/dashboardList.html index 104861af637..b5f0fabeef4 100644 --- a/public/app/features/dashboard/partials/dashboardList.html +++ b/public/app/features/dashboard/partials/dashboardList.html @@ -54,23 +54,31 @@