summaryrefslogtreecommitdiff
path: root/coverage/htmlfiles
diff options
context:
space:
mode:
authorDanny Allen <danny.allen@pennantplc.co.uk>2014-09-22 12:05:15 +0100
committerDanny Allen <danny.allen@pennantplc.co.uk>2014-09-22 12:05:15 +0100
commit3587bb6df97533fce78553c480c737bd79164520 (patch)
treec9490e33595f4ac743ceff3bb2eaedb6cc830639 /coverage/htmlfiles
parent8ec6f58369a6c956677c4391fd37156a7f8f72bf (diff)
downloadpython-coveragepy-3587bb6df97533fce78553c480c737bd79164520.tar.gz
Address comments from pull request 34 (https://bitbucket.org/ned/coveragepy/pull-request/34/rework-of-my-pull-request-18/diff):
* Remove fixed header and header buttons in file details page. * Add dynamically summing footer values.
Diffstat (limited to 'coverage/htmlfiles')
-rw-r--r--coverage/htmlfiles/coverage_html.js173
-rw-r--r--coverage/htmlfiles/pyfile.html6
-rw-r--r--coverage/htmlfiles/style.css22
3 files changed, 77 insertions, 124 deletions
diff --git a/coverage/htmlfiles/coverage_html.js b/coverage/htmlfiles/coverage_html.js
index fdee551..88a0cd8 100644
--- a/coverage/htmlfiles/coverage_html.js
+++ b/coverage/htmlfiles/coverage_html.js
@@ -4,7 +4,7 @@
coverage = {};
-// Find all the elements with shortkey_* class, and use them to assign a shotrtcut key.
+// Find all the elements with shortkey_* class, and use them to assign a shortcut key.
coverage.assign_shortkeys = function () {
$("*[class*='shortkey_']").each(function (i, e) {
$.each($(e).attr("class").split(" "), function (i, c) {
@@ -37,27 +37,50 @@ coverage.wire_up_help_panel = function () {
// Create the events for the filter box.
coverage.wire_up_filter = function () {
+ // Cache elements.
+ var table = $("table.index");
+ var table_rows = table.find("tbody tr");
+ var table_row_names = table_rows.find("td.name a");
+ var table_cells = {
+ 2: table_rows.find('td:nth-child(2)'),
+ 3: table_rows.find('td:nth-child(3)'),
+ 4: table_rows.find('td:nth-child(4)'),
+ 5: table_rows.find('td:nth-child(5)')
+ };
+ var no_rows = $("#no_rows");
+
+ // Create a duplicate table footer that we can modify with dynamic summed values.
+ var table_footer = $("table.index tfoot tr");
+ var table_dynamic_footer = table_footer.clone();
+ table_dynamic_footer.attr('class', 'total_dynamic hidden');
+ table_footer.after(table_dynamic_footer);
+
+ // Observe filter keyevents.
$("#filter").on("keyup change", $.debounce(150, function (event) {
var filter_value = $(this).val();
if (filter_value === "") {
- // Filter box is empty, remove all filtering
- $("table.index tr").removeClass("hidden");
+ // Filter box is empty, remove all filtering.
+ table_rows.removeClass("hidden");
- // Hide placeholder, show table
- if ($("#no_rows").length > 0) {
- $("#no_rows").hide();
+ // Show standard footer, hide dynamic footer.
+ table_footer.removeClass("hidden");
+ table_dynamic_footer.addClass("hidden");
+
+ // Hide placeholder, show table.
+ if (no_rows.length > 0) {
+ no_rows.hide();
}
- $("table.index").show();
+ table.show();
}
else {
- // Filter table items by value
+ // Filter table items by value.
var hide = $([]);
var show = $([]);
- // Compile elements to hide / show
- $.each($("table.index tr td.name a"), function () {
+ // Compile elements to hide / show.
+ $.each(table_row_names, function () {
var element = $(this).parents("tr");
if ($(this).text().indexOf(filter_value) === -1) {
@@ -71,116 +94,67 @@ coverage.wire_up_filter = function () {
}
});
- // Perform DOM manipulation
+ // Perform DOM manipulation.
hide.addClass("hidden");
show.removeClass("hidden");
- // Show placeholder if no rows will be displayed
- if ($("#no_rows").length > 0) {
+ // Show placeholder if no rows will be displayed.
+ if (no_rows.length > 0) {
if (show.length === 0) {
- // Show placeholder, hide table
- $("#no_rows").show();
- $("table.index").hide();
+ // Show placeholder, hide table.
+ no_rows.show();
+ table.hide();
}
else {
- // Hide placeholder, show table
- $("#no_rows").hide();
- $("table.index").show();
+ // Hide placeholder, show table.
+ no_rows.hide();
+ table.show();
}
}
- // Hide totals table footer if hiding any rows, as values will be inaccurate
+ // Manage dynamic header:
if (hide.length > 0) {
- // Hide footer
- $("table.index tfoot tr").addClass("hidden");
+ // Calculate new dynamic sum values based on visible rows.
+ for (var column in table_cells) {
+ // Calculate summed value.
+ var tmp = 0;
+ $.each(table_cells[column].filter(':visible'), function () {
+ tmp += parseInt(this.innerHTML, 10);
+ });
+
+ // Get footer cell element.
+ var footer_cell = table_dynamic_footer.find('td:nth-child(' + column + ')');
+
+ // Set value into dynamic footer cell element.
+ if (column === '5') {
+ // Value of 5th "coverage" column is expressed as a percentage
+ footer_cell.text(parseInt((tmp / show.length), 10) + '%');
+
+ } else {
+ footer_cell.text(tmp);
+ }
+ }
+
+
+ // Hide standard footer, show dynamic footer.
+ table_footer.addClass("hidden");
+ table_dynamic_footer.removeClass("hidden");
}
else {
- // Show footer
- $("table.index tfoot tr").removeClass("hidden");
+ // Show standard footer, hide dynamic footer.
+ table_footer.removeClass("hidden");
+ table_dynamic_footer.addClass("hidden");
}
}
}));
- // Trigger change event on setup, to force filter on page refresh (filter value may still be present)
+ // Trigger change event on setup, to force filter on page refresh
+ // (filter value may still be present).
$("#filter").trigger("change");
};
-// Create the events for the next buttons.
-coverage.wire_up_next_buttons = function () {
- // Define next button handler.
- function next_handler(event) {
- event.preventDefault();
-
- // Define selector based on clicked button.
- var button_id = $(this).attr("id");
- var selector;
-
- if (button_id == "next_run") {
- selector = ".run";
- }
- else if (button_id == "next_missing") {
- selector = ".mis";
- }
- else if (button_id == "next_excluded") {
- selector = ".exc";
- }
- else {
- return false;
- }
-
- // Go to first line, or next in sequence?
- var target;
- var previous_target = $(this).data("target");
-
- if (previous_target === undefined) {
- // First click, get first matching line.
- target = $("p[id^='t']" + selector).first();
- }
- else {
- // Get next matching (non-contiguous) line.
- var old_target = previous_target;
- target = old_target.nextAll("p[id^='t']" + selector).first();
-
- while ((parseInt(target.attr("id").match(/\d+/)[0]) - parseInt(old_target.attr("id").match(/\d+/)[0])) === 1) {
- old_target = target;
- target = old_target.nextAll("p[id^='t']" + selector).first();
- }
- }
-
- if (target.length > 0) {
- // Set highlight styling and arrow indicator.
- $("p[id^='n'].highlight").removeClass("highlight");
- $("p[id^='n'] span.indicator").remove();
-
- $("p#n" + target.attr("id").match(/\d+/)[0])
- .prepend(
- $("<span />")
- .addClass("indicator")
- .html("&loz;")
- )
- .addClass("highlight");
-
- // Scroll to line.
- $("html, body").animate({
- scrollTop: (target.position().top - ($("#header").outerHeight() + 100))
- }, 100);
-
- // Save target reference in button element for next click.
- $(this).data("target", target);
- }
-
- return false;
- }
-
-
- // Wire up buttons to handler.
- $("#header .stats button")
- .off("click.next")
- .on("click.next", next_handler);
-};
-
// Loaded on index.html
coverage.index_ready = function ($) {
// Look for a cookie containing previous sort settings:
@@ -276,7 +250,6 @@ coverage.pyfile_ready = function ($) {
coverage.assign_shortkeys();
coverage.wire_up_help_panel();
- coverage.wire_up_next_buttons();
};
coverage.toggle_lines = function (btn, cls) {
diff --git a/coverage/htmlfiles/pyfile.html b/coverage/htmlfiles/pyfile.html
index 1ed7487..3a35b02 100644
--- a/coverage/htmlfiles/pyfile.html
+++ b/coverage/htmlfiles/pyfile.html
@@ -11,7 +11,6 @@
<link rel='stylesheet' href='{{ extra_css }}' type='text/css'>
{% endif %}
<script type='text/javascript' src='jquery.min.js'></script>
- <script type='text/javascript' src='jquery.debounce.min.js'></script>
<script type='text/javascript' src='jquery.hotkeys.js'></script>
<script type='text/javascript' src='jquery.isonscreen.js'></script>
<script type='text/javascript' src='coverage_html.js'></script>
@@ -32,13 +31,8 @@
<h2 class='stats'>
{{nums.n_statements}} statements &nbsp;
<span class='{{c_run}} shortkey_r button_toggle_run'>{{nums.n_executed}} run</span>
- <button id="next_run" title="Go to next run line...">&darr;</button>
-
<span class='{{c_mis}} shortkey_m button_toggle_mis'>{{nums.n_missing}} missing</span>
- <button id="next_missing" title="Go to next missing line...">&darr;</button>
-
<span class='{{c_exc}} shortkey_x button_toggle_exc'>{{nums.n_excluded}} excluded</span>
- <button id="next_excluded" title="Go to next excluded line...">&darr;</button>
{% if arcs %}
<span class='{{c_par}} shortkey_p button_toggle_par'>{{nums.n_partial_branches}} partial</span>
diff --git a/coverage/htmlfiles/style.css b/coverage/htmlfiles/style.css
index 176d613..7f2a826 100644
--- a/coverage/htmlfiles/style.css
+++ b/coverage/htmlfiles/style.css
@@ -59,7 +59,6 @@ a.nav:hover {
#source {
padding: 1em;
font-family: "courier new", monospace;
- margin-top: 92px;
}
#source span.indicator {
@@ -82,11 +81,6 @@ a.nav:hover {
margin: 1em 3em;
}
-#pyfile #header {
- position: fixed;
- top: 0;
- }
-
#pyfile #footer {
margin: 1em 1em;
}
@@ -133,16 +127,6 @@ h2.stats {
cursor: pointer;
border-color: #999 #ccc #ccc #999;
}
-.stats button {
- margin: 0 1em 0 0;
- padding: 0 0 1px 0;
- width: 1.5em;
- font-size: 1em;
- cursor: pointer;
- border-width: 1px;
- border-style: solid;
- border-color: #999999 #CCCCCC #CCCCCC #999999;
-}
.stats span.hide_run, .stats span.hide_exc,
.stats span.hide_mis, .stats span.hide_par,
.stats span.par.hide_run.hide_par {
@@ -339,9 +323,11 @@ td.text {
text-decoration: underline;
color: #000;
}
-#index tr.total {
+#index tr.total,
+#index tr.total_dynamic {
}
-#index tr.total td {
+#index tr.total td,
+#index tr.total_dynamic td {
font-weight: bold;
border-top: 1px solid #ccc;
border-bottom: none;