Skip to content

Commit

Permalink
Add sticky headers, sorting to task table in web UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Raghav Sethi committed Jan 15, 2016
1 parent c0e32e0 commit 91f135d
Show file tree
Hide file tree
Showing 5 changed files with 523 additions and 30 deletions.
72 changes: 42 additions & 30 deletions presto-main/src/main/resources/webapp/query.html
Expand Up @@ -3,8 +3,13 @@
<meta charset="utf-8">

<script src="vendor/d3/d3-3.3.4.js"></script>
<script src="vendor/jquery/jquery-1.11.1.min.js"></script>
<script src="vendor/stickytableheaders/jquery.stickytableheaders.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.js"></script>
<script src="vendor/bootstrap-sortable/bootstrap-sortable.js"></script>

<link href="vendor/bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css">
<link href="vendor/bootstrap-sortable/bootstrap-sortable.css" rel="stylesheet" type="text/css">

<link rel="stylesheet" href="vendor/highlightjs/7.3/styles/idea.min.css">
<script src="vendor/highlightjs/7.3/highlight.min.js"></script>
Expand Down Expand Up @@ -32,6 +37,16 @@
stroke-width: 1.5px;
}

#tasks th {
background-color: #fff;
padding-left: 15px;
padding-right: 10px;
}

#tasks td {
padding-left: 15px;
}

#tasks td:nth-child(4),
#tasks td:nth-child(5),
#tasks td:nth-child(6),
Expand Down Expand Up @@ -142,10 +157,10 @@ <h2>Stages</h2>

<h2>Tasks</h2>

<table id="tasks" class="table table-striped">
<table id="tasks" class="table table-striped sortable">
<thead>
<tr>
<th>Id</th>
<th data-defaultsort="asc">Id</th>
<th>Host</th>
<th>State</th>
<th>Rows</th>
Expand Down Expand Up @@ -265,7 +280,9 @@ <h2>Tasks</h2>

renderStagesTree(query.outputStage);

renderTable('tasks', getTasks(query.outputStage).sort(taskIdComparator));
renderTable('tasks', getTasks(query.outputStage));
$.bootstrapSortable(applyLast=true);
$('#tasks').stickyTableHeaders();
});

function formatStackTrace(info) {
Expand Down Expand Up @@ -334,20 +351,10 @@ <h2>Tasks</h2>
return id
}

function taskIdComparator(a, b) {
a = a[0].split('.').map(parseFloat);
b = b[0].split('.').map(parseFloat);
return numericArrayComparator(a, b);
}

function numericArrayComparator(a, b) {
for (var i = 0; (i < a.length) && (i < b.length); i++) {
if (a[i] < b[i]) return -1;
if (a[i] > b[i]) return 1;
}
if (a.length < b.length) return -1;
if (a.length > b.length) return 1;
return 0;
function taskIdToSortableString(id) {
var taskIdArr = removeQueryId(id).split(".");
var maxLength = Number.MAX_VALUE.toString().length + 1;
return taskIdArr.map(numStr => new Array(maxLength - numStr.length).join("0") + numStr).join(".");
}

function getTasks(stage) {
Expand All @@ -370,18 +377,18 @@ <h2>Tasks</h2>
});

return [
"<a href=" + d.self + "?pretty>" + htmlEscape(d.taskId) + "</a>",
htmlEscape(urlHostname(d.self)),
htmlEscape(formatState(d.state, d.stats.fullyBlocked)),
htmlEscape(formatCount(rows)),
htmlEscape(formatCount(computeRate(rows, elapsed))),
htmlEscape(formatDataSize(bytes)),
htmlEscape(formatDataSize(computeRate(bytes, elapsed))),
htmlEscape(d.stats.queuedDrivers),
htmlEscape(d.stats.runningDrivers),
htmlEscape(d.stats.completedDrivers),
htmlEscape(finishedBuffers + ' / ' + allBuffers),
htmlEscape(bufferedPages)
{"display": "<a href=" + d.self + "?pretty>" + htmlEscape(d.taskId) + "</a>", "sortableString": taskIdToSortableString(d.taskId)},
{"display": htmlEscape(urlHostname(d.self))},
{"display": htmlEscape(formatState(d.state, d.stats.fullyBlocked))},
{"display": htmlEscape(formatCount(rows)), "sortableString": rows},
{"display": htmlEscape(formatCount(computeRate(rows, elapsed))), "sortableString": computeRate(rows, elapsed)},
{"display": htmlEscape(formatDataSize(bytes)), "sortableString": bytes},
{"display": htmlEscape(formatDataSize(computeRate(bytes, elapsed))), "sortableString": computeRate(bytes, elapsed)},
{"display": htmlEscape(d.stats.queuedDrivers)},
{"display": htmlEscape(d.stats.runningDrivers)},
{"display": htmlEscape(d.stats.completedDrivers)},
{"display": htmlEscape(finishedBuffers + ' / ' + allBuffers)},
{"display": htmlEscape(bufferedPages)}
];
}

Expand Down Expand Up @@ -540,7 +547,12 @@ <h2>Tasks</h2>
.enter()
.append("td")
.html(function (d) {
return d;
return d["display"]
})
.attr("data-value", function(d) {
if ("sortableString" in d) {
return d["sortableString"];
}
});
}

Expand Down
@@ -0,0 +1,123 @@
/*
Copyright (c) 2013 Matúš Brliť (drvic10k), bootstrap-sortable contributors
Copyright (c) 2011-2013 Tim Wood, Iskren Chernev, Moment.js contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

table.sortable span.sign {
display: block;
position: absolute;
top: 50%;
left: 0px;
font-size: 12px;
margin-top: -10px;
color: #bfbfc1;
}

table.sortable th:after {
display: block;
position: absolute;
top: 50%;
right: 5px;
font-size: 12px;
margin-top: -10px;
color: #bfbfc1;
}

table.sortable th.arrow:after {
content: '';
}

table.sortable span.arrow, span.reversed, th.arrow.down:after, th.reversedarrow.down:after, th.arrow.up:after, th.reversedarrow.up:after {
border-style: solid;
border-width: 5px;
font-size: 0;
border-color: #ccc transparent transparent transparent;
line-height: 0;
height: 0;
width: 0;
margin-top: 8px;
}

table.sortable span.arrow.up, th.arrow.up:after {
border-color: transparent transparent #ccc transparent;
margin-top: 2px;
}

table.sortable span.reversed, th.reversedarrow.down:after {
border-color: transparent transparent #ccc transparent;
margin-top: -7px;
}

table.sortable span.reversed.up, th.reversedarrow.up:after {
border-color: #ccc transparent transparent transparent;
margin-top: -2px;
}

table.sortable span.az:before, th.az.down:after {
content: "a .. z";
}

table.sortable span.az.up:before, th.az.up:after {
content: "z .. a";
}

table.sortable th.az.nosort:after, th.AZ.nosort:after, th._19.nosort:after, th.month.nosort:after {
content: "..";
}

table.sortable span.AZ:before, th.AZ.down:after {
content: "A .. Z";
}

table.sortable span.AZ.up:before, th.AZ.up:after {
content: "Z .. A";
}

table.sortable span._19:before, th._19.down:after {
content: "1 .. 9";
}

table.sortable span._19.up:before, th._19.up:after {
content: "9 .. 1";
}

table.sortable span.month:before, th.month.down:after {
content: "jan .. dec";
}

table.sortable span.month.up:before, th.month.up:after {
content: "dec .. jan";
}

table.sortable>thead th:not([data-defaultsort=disabled]) {
cursor: pointer;
position: relative;
top: 0;
left: 0;
}

table.sortable>thead th:hover:not([data-defaultsort=disabled]) {
background: #efefef;
}

table.sortable>thead th div.mozilla {
position: relative;
}

0 comments on commit 91f135d

Please sign in to comment.