Add ability to export query results to JSON
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -61,7 +61,8 @@
|
|||||||
<div class="actions">
|
<div class="actions">
|
||||||
<input type="button" id="run" value="Run Query" class="btn btn-sm btn-primary" />
|
<input type="button" id="run" value="Run Query" class="btn btn-sm btn-primary" />
|
||||||
<input type="button" id="explain" value="Explain Query" class="btn btn-sm btn-default" />
|
<input type="button" id="explain" value="Explain Query" class="btn btn-sm btn-default" />
|
||||||
<input type="button" id="csv" value="Download CSV" class="btn btn-sm btn-default" />
|
<input type="button" id="csv" value="CSV" class="btn btn-sm btn-default" />
|
||||||
|
<input type="button" id="json" value="JSON" class="btn btn-sm btn-default" />
|
||||||
|
|
||||||
<div id="query_progress">Please wait, query is executing...</div>
|
<div id="query_progress">Please wait, query is executing...</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -316,13 +316,13 @@ function showActivityPanel() {
|
|||||||
function runQuery() {
|
function runQuery() {
|
||||||
setCurrentTab("table_query");
|
setCurrentTab("table_query");
|
||||||
|
|
||||||
$("#run, #explain, #csv").prop("disabled", true);
|
$("#run, #explain, #csv, #json").prop("disabled", true);
|
||||||
$("#query_progress").show();
|
$("#query_progress").show();
|
||||||
|
|
||||||
var query = $.trim(editor.getSelectedText() || editor.getValue());
|
var query = $.trim(editor.getSelectedText() || editor.getValue());
|
||||||
|
|
||||||
if (query.length == 0) {
|
if (query.length == 0) {
|
||||||
$("#run, #explain, #csv").prop("disabled", false);
|
$("#run, #explain, #csv, #json").prop("disabled", false);
|
||||||
$("#query_progress").hide();
|
$("#query_progress").hide();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -330,7 +330,7 @@ function runQuery() {
|
|||||||
executeQuery(query, function(data) {
|
executeQuery(query, function(data) {
|
||||||
buildTable(data);
|
buildTable(data);
|
||||||
|
|
||||||
$("#run, #explain, #csv").prop("disabled", false);
|
$("#run, #explain, #csv, #json").prop("disabled", false);
|
||||||
$("#query_progress").hide();
|
$("#query_progress").hide();
|
||||||
$("#input").show();
|
$("#input").show();
|
||||||
$("#output").removeClass("full");
|
$("#output").removeClass("full");
|
||||||
@@ -352,13 +352,13 @@ function runQuery() {
|
|||||||
function runExplain() {
|
function runExplain() {
|
||||||
setCurrentTab("table_query");
|
setCurrentTab("table_query");
|
||||||
|
|
||||||
$("#run, #explain, #csv").prop("disabled", true);
|
$("#run, #explain, #csv, #json").prop("disabled", true);
|
||||||
$("#query_progress").show();
|
$("#query_progress").show();
|
||||||
|
|
||||||
var query = $.trim(editor.getValue());
|
var query = $.trim(editor.getValue());
|
||||||
|
|
||||||
if (query.length == 0) {
|
if (query.length == 0) {
|
||||||
$("#run, #explain, #csv").prop("disabled", false);
|
$("#run, #explain, #csv, #json").prop("disabled", false);
|
||||||
$("#query_progress").hide();
|
$("#query_progress").hide();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -366,7 +366,7 @@ function runExplain() {
|
|||||||
explainQuery(query, function(data) {
|
explainQuery(query, function(data) {
|
||||||
buildTable(data);
|
buildTable(data);
|
||||||
|
|
||||||
$("#run, #explain, #csv").prop("disabled", false);
|
$("#run, #explain, #csv, #json").prop("disabled", false);
|
||||||
$("#query_progress").hide();
|
$("#query_progress").hide();
|
||||||
$("#input").show();
|
$("#input").show();
|
||||||
$("#output").removeClass("full");
|
$("#output").removeClass("full");
|
||||||
@@ -374,14 +374,14 @@ function runExplain() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function exportToCSV() {
|
function exportTo(format) {
|
||||||
var query = $.trim(editor.getValue());
|
var query = $.trim(editor.getValue());
|
||||||
|
|
||||||
if (query.length == 0) {
|
if (query.length == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var url = "http://" + window.location.host + "/api/query?format=csv&query=" + encodeQuery(query);
|
var url = "http://" + window.location.host + "/api/query?format=" + format + "&query=" + encodeQuery(query);
|
||||||
var win = window.open(url, '_blank');
|
var win = window.open(url, '_blank');
|
||||||
|
|
||||||
setCurrentTab("table_query");
|
setCurrentTab("table_query");
|
||||||
@@ -524,9 +524,13 @@ $(document).ready(function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$("#csv").on("click", function() {
|
$("#csv").on("click", function() {
|
||||||
exportToCSV();
|
exportTo("csv");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("#json").on("click", function() {
|
||||||
|
exportTo("json");
|
||||||
|
})
|
||||||
|
|
||||||
$("#results").on("click", "tr", function() {
|
$("#results").on("click", "tr", function() {
|
||||||
$("#results tr.selected").removeClass();
|
$("#results tr.selected").removeClass();
|
||||||
$(this).addClass("selected");
|
$(this).addClass("selected");
|
||||||
|
|||||||
Reference in New Issue
Block a user