Add ability to export table to JSON and XML
This commit is contained in:
@@ -197,7 +197,9 @@
|
||||
</div>
|
||||
<div id="tables_context_menu">
|
||||
<ul class="dropdown-menu" role="menu">
|
||||
<li><a href="#" data-action="export">Export to CSV</a></li>
|
||||
<li><a href="#" data-action="export" data-format="json">Export to JSON</a></li>
|
||||
<li><a href="#" data-action="export" data-format="csv">Export to CSV</a></li>
|
||||
<li><a href="#" data-action="export" data-format="xml">Export to XML</a></li>
|
||||
<li class="divider"></li>
|
||||
<li><a href="#" data-action="truncate">Truncate table</a></li>
|
||||
<li><a href="#" data-action="delete">Delete table</a></li>
|
||||
|
||||
@@ -84,7 +84,7 @@ function resetTable() {
|
||||
removeClass("no-crop");
|
||||
}
|
||||
|
||||
function performTableAction(table, action) {
|
||||
function performTableAction(table, action, el) {
|
||||
if (action == "truncate" || action == "delete") {
|
||||
var message = "Are you sure you want to " + action + " table " + table + " ?";
|
||||
if (!confirm(message)) return;
|
||||
@@ -106,10 +106,11 @@ function performTableAction(table, action) {
|
||||
});
|
||||
break;
|
||||
case "export":
|
||||
var filename = table + ".csv"
|
||||
var format = el.data("format");
|
||||
var filename = table + "." + format;
|
||||
var query = window.encodeURI("SELECT * FROM " + table);
|
||||
var url = "http://" + window.location.host + "/api/query?format=csv&filename=" + filename + "&query=" + query;
|
||||
var win = window.open(url, "_blank");
|
||||
var url = "http://" + window.location.host + "/api/query?format=" + format + "&filename=" + filename + "&query=" + query;
|
||||
var win = window.open(url, "_blank");
|
||||
win.focus();
|
||||
break;
|
||||
}
|
||||
@@ -583,9 +584,10 @@ $(document).ready(function() {
|
||||
target: "#tables_context_menu",
|
||||
scopes: "li",
|
||||
onItem: function(context, e) {
|
||||
var el = $(e.target);
|
||||
var table = $.trim($(context[0]).text());
|
||||
var action = $(e.target).data("action");
|
||||
performTableAction(table, action);
|
||||
var action = el.data("action");
|
||||
performTableAction(table, action, el);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user