@@ -14,6 +14,7 @@ function (angular, _, config, $) {
14
14
$scope . init = function ( ) {
15
15
$scope . giveSearchFocus = 0 ;
16
16
$scope . selectedIndex = - 1 ;
17
+ $scope . results = { dashboards : [ ] , tags : [ ] , metrics : [ ] } ;
17
18
$scope . query = { query : 'title:' } ;
18
19
$rootScope . $on ( 'open-search' , $scope . openSearch ) ;
19
20
} ;
@@ -29,7 +30,15 @@ function (angular, _, config, $) {
29
30
$scope . selectedIndex -- ;
30
31
}
31
32
if ( evt . keyCode === 13 ) {
32
- var selectedDash = $scope . search_results . dashboards [ $scope . selectedIndex ] ;
33
+ if ( $scope . tagsOnly ) {
34
+ var tag = $scope . results . tags [ $scope . selectedIndex ] ;
35
+ if ( tag ) {
36
+ $scope . filterByTag ( tag . term ) ;
37
+ }
38
+ return ;
39
+ }
40
+
41
+ var selectedDash = $scope . results . dashboards [ $scope . selectedIndex ] ;
33
42
if ( selectedDash ) {
34
43
$location . path ( "/dashboard/elasticsearch/" + encodeURIComponent ( selectedDash . _id ) ) ;
35
44
setTimeout ( function ( ) {
@@ -39,15 +48,21 @@ function (angular, _, config, $) {
39
48
}
40
49
} ;
41
50
42
- $scope . elasticsearch_dashboards = function ( query ) {
51
+ $scope . searchDasboards = function ( query ) {
43
52
var request = $scope . ejs . Request ( ) . indices ( config . grafana_index ) . types ( 'dashboard' ) ;
44
-
45
- if ( query . length === 0 ) {
46
- query = 'title:' ;
53
+ var tagsOnly = query . indexOf ( 'tags!:' ) === 0 ;
54
+ if ( tagsOnly ) {
55
+ var tagsQuery = query . substring ( 6 , query . length ) ;
56
+ query = 'tags:' + tagsQuery + '*' ;
47
57
}
58
+ else {
59
+ if ( query . length === 0 ) {
60
+ query = 'title:' ;
61
+ }
48
62
49
- if ( query [ query . length - 1 ] !== '*' ) {
50
- query += '*' ;
63
+ if ( query [ query . length - 1 ] !== '*' ) {
64
+ query += '*' ;
65
+ }
51
66
}
52
67
53
68
return request
@@ -58,28 +73,31 @@ function (angular, _, config, $) {
58
73
. then ( function ( results ) {
59
74
60
75
if ( _ . isUndefined ( results . hits ) ) {
61
- $scope . search_results = { dashboards : [ ] } ;
76
+ $scope . results . dashboards = [ ] ;
77
+ $scope . results . tags = [ ] ;
62
78
return ;
63
79
}
64
80
65
- $scope . search_results = { dashboards : results . hits . hits } ;
66
- $scope . tags = results . facets . tags . terms ;
81
+ $scope . tagsOnly = tagsOnly ;
82
+ $scope . results . dashboards = results . hits . hits ;
83
+ $scope . results . tags = results . facets . tags . terms ;
67
84
} ) ;
68
85
} ;
69
86
70
87
$scope . filterByTag = function ( tag , evt ) {
71
88
$scope . query . query = "tags:" + tag + " AND title:" ;
72
89
$scope . search ( ) ;
73
- $scope . tagsOnly = false ;
74
90
$scope . giveSearchFocus = $scope . giveSearchFocus + 1 ;
75
- evt . stopPropagation ( ) ;
76
- evt . preventDefault ( ) ;
91
+ if ( evt ) {
92
+ evt . stopPropagation ( ) ;
93
+ evt . preventDefault ( ) ;
94
+ }
77
95
} ;
78
96
79
97
$scope . showTags = function ( evt ) {
80
98
evt . stopPropagation ( ) ;
81
99
$scope . tagsOnly = ! $scope . tagsOnly ;
82
- $scope . query . query = $scope . tagsOnly ? "tags!" : "" ;
100
+ $scope . query . query = $scope . tagsOnly ? "tags!: " : "" ;
83
101
$scope . giveSearchFocus = $scope . giveSearchFocus + 1 ;
84
102
$scope . selectedIndex = - 1 ;
85
103
} ;
@@ -92,7 +110,7 @@ function (angular, _, config, $) {
92
110
93
111
if ( queryStr . indexOf ( 'm:' ) !== 0 ) {
94
112
queryStr = queryStr . replace ( ' and ' , ' AND ' ) ;
95
- $scope . elasticsearch_dashboards ( queryStr ) ;
113
+ $scope . searchDasboards ( queryStr ) ;
96
114
return ;
97
115
}
98
116
@@ -115,10 +133,10 @@ function (angular, _, config, $) {
115
133
116
134
results . then ( function ( results ) {
117
135
if ( results && results . hits && results . hits . hits . length > 0 ) {
118
- $scope . search_results = { metrics : results . hits . hits } ;
136
+ $scope . results . metrics = { metrics : results . hits . hits } ;
119
137
}
120
138
else {
121
- $scope . search_results = { metric : [ ] } ;
139
+ $scope . results . metrics = { metric : [ ] } ;
122
140
}
123
141
} ) ;
124
142
} ;
0 commit comments