// --- BEGIN Global variables -----------------------------------
var rankedOnly = null; // Whether to adapt GUI to only show
// information related to rankings
var testCaseChecked = new Array();
// --- END Global variables -------------------------------------
function selectAllTestCases() {
$("#testCasesTable input").attr("checked", true);
updateActions();
}
function clearAllTestCases() {
$("#testCasesTable input").attr("checked", false);
updateActions();
}
function fetchTestCases() {
updateStatus("fetching matching test cases ...", true);
$("#div_matchingTestCases").css("display", "none");
context1_ = context1();
if (context1_ == null) {
updateStatus("fetching matching test cases ... done", false);
updateStatus("", false);
return;
}
context2_ = context2();
// Save current selection ...
$("#testCasesTable input").each(function() {
testCaseChecked[this.name] = this.checked;
});
query = "?db=" + $('#database').val();
if (context2_["host"] == "") {
query += "&cmd=testcases1";
query += "&host=" + encodeURIComponent(context1_["host"]);
query += "&platform=" + encodeURIComponent(context1_["platform"]);
query += "&branch=" + encodeURIComponent(context1_["branch"]);
query += "&sha1=" + context1_["sha1"];
} else {
query += "&cmd=testcases2";
query += "&host1=" + encodeURIComponent(context1_["host"]);
query += "&platform1=" + encodeURIComponent(context1_["platform"]);
query += "&branch1=" + encodeURIComponent(context1_["branch"]);
query += "&sha11=" + context1_["sha1"];
query += "&host2=" + encodeURIComponent(context2_["host"]);
query += "&platform2=" + encodeURIComponent(context2_["platform"]);
query += "&branch2=" + encodeURIComponent(context2_["branch"]);
query += "&sha12=" + context2_["sha1"];
}
url = "http://" + location.host + "/cgi-bin/getstatswrapper" + query;
// alert("url: >" + url + "<");
$.ajax({
url: url,
type: "GET",
dataType: "json",
success: function(data, textStatus, request) {
if (request.readyState == 4) {
if (request.status == 200) {
if (data.error != null) {
updateStatus(
"fetching matching test cases ... failed: " +
data.error, false);
return
}
updateStatus(
"fetching matching test cases ... done", false);
updateStatus("", false);
// Remove all rows ...
$("#testCasesTable tr").remove();
// Insert new rows ...
testCases = data.testcases;
html = "";
for (i = 0; i < testCases.length; ++i) {
testCase = testCases[i];
html += "
";
html += " | ";
html += " | ";
html += "" + context.host +
" | ";
html += "" + context.platform +
" | ";
html += "" + context.branch +
" | ";
html += "";
snapshots = context.snapshots;
firstUploadTime0 = snapshots[0][1];
secsAgo0 = currTime - firstUploadTime0;
ageColor0 = ageColor(secsAgo0);
html += "";
html +=" | ";
html += "
";
}
$("#contextsTable > tbody:last").append(html);
// Select the first context as Context 1 ...
$("#contextsTable td:first input").attr("checked", "true");
if (context1() == null)
$("#div_noMatchingContexts").css("display", "block");
highlightContextsTable();
updateActions();
$("#div_availableContexts").css("display", "block");
if (rankedOnly) {
// In contexts table, disable the 'Context 2' column:
$("#contextsTable th:eq(1)").remove();
$("#contextsTable td:nth-child(2)").remove();
}
fetchTestCases();
}
}
},
error: function(request, textStatus, errorThrown) {
descr = errorThrown;
if (errorThrown == null) {
descr = "undefined error - is the server down?";
}
updateStatus(
"fetching available contexts ... error: " + descr, false);
}
// complete: function(request, textStatus) {
// alert("complete; request.status: " + request.status)
// }
});
return false;
}
// Handles selecting another database.
function selectDatabase() {
fetchContexts();
}
function highlightContextsTable() {
// Unhighlight all selectable rows:
$("#contextsTable tr:has(input)").attr("class", "unselected");
// Highlight selected rows (prioritizing context 1):
$.each(["context2", "context1"], function(index, value) {
rows = $("#contextsTable tr:has(input[name='" + value +
"'][checked='true'])");
rows.attr("class", value);
});
// Highlight extra context 2 row (if any):
$("#extra_context2_row").attr("class", "context2");
}
// Handles clicking a context checkbox. Exactly one Context 1 and
// zero or one Context 2 must be selected at any time.
function clickContextCheckbox(cb, col) {
// Enforce selection invariant:
if (cb.checked) {
// Deselect all other checkboxes in this column
// (note: nth-child assumes 1-based indexes):
$("#contextsTable td:nth-child(" + (col + 1) + ") input")
.attr("checked", false);
cb.checked = true;
} else if ((col == 0)) {
// Prevent deselection by reselecting:
cb.checked = true;
}
// Check if the same host/platform/branch combination is selected for
// both contexts. If so, add an extra row below the selected row to enable
// selection of a different snapshot for the Context 2
// (unless such an extra row doesn't already exist):
index = cb.id.split(":")[1];
tr = $("#" + "context_row\\:" + index);
checked1 = tr.find("td:nth-child(1) input").attr("checked");
checked2 = tr.find("td:nth-child(2) input").attr("checked");
if (checked1 && checked2) {
if ($("#extra_context2_row").length == 0) {
// Get selected sha1:
sha1 = tr.find("select option:selected").attr("value");
// Append extra row:
tr.after(
"");
// Clone snapshots:
tr.find("#context_snapshots\\:" + index).clone().appendTo(
"#extra_context2_snapshots");
extraSelect = $("#extra_context2_snapshots select");
extraSelect.find("option[value = '" + sha1 + "']").attr(
"selected", true);
extraSelect.attr("onchange", ""); // This is needed!
extraSelect.change(function() {
selectExtraContext2Snapshot();
});
// Initialize selected snapshot color:
selectExtraContext2Snapshot(true);
}
} else {
// Remove any extra row:
trExtra = $("#extra_context2_row");
if (trExtra.length > 0) {
mainIndex = trExtra.attr("name");
trMain = $("#" + "context_row\\:" + mainIndex);
// If Context 2 is still selected for the main row,
// select the current snapshot of the main row as the one
// selected for the extra row before removing the latter:
if (trMain.find("td:nth-child(2) input").attr("checked")) {
// Get selected sha1 in extra row:
sha1 = trExtra.find("select option:selected").attr("value");
// Select this sha1 in the main row:
trMain.find("select option[value = '" + sha1 + "']").attr(
"selected", true);
// Initialize selected snapshot color:
selectContextSnapshot(parseInt(mainIndex));
}
trExtra.remove();
}
}
highlightContextsTable();
updateActions();
fetchTestCases();
}
$(document).ready(function() {
var args = queryStringArgs();
var rankedOnly_int = parseInt(extractArg(args, "rankedonly"));
rankedOnly = ((!isNaN(rankedOnly_int)) && (rankedOnly_int != 0))
if (rankedOnly) {
// In actions table, keep only header and rows related to
// 'Show rankings...' action:
$("#actionTable tr").css("display", "none");
$("#actionTable tr[id='actionTable_header']").css("display", "");
$("#actionTable tr[id*='rankings']").css("display", "");
}
// Set default action arguments:
$("#max_rank_size option[value='10']").attr("selected", true);
$("#diff_tol option[value='1.1']").attr("selected", true);
$("#dur_tol_min option[value='3']").attr("selected", true);
$("#dur_tol_max option[value='50']").attr("selected", true);
fetchContexts();
});