Skip to content

Commit c87d6fd

Browse files
committed
new table presenter! + date_histogram now shows key_as_string
1 parent db834ef commit c87d6fd

27 files changed

+17688
-91
lines changed

src/_site/controllers.js

Lines changed: 107 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11

22
var elasticsearchSqlApp = angular.module('elasticsearchSqlApp', ["ngAnimate", "ngSanitize"]);
33

4-
elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce) {
4+
elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce,$compile) {
55
scroll_url = "_search/scroll?scroll=1m&scroll_id=";
66
$scope.url = getUrl();
77
$scope.showResults = false;
88
$scope.error = "";
9-
$scope.resultsColumns = [];
9+
$scope.resultsColumns =[];
1010
$scope.resultsRows = [];
1111
$scope.searchLoading = false;
1212
$scope.explainLoading = false;
1313
$scope.nextLoading = false;
1414
$scope.resultExplan = false;
15-
$scope.scrollId = null;
15+
$scope.scrollId = undefined;
16+
$scope.amountDescription = "";
17+
var fetched = 0;
18+
var total = 0 ;
19+
//checkboxes
1620
$scope.gotNext = false;
21+
$scope.useOldTable = false;
1722
$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
2228
$http.get($scope.url).success(function (data) {
2329
$http.get($scope.url + "_nodes/" + data.name).success(function (nodeData) {
2430
var node = nodeData.nodes[Object.keys(nodeData.nodes)[0]];
@@ -30,73 +36,12 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
3036
});
3137
});
3238

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-
}
9539

9640
$scope.nextSearch = function(){
9741
$scope.error = "";
9842
$scope.nextLoading = true;
9943
$scope.$apply();
44+
var needToBuildTable = false;
10045

10146

10247
if($scope.scrollId == undefined || $scope.scrollId == "" ){
@@ -119,12 +64,13 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
11964
}
12065

12166
if($scope.resultsRows.length > 0){
67+
tablePresenter.addRows(handler.getBody());
12268
$scope.resultsRows = $scope.resultsRows.concat(handler.getBody());
12369
}
12470
else {
12571
$scope.resultsColumns = handler.getHead();
12672
$scope.resultsRows = handler.getBody();
127-
73+
needToBuildTable = true;
12874
}
12975

13076

@@ -135,12 +81,16 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
13581
}
13682
else {
13783
$scope.error = JSON.stringify(data);
138-
$scope.scrollId = null;
84+
$scope.scrollId = undefined;
13985
}
14086
})
14187
.finally(function() {
14288
$scope.nextLoading = false;
143-
$scope.$apply()
89+
$scope.$apply();
90+
if(needToBuildTable) {
91+
tablePresenter.createOrReplace($scope.resultsColumns,$scope.resultsRows);
92+
}
93+
14494
});
14595

14696
}
@@ -154,12 +104,12 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
154104
$scope.resultsColumns = [];
155105
$scope.resultsRows = [];
156106
$scope.searchLoading = true;
157-
$scope.$apply();
107+
158108
$scope.resultExplan = false;
159-
109+
$scope.$apply();
160110
saveUrl()
161111

162-
var query = window.editor.getValue();
112+
var query = window.editor.getValue();
163113

164114
$http.post($scope.url + "_sql", query)
165115
.success(function(data, status, headers, config) {
@@ -185,6 +135,7 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
185135
else {
186136
$scope.resultsColumns = handler.getHead();
187137
$scope.resultsRows = handler.getBody();
138+
188139
}
189140
}
190141
})
@@ -198,7 +149,11 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
198149
})
199150
.finally(function() {
200151
$scope.searchLoading = false;
201-
$scope.$apply()
152+
$scope.$apply();
153+
if($scope.resultsColumns.length >0){
154+
tablePresenter.createOrReplace($scope.resultsColumns,$scope.resultsRows);
155+
}
156+
202157
});
203158
}
204159

@@ -247,6 +202,82 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
247202
return true;
248203
}
249204

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+
250281

251282
$scope.exportCSV = function() {
252283
var columns = $scope.resultsColumns ;

src/_site/index.html

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
<!-- Bootstrap core CSS -->
1313
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
1414
<link href="style.css" rel="stylesheet">
15-
15+
<link rel="stylesheet" type="text/css" href="vendor/dataTables/css/jquery.dataTables.min.css"/>
16+
1617
</head>
1718

1819
<body ng-app="elasticsearchSqlApp" ng-controller="MainController">
@@ -108,8 +109,12 @@ <h3> Options </h3>
108109
<label><input type="checkbox" ng-model="isFlat" value="">Flat</label>
109110
</div>
110111
<div class="checkbox">
111-
<label><input type="checkbox" ng-model="isAutoSave" value="">AutoSave</label>
112+
<label><input type="checkbox" ng-model="useOldTable" ng-change="onChangeTablePresnterType()" value="">useOldTable</label>
113+
</div>
114+
<div class="checkbox">
115+
<label><input type="checkbox" ng-model="isAutoSave" value="">AutoExportCSV</label>
112116
</div>
117+
113118
<div class="">
114119
<label class="delimiterLable" >delimiter<input type="text" class="delimiter" name="delimiterText" ng-model="delimiter" maxlength="1" value="," /></label>
115120

@@ -120,15 +125,16 @@ <h1 class="page-header">SQL Query</h1>
120125

121126
<!-- Query area -->
122127
<div class="search-area">
123-
<textarea id="queryTextarea">SELECT * FROM myindex</textarea>
128+
<textarea id="queryTextarea">SELECT * FROM sql_test</textarea>
124129
<button type="button" ng-click="search()" id="searchButton" class="btn btn-success search-button" ng-bind-html="getButtonContent(searchLoading,'Search')" ng-cloak>
125130
</button>
126131

127132
<button type="button" ng-click="explain()" id="explainButton" class="btn btn-info explain-button" ng-bind-html="getButtonContent(explainLoading,'Explain')" ng-cloak>
128133
</button>
129-
130-
<button type="next" ng-click="nextSearch()" id="nextButton" class="btn btn-warning next-button" ng-show="gotNext" ng-bind-html="getButtonContent(nextLoading,'Next')" ng-cloak>
134+
<button type="next" ng-click="nextSearch()" id="nextButton" class="btn btn-warning next-button" ng-disabled="!gotNext" ng-bind-html="getButtonContent(nextLoading,'Scroll <span class=\'glyphicon glyphicon-cloud-download\'></span>')" ng-cloak>
131135
</button>
136+
<button type="button" ng-click="exportCSV()" id="exportCSV" class="btn btn-primary " ng-cloak>Export CSV <span class="glyphicon glyphicon-share"></span></button>
137+
132138
</div>
133139

134140
<!-- Error box, displayed only on errors -->
@@ -141,12 +147,12 @@ <h1 class="page-header">SQL Query</h1>
141147
<!-- Results area, displayed after search -->
142148
<div class="fadein" ng-show="resultsColumns.length > 0 || showResults" ng-cloak>
143149
<div>
144-
<h2 class="sub-header">Results {{amountDescription}}</h2>
150+
<h2 class="sub-header">Results ({{amountDescription}})</h2>
145151
</div>
146152

147-
<div class="table-responsive">
153+
<div class="table-responsive" id ="searchResultZone">
148154
<table class="table table-striped" id="searchResult">
149-
<thead>
155+
<!-- <thead>
150156
<tr id="tableHead">
151157
<th ng-repeat="column in resultsColumns">{{column}}</th>
152158
</tr>
@@ -157,11 +163,11 @@ <h2 class="sub-header">Results {{amountDescription}}</h2>
157163
{{row[column]}}
158164
</td>
159165
</tr>
160-
</tbody>
166+
</tbody> -->
161167
</table>
162168
</div>
163169

164-
<button type="button" ng-click="exportCSV()" id="exportCSV" class="btn btn-primary btn-sm" ng-cloak>Export CSV <span class="glyphicon glyphicon-share"></span></button>
170+
165171
</div>
166172

167173
<!-- explan area , displayed after explan -->
@@ -181,9 +187,11 @@ <h2 class="sub-header">Results</h2>
181187

182188
<!-- Jquery include -->
183189
<script src="vendor/jquery/jquery-2.1.1.min.js"></script>
190+
184191

185192
<!-- Bootstrap core JavaScript -->
186-
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
193+
<script src="vendor/dataTables/js/jquery.dataTables.min.js"></script>
194+
187195

188196
<!-- CodeMirror includes -->
189197
<script src="vendor/codemirror/lib/codemirror.js"></script>
@@ -199,10 +207,12 @@ <h2 class="sub-header">Results</h2>
199207
<script src="vendor/angularjs/angular.min.js"></script>
200208
<script src="vendor/angularjs/angular-animate.min.js"></script>
201209
<script src="vendor/angularjs/angular-sanitize.min.js"></script>
210+
202211

203-
212+
<script src="table_presenter.js"></script>
204213
<script src="editor.js"></script>
205214
<script src="mapping_parser.js"></script>
215+
206216
<script src="query.js"></script>
207217
<script src="controllers.js"></script>
208218

0 commit comments

Comments
 (0)