Merge pull request #83 from benjamin-thomas/sort-columns

Sort columns
This commit is contained in:
Dan Sosedoff 2015-04-09 08:34:31 -05:00
commit 7606a88293
2 changed files with 70 additions and 27 deletions

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@ var bookmarks = {};
function apiCall(method, path, params, cb) { function apiCall(method, path, params, cb) {
$.ajax({ $.ajax({
url: "/api" + path, url: "/api" + path,
method: method, method: method,
cache: false, cache: false,
data: params, data: params,
@ -68,7 +68,18 @@ function resetTable() {
removeClass("no-crop"); removeClass("no-crop");
} }
function buildTable(results) { function sortArrow(direction) {
switch (direction) {
case "ASC":
return "▲";
case "DESC":
return "▼";
default:
return "";
}
}
function buildTable(results, sortColumn, sortOrder) {
resetTable(); resetTable();
if (results.error) { if (results.error) {
@ -87,7 +98,11 @@ function buildTable(results) {
var rows = ""; var rows = "";
results.columns.forEach(function(col) { results.columns.forEach(function(col) {
cols += "<th data='" + col + "'>" + col + "</th>"; if (col === sortColumn) {
cols += "<th data='" + col + "'" + "data-sort-order=" + sortOrder + ">" + col + "&nbsp;" + sortArrow(sortOrder) + "</th>";
} else {
cols += "<th data='" + col + "'>" + col + "</th>";
}
}); });
results.rows.forEach(function(row) { results.rows.forEach(function(row) {
@ -113,8 +128,8 @@ function showQueryHistory() {
} }
buildTable({ columns: ["id", "query", "timestamp"], rows: rows }); buildTable({ columns: ["id", "query", "timestamp"], rows: rows });
setCurrentTab("table_history"); setCurrentTab("table_history");
$("#input").hide(); $("#input").hide();
$("#output").addClass("full"); $("#output").addClass("full");
$("#results").addClass("no-crop"); $("#results").addClass("no-crop");
@ -157,7 +172,7 @@ function showTableInfo() {
}); });
} }
function showTableContent() { function showTableContent(sortColumn, sortOrder) {
var name = getCurrentTable(); var name = getCurrentTable();
if (name.length == 0) { if (name.length == 0) {
@ -165,8 +180,8 @@ function showTableContent() {
return; return;
} }
getTableRows(name, { limit: 100 }, function(data) { getTableRows(name, { limit: 100, sort_column: sortColumn, sort_order: sortOrder }, function(data) {
buildTable(data); buildTable(data, sortColumn, sortOrder);
setCurrentTab("table_content"); setCurrentTab("table_content");
$("#results").attr("data-mode", "browse"); $("#results").attr("data-mode", "browse");
@ -433,6 +448,23 @@ $(document).ready(function() {
$(this).addClass("selected"); $(this).addClass("selected");
}); });
$("#results").on("click", "th", function(e) {
var sortColumn = this.attributes['data'].value;
var contentTab = $('#table_content').hasClass('selected');
if (!contentTab) {
return;
}
if (this.dataset.sortOrder === "ASC") {
this.dataset.sortOrder = "DESC"
} else {
this.dataset.sortOrder = "ASC"
}
showTableContent(sortColumn, this.dataset.sortOrder);
});
$("#results").on("dblclick", "td > div", function() { $("#results").on("dblclick", "td > div", function() {
if ($(this).has("textarea").length > 0) { if ($(this).has("textarea").length > 0) {
return; return;
@ -544,7 +576,7 @@ $(document).ready(function() {
var button = $(this).children("button"); var button = $(this).children("button");
var url = getConnectionString(); var url = getConnectionString();
if (url.length == 0) { if (url.length == 0) {
return; return;
} }
@ -572,7 +604,7 @@ $(document).ready(function() {
initEditor(); initEditor();
addShortcutTooltips(); addShortcutTooltips();
apiCall("get", "/connection", {}, function(resp) { apiCall("get", "/connection", {}, function(resp) {
if (resp.error) { if (resp.error) {
connected = false; connected = false;
@ -586,4 +618,4 @@ $(document).ready(function() {
$("#main").show(); $("#main").show();
} }
}); });
}); });