Просмотр исходного кода

minor update to dashboard search

Torkel Ödegaard 8 лет назад
Родитель
Сommit
c1539b90b7

+ 4 - 4
public/app/core/components/search/search.html

@@ -56,14 +56,14 @@
 				<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="ctrl.toggleFolder(section)">
+					<a class="search-section__header pointer" ng-hide="section.hideHeader" 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>
-						<i class="fa fa-plus search-section__header__toggle" ng-show="section.collapsed"></i>
+						<i class="fa fa-minus search-section__header__toggle" ng-show="section.expanded"></i>
+						<i class="fa fa-plus search-section__header__toggle" ng-hide="section.expanded"></i>
 					</a>
 
-					<div ng-if="!section.collapsed">
+					<div ng-if="section.expanded">
 						<a ng-repeat="item in section.items" class="search-item" ng-class="{'selected': item.selected}" ng-href="{{::item.url}}">
 							<span class="search-item__icon">
 								<i class="fa fa-th-large"></i>

+ 3 - 3
public/app/core/components/search/search.ts

@@ -151,9 +151,9 @@ export class SearchCtrl {
     this.searchDashboards();
   }
 
-  // toggleFolder(section) {
-  //   this.searchSrv.toggleFolder(section);
-  // }
+  toggleFolder(section) {
+    this.searchSrv.toggleFolder(section);
+  }
 }
 
 export function searchDirective() {

+ 25 - 3
public/app/core/services/search_srv.ts

@@ -34,6 +34,7 @@ export class SearchSrv {
         items: [],
         icon: 'fa fa-folder-open',
         score: _.keys(sections).length,
+        expanded: true,
       };
 
       for (let hit of results) {
@@ -54,14 +55,16 @@ export class SearchSrv {
       return this.browse();
     }
 
-    options.folderIds = [];
-    options.type = 'dash-db';
+    let query = _.clone(options);
+    query.folderIds = [];
+    query.type = 'dash-db';
 
-    return this.backendSrv.search(options).then(results => {
+    return this.backendSrv.search(query).then(results => {
 
       let section = {
         hideHeader: true,
         items: [],
+        expanded: true,
       };
 
       for (let hit of results) {
@@ -76,6 +79,25 @@ export class SearchSrv {
     });
   }
 
+  toggleFolder(section) {
+    section.expanded = !section.expanded;
+
+    if (section.items.length) {
+      return;
+    }
+
+    let query = {
+      folderIds: [section.id]
+    };
+
+    return this.backendSrv.search(query).then(results => {
+      for (let hit of results) {
+        hit.url = 'dashboard/' + hit.uri;
+        section.items.push(hit);
+      }
+    });
+  }
+
   getDashboardTags() {
     return this.backendSrv.get('/api/dashboards/tags');
   }