Skip to content

Commit 9f71fbb

Browse files
committed
Merge pull request NLPchina#104 from ottboy4/master
Added the plugin version to display on the sql UI
2 parents aacb4ad + 04b84a8 commit 9f71fbb

File tree

4 files changed

+62
-32
lines changed

4 files changed

+62
-32
lines changed

pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@
114114

115115

116116
<build>
117+
<resources>
118+
<resource>
119+
<directory>src/main/resources</directory>
120+
<filtering>true</filtering>
121+
<includes>
122+
<include>es-plugin.properties</include>
123+
</includes>
124+
</resource>
125+
</resources>
126+
117127
<plugins>
118128
<plugin>
119129
<artifactId>maven-compiler-plugin</artifactId>

src/_site/controllers.js

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var elasticsearchSqlApp = angular.module('elasticsearchSqlApp', ["ngAnimate", "n
33

44
elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce) {
55
$scope.url = getUrl();
6-
$scope.error = "";
6+
$scope.error = "";
77
$scope.resultsColumns = [];
88
$scope.resultsRows = [];
99
$scope.searchLoading = false;
@@ -13,6 +13,18 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
1313
$scope.scrollId = null;
1414
$scope.gotNext = false;
1515

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+
1628
$scope.nextSearch = function(){
1729
$scope.error = "";
1830
$scope.nextLoading = true;
@@ -28,11 +40,11 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
2840
.success(function(data, status, headers, config) {
2941
var handler = ResultHandlerFactory.create(data);
3042
var body = handler.getBody()
31-
43+
3244
if(body.length ==null || body.length == 0){
3345
$scope.gotNext=false;
3446
}
35-
else
47+
else
3648
{
3749
$scope.scrollId = handler.getScrollId();
3850
}
@@ -43,12 +55,12 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
4355
else {
4456
$scope.resultsColumns = handler.getHead();
4557
$scope.resultsRows = handler.getBody();
46-
58+
4759
}
4860

49-
61+
5062
})
51-
.error(function(data, status, headers, config) {
63+
.error(function(data, status, headers, config) {
5264
if(data == "") {
5365
$scope.error = "Error occured! response is not avalible.";
5466
}
@@ -59,7 +71,7 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
5971
})
6072
.finally(function() {
6173
$scope.nextLoading = false;
62-
$scope.$apply()
74+
$scope.$apply()
6375
});
6476

6577
}
@@ -86,9 +98,9 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
8698
}
8799
$scope.resultsColumns = handler.getHead();
88100
$scope.resultsRows = handler.getBody();
89-
101+
90102
})
91-
.error(function(data, status, headers, config) {
103+
.error(function(data, status, headers, config) {
92104
if(data == "") {
93105
$scope.error = "Error occured! response is not avalible.";
94106
}
@@ -98,10 +110,10 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
98110
})
99111
.finally(function() {
100112
$scope.searchLoading = false;
101-
$scope.$apply()
113+
$scope.$apply()
102114
});
103115
}
104-
116+
105117
$scope.explain = function() {
106118
// Reset results and error box
107119
$scope.error = "";
@@ -119,7 +131,7 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
119131
$scope.resultExplan = true;
120132
window.explanResult.setValue(JSON.stringify(data, null, "\t"));
121133
})
122-
.error(function(data, status, headers, config) {
134+
.error(function(data, status, headers, config) {
123135
$scope.resultExplan = false;
124136
if(data == "") {
125137
$scope.error = "Error occured! response is not avalible.";
@@ -130,44 +142,44 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
130142
})
131143
.finally(function() {
132144
$scope.explainLoading = false;
133-
$scope.$apply()
145+
$scope.$apply()
134146
});
135147
}
136-
137-
138-
139-
$scope.exportCSV = function() {
148+
149+
150+
151+
$scope.exportCSV = function() {
140152
var columns = $scope.resultsColumns ;
141153
var rows = $scope.resultsRows ;
142154
var data =arr2csvStr(columns,',') ;
143155
for(var i=0; i<rows.length ; i++){
144156
data += "\n";
145157
data += map2csvStr(columns,rows[i],',') ;
146-
158+
147159
}
148160
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;
151163
}
152164

153165
$scope.getButtonContent = function(isLoading , defName) {
154166
var loadingContent = "<span class=\"glyphicon glyphicon-refresh glyphicon-refresh-animate\"></span> Loading...";
155167
var returnValue = isLoading ? loadingContent : defName;
156168
return $sce.trustAsHtml(returnValue);
157169
}
158-
159-
170+
171+
160172
function arr2csvStr(arr,op){
161-
var data = arr[0];
173+
var data = arr[0];
162174
for(var i=1; i<arr.length ; i++){
163175
data += op;
164176
data += arr[i] ;
165177
}
166178
return data ;
167179
}
168-
180+
169181
function map2csvStr(columns,arr,op){
170-
var data = JSON.stringify(arr[columns[0]]);
182+
var data = JSON.stringify(arr[columns[0]]);
171183
for(var i=1; i<columns.length ; i++){
172184
data += op;
173185
data += JSON.stringify(arr[columns[i]]) ;
@@ -186,7 +198,7 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
186198
url = location.protocol+'//' + location.hostname + (location.port ? ':'+location.port : '');
187199
}
188200
}
189-
201+
190202
if(url.substr(url.length - 1, 1) != '/') {
191203
url += '/'
192204
}
@@ -196,5 +208,5 @@ elasticsearchSqlApp.controller('MainController', function ($scope, $http, $sce)
196208

197209
function saveUrl() {
198210
localStorage.setItem("lasturl", $scope.url);
199-
}
211+
}
200212
});

src/_site/index.html

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,23 @@
2626
</div>
2727
<div id="navbar" class="navbar-collapse collapse">
2828
<ul class="nav navbar-nav navbar-right">
29-
29+
30+
<li ng-cloak>
31+
<a>{{version ? 'Version: ' + version : ''}}</a>
32+
</li>
33+
34+
<li>
35+
<form class="navbar-form">
36+
<input type="text" id="urlBox" class="form-control" ng-model="url" />
37+
</form>
38+
</li>
39+
3040
<li id="help_btn" data-toggle="modal" data-target="#help_popup">
3141
<a title="Help" href="#" data-placement="bottom">Help</a>
3242
</li>
3343

3444
</ul>
3545

36-
<form class="navbar-form navbar-right">
37-
<input type="text" id="urlBox" class="form-control" ng-model="url" />
38-
</form>
3946
</div>
4047
</div>
4148
</nav>
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
plugin=org.elasticsearch.plugin.nlpcn.SqlPlug
1+
plugin=org.elasticsearch.plugin.nlpcn.SqlPlug
2+
version=${project.version}

0 commit comments

Comments
 (0)