1
1
2
2
var elasticsearchSqlApp = angular . module ( 'elasticsearchSqlApp' , [ "ngAnimate" , "ngSanitize" ] ) ;
3
3
4
- elasticsearchSqlApp . controller ( 'MainController' , function ( $scope , $http , $sce ) {
4
+ elasticsearchSqlApp . controller ( 'MainController' , function ( $scope , $http , $sce , $compile ) {
5
5
scroll_url = "_search/scroll?scroll=1m&scroll_id=" ;
6
6
$scope . url = getUrl ( ) ;
7
7
$scope . showResults = false ;
8
8
$scope . error = "" ;
9
- $scope . resultsColumns = [ ] ;
9
+ $scope . resultsColumns = [ ] ;
10
10
$scope . resultsRows = [ ] ;
11
11
$scope . searchLoading = false ;
12
12
$scope . explainLoading = false ;
13
13
$scope . nextLoading = false ;
14
14
$scope . resultExplan = false ;
15
- $scope . scrollId = null ;
15
+ $scope . scrollId = undefined ;
16
+ $scope . amountDescription = "" ;
17
+ var fetched = 0 ;
18
+ var total = 0 ;
19
+ //checkboxes
16
20
$scope . gotNext = false ;
21
+ $scope . useOldTable = false ;
17
22
$scope . delimiter = ',' ;
18
- $scope . amountDescription = "" ;
19
- var fetched = 0 ;
20
- var total = 0 ;
21
- // pull version and put it on the scope
23
+
24
+ var tablePresenter = new TablePresenter ( 'searchResult' , '#searchResultZone' ) ;
25
+
26
+
27
+ // pull version and put it on the scope
22
28
$http . get ( $scope . url ) . success ( function ( data ) {
23
29
$http . get ( $scope . url + "_nodes/" + data . name ) . success ( function ( nodeData ) {
24
30
var node = nodeData . nodes [ Object . keys ( nodeData . nodes ) [ 0 ] ] ;
@@ -30,73 +36,12 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
30
36
} ) ;
31
37
} ) ;
32
38
33
- function searchTillEndAndExportCsv ( scrollId ) {
34
- //todo: get total amount show fetched/total
35
- head = [ ]
36
- body = [ ]
37
- $scope . showResults = true ;
38
- callScrollAndFillBodyTillEnd ( scrollId , head , body , true ) ;
39
- }
40
- function updateDescription ( handler ) {
41
- total = handler . getTotal ( ) ;
42
- fetched += handler . getCurrentHitsSize ( ) ;
43
- $scope . amountDescription = fetched + "/" + total
44
- }
45
- function callScrollAndFillBodyTillEnd ( scrollId , head , body , firstTime ) {
46
- var url = $scope . url + scroll_url + scrollId ;
47
- $http . get ( url )
48
- . success ( function ( data , status , headers , config ) {
49
-
50
- var handler = ResultHandlerFactory . create ( data , $scope . isFlat ) ;
51
-
52
- updateDescription ( handler ) ;
53
- recieved = handler . getBody ( )
54
- if ( body . length > 0 ) {
55
- body = body . concat ( recieved ) ;
56
- //todo: extend head?
57
- head = handler . getHead ( ) ;
58
- }
59
- else {
60
- body = recieved ;
61
- head = handler . getHead ( ) ;
62
-
63
- }
64
- if ( recieved == undefined || recieved . length == undefined || recieved . length == 0 ) {
65
- if ( firstTime ) {
66
- callScrollAndFillBodyTillEnd ( handler . getScrollId ( ) , head , body , false ) ;
67
- }
68
- else {
69
- exportCSVWithoutScope ( head , body ) ;
70
- }
71
- }
72
- else {
73
- callScrollAndFillBodyTillEnd ( handler . getScrollId ( ) , head , body , false ) ;
74
- }
75
-
76
-
77
- } )
78
- . error ( function ( data , status , headers , config ) {
79
- if ( data == "" ) {
80
- $scope . error = "Error occured! response is not avalible." ;
81
- }
82
- else {
83
- $scope . error = JSON . stringify ( data ) ;
84
- $scope . scrollId = undefined ;
85
- }
86
- } )
87
- . finally ( function ( ) {
88
- $scope . nextLoading = false ;
89
- $scope . $apply ( )
90
- } ) ;
91
-
92
-
93
- // body...
94
- }
95
39
96
40
$scope . nextSearch = function ( ) {
97
41
$scope . error = "" ;
98
42
$scope . nextLoading = true ;
99
43
$scope . $apply ( ) ;
44
+ var needToBuildTable = false ;
100
45
101
46
102
47
if ( $scope . scrollId == undefined || $scope . scrollId == "" ) {
@@ -119,12 +64,13 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
119
64
}
120
65
121
66
if ( $scope . resultsRows . length > 0 ) {
67
+ tablePresenter . addRows ( handler . getBody ( ) ) ;
122
68
$scope . resultsRows = $scope . resultsRows . concat ( handler . getBody ( ) ) ;
123
69
}
124
70
else {
125
71
$scope . resultsColumns = handler . getHead ( ) ;
126
72
$scope . resultsRows = handler . getBody ( ) ;
127
-
73
+ needToBuildTable = true ;
128
74
}
129
75
130
76
@@ -135,12 +81,16 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
135
81
}
136
82
else {
137
83
$scope . error = JSON . stringify ( data ) ;
138
- $scope . scrollId = null ;
84
+ $scope . scrollId = undefined ;
139
85
}
140
86
} )
141
87
. finally ( function ( ) {
142
88
$scope . nextLoading = false ;
143
- $scope . $apply ( )
89
+ $scope . $apply ( ) ;
90
+ if ( needToBuildTable ) {
91
+ tablePresenter . createOrReplace ( $scope . resultsColumns , $scope . resultsRows ) ;
92
+ }
93
+
144
94
} ) ;
145
95
146
96
}
@@ -154,12 +104,12 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
154
104
$scope . resultsColumns = [ ] ;
155
105
$scope . resultsRows = [ ] ;
156
106
$scope . searchLoading = true ;
157
- $scope . $apply ( ) ;
107
+
158
108
$scope . resultExplan = false ;
159
-
109
+ $scope . $apply ( ) ;
160
110
saveUrl ( )
161
111
162
- var query = window . editor . getValue ( ) ;
112
+ var query = window . editor . getValue ( ) ;
163
113
164
114
$http . post ( $scope . url + "_sql" , query )
165
115
. success ( function ( data , status , headers , config ) {
@@ -185,6 +135,7 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
185
135
else {
186
136
$scope . resultsColumns = handler . getHead ( ) ;
187
137
$scope . resultsRows = handler . getBody ( ) ;
138
+
188
139
}
189
140
}
190
141
} )
@@ -198,7 +149,11 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
198
149
} )
199
150
. finally ( function ( ) {
200
151
$scope . searchLoading = false ;
201
- $scope . $apply ( )
152
+ $scope . $apply ( ) ;
153
+ if ( $scope . resultsColumns . length > 0 ) {
154
+ tablePresenter . createOrReplace ( $scope . resultsColumns , $scope . resultsRows ) ;
155
+ }
156
+
202
157
} ) ;
203
158
}
204
159
@@ -247,6 +202,82 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
247
202
return true ;
248
203
}
249
204
205
+ $scope . onChangeTablePresnterType = function ( ) {
206
+ //value = ?
207
+ value = $scope . useOldTable ;
208
+ tablePresenter . destroy ( ) ;
209
+ tablePresenter . changeTableType ( value , $compile , $scope ) ;
210
+ }
211
+
212
+ function searchTillEndAndExportCsv ( scrollId ) {
213
+ //todo: get total amount show fetched/total
214
+ head = [ ]
215
+ body = [ ]
216
+ $scope . showResults = true ;
217
+ callScrollAndFillBodyTillEnd ( scrollId , head , body , true ) ;
218
+ }
219
+ function updateDescription ( handler ) {
220
+ total = handler . getTotal ( ) ;
221
+ fetched += handler . getCurrentHitsSize ( ) ;
222
+ if ( total == undefined ) {
223
+ $scope . amountDescription = fetched
224
+ }
225
+ else {
226
+ $scope . amountDescription = fetched + "/" + total
227
+ }
228
+ }
229
+ function callScrollAndFillBodyTillEnd ( scrollId , head , body , firstTime ) {
230
+ var url = $scope . url + scroll_url + scrollId ;
231
+ $http . get ( url )
232
+ . success ( function ( data , status , headers , config ) {
233
+
234
+ var handler = ResultHandlerFactory . create ( data , $scope . isFlat ) ;
235
+
236
+ updateDescription ( handler ) ;
237
+ recieved = handler . getBody ( )
238
+ if ( body . length > 0 ) {
239
+ body = body . concat ( recieved ) ;
240
+ //todo: extend head?
241
+ head = handler . getHead ( ) ;
242
+ }
243
+ else {
244
+ body = recieved ;
245
+ head = handler . getHead ( ) ;
246
+
247
+ }
248
+ if ( recieved == undefined || recieved . length == undefined || recieved . length == 0 ) {
249
+ if ( firstTime ) {
250
+ callScrollAndFillBodyTillEnd ( handler . getScrollId ( ) , head , body , false ) ;
251
+ }
252
+ else {
253
+ exportCSVWithoutScope ( head , body ) ;
254
+ }
255
+ }
256
+ else {
257
+ callScrollAndFillBodyTillEnd ( handler . getScrollId ( ) , head , body , false ) ;
258
+ }
259
+
260
+
261
+ } )
262
+ . error ( function ( data , status , headers , config ) {
263
+ if ( data == "" ) {
264
+ $scope . error = "Error occured! response is not avalible." ;
265
+ }
266
+ else {
267
+ $scope . error = JSON . stringify ( data ) ;
268
+ $scope . scrollId = undefined ;
269
+ }
270
+ } )
271
+ . finally ( function ( ) {
272
+ $scope . nextLoading = false ;
273
+ $scope . $apply ( )
274
+ } ) ;
275
+
276
+
277
+ // body...
278
+ }
279
+
280
+
250
281
251
282
$scope . exportCSV = function ( ) {
252
283
var columns = $scope . resultsColumns ;
0 commit comments