@@ -3,7 +3,7 @@ var elasticsearchSqlApp = angular.module('elasticsearchSqlApp', ["ngAnimate", "n
3
3
4
4
elasticsearchSqlApp . controller ( 'MainController' , function ( $scope , $http , $sce ) {
5
5
$scope . url = getUrl ( ) ;
6
- $scope . error = "" ;
6
+ $scope . error = "" ;
7
7
$scope . resultsColumns = [ ] ;
8
8
$scope . resultsRows = [ ] ;
9
9
$scope . searchLoading = false ;
@@ -13,6 +13,18 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
13
13
$scope . scrollId = null ;
14
14
$scope . gotNext = false ;
15
15
16
+ // pull version and put it on the scope
17
+ $http . get ( $scope . url ) . success ( function ( data ) {
18
+ $http . get ( $scope . url + "_nodes/" + data . name ) . success ( function ( nodeData ) {
19
+ var node = nodeData . nodes [ Object . keys ( nodeData . nodes ) [ 0 ] ] ;
20
+ angular . forEach ( node . plugins , function ( plugin ) {
21
+ if ( plugin . name === "sql" ) {
22
+ $scope . version = plugin . version ;
23
+ }
24
+ } ) ;
25
+ } ) ;
26
+ } ) ;
27
+
16
28
$scope . nextSearch = function ( ) {
17
29
$scope . error = "" ;
18
30
$scope . nextLoading = true ;
@@ -28,11 +40,11 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
28
40
. success ( function ( data , status , headers , config ) {
29
41
var handler = ResultHandlerFactory . create ( data ) ;
30
42
var body = handler . getBody ( )
31
-
43
+
32
44
if ( body . length == null || body . length == 0 ) {
33
45
$scope . gotNext = false ;
34
46
}
35
- else
47
+ else
36
48
{
37
49
$scope . scrollId = handler . getScrollId ( ) ;
38
50
}
@@ -43,12 +55,12 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
43
55
else {
44
56
$scope . resultsColumns = handler . getHead ( ) ;
45
57
$scope . resultsRows = handler . getBody ( ) ;
46
-
58
+
47
59
}
48
60
49
-
61
+
50
62
} )
51
- . error ( function ( data , status , headers , config ) {
63
+ . error ( function ( data , status , headers , config ) {
52
64
if ( data == "" ) {
53
65
$scope . error = "Error occured! response is not avalible." ;
54
66
}
@@ -59,7 +71,7 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
59
71
} )
60
72
. finally ( function ( ) {
61
73
$scope . nextLoading = false ;
62
- $scope . $apply ( )
74
+ $scope . $apply ( )
63
75
} ) ;
64
76
65
77
}
@@ -86,9 +98,9 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
86
98
}
87
99
$scope . resultsColumns = handler . getHead ( ) ;
88
100
$scope . resultsRows = handler . getBody ( ) ;
89
-
101
+
90
102
} )
91
- . error ( function ( data , status , headers , config ) {
103
+ . error ( function ( data , status , headers , config ) {
92
104
if ( data == "" ) {
93
105
$scope . error = "Error occured! response is not avalible." ;
94
106
}
@@ -98,10 +110,10 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
98
110
} )
99
111
. finally ( function ( ) {
100
112
$scope . searchLoading = false ;
101
- $scope . $apply ( )
113
+ $scope . $apply ( )
102
114
} ) ;
103
115
}
104
-
116
+
105
117
$scope . explain = function ( ) {
106
118
// Reset results and error box
107
119
$scope . error = "" ;
@@ -119,7 +131,7 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
119
131
$scope . resultExplan = true ;
120
132
window . explanResult . setValue ( JSON . stringify ( data , null , "\t" ) ) ;
121
133
} )
122
- . error ( function ( data , status , headers , config ) {
134
+ . error ( function ( data , status , headers , config ) {
123
135
$scope . resultExplan = false ;
124
136
if ( data == "" ) {
125
137
$scope . error = "Error occured! response is not avalible." ;
@@ -130,44 +142,44 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
130
142
} )
131
143
. finally ( function ( ) {
132
144
$scope . explainLoading = false ;
133
- $scope . $apply ( )
145
+ $scope . $apply ( )
134
146
} ) ;
135
147
}
136
-
137
-
138
-
139
- $scope . exportCSV = function ( ) {
148
+
149
+
150
+
151
+ $scope . exportCSV = function ( ) {
140
152
var columns = $scope . resultsColumns ;
141
153
var rows = $scope . resultsRows ;
142
154
var data = arr2csvStr ( columns , ',' ) ;
143
155
for ( var i = 0 ; i < rows . length ; i ++ ) {
144
156
data += "\n" ;
145
157
data += map2csvStr ( columns , rows [ i ] , ',' ) ;
146
-
158
+
147
159
}
148
160
var plain = 'data:text/csv;charset=utf8,' + encodeURIComponent ( data ) ;
149
- download ( plain , "query_result.csv" , "text/plain" ) ;
150
- return true ;
161
+ download ( plain , "query_result.csv" , "text/plain" ) ;
162
+ return true ;
151
163
}
152
164
153
165
$scope . getButtonContent = function ( isLoading , defName ) {
154
166
var loadingContent = "<span class=\"glyphicon glyphicon-refresh glyphicon-refresh-animate\"></span> Loading..." ;
155
167
var returnValue = isLoading ? loadingContent : defName ;
156
168
return $sce . trustAsHtml ( returnValue ) ;
157
169
}
158
-
159
-
170
+
171
+
160
172
function arr2csvStr ( arr , op ) {
161
- var data = arr [ 0 ] ;
173
+ var data = arr [ 0 ] ;
162
174
for ( var i = 1 ; i < arr . length ; i ++ ) {
163
175
data += op ;
164
176
data += arr [ i ] ;
165
177
}
166
178
return data ;
167
179
}
168
-
180
+
169
181
function map2csvStr ( columns , arr , op ) {
170
- var data = JSON . stringify ( arr [ columns [ 0 ] ] ) ;
182
+ var data = JSON . stringify ( arr [ columns [ 0 ] ] ) ;
171
183
for ( var i = 1 ; i < columns . length ; i ++ ) {
172
184
data += op ;
173
185
data += JSON . stringify ( arr [ columns [ i ] ] ) ;
@@ -186,7 +198,7 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
186
198
url = location . protocol + '//' + location . hostname + ( location . port ? ':' + location . port : '' ) ;
187
199
}
188
200
}
189
-
201
+
190
202
if ( url . substr ( url . length - 1 , 1 ) != '/' ) {
191
203
url += '/'
192
204
}
@@ -196,5 +208,5 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
196
208
197
209
function saveUrl ( ) {
198
210
localStorage . setItem ( "lasturl" , $scope . url ) ;
199
- }
211
+ }
200
212
} ) ;
0 commit comments