diff options
Diffstat (limited to 'coverage/htmlfiles/coverage_html.js')
-rw-r--r-- | coverage/htmlfiles/coverage_html.js | 123 |
1 files changed, 122 insertions, 1 deletions
diff --git a/coverage/htmlfiles/coverage_html.js b/coverage/htmlfiles/coverage_html.js index b24006d2..88a0cd89 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) { @@ -35,6 +35,126 @@ 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_rows.removeClass("hidden"); + + // 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.show(); + + } + else { + // Filter table items by value. + var hide = $([]); + var show = $([]); + + // Compile elements to hide / show. + $.each(table_row_names, function () { + var element = $(this).parents("tr"); + + if ($(this).text().indexOf(filter_value) === -1) { + // hide + hide = hide.add(element); + + } + else { + // show + show = show.add(element); + } + }); + + // Perform DOM manipulation. + hide.addClass("hidden"); + show.removeClass("hidden"); + + // 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.hide(); + + } + else { + // Hide placeholder, show table. + no_rows.hide(); + table.show(); + } + } + + // Manage dynamic header: + if (hide.length > 0) { + // 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 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). + $("#filter").trigger("change"); +}; + // Loaded on index.html coverage.index_ready = function ($) { // Look for a cookie containing previous sort settings: @@ -95,6 +215,7 @@ coverage.index_ready = function ($) { coverage.assign_shortkeys(); coverage.wire_up_help_panel(); + coverage.wire_up_filter(); // Watch for page unload events so we can save the final sort settings: $(window).unload(function () { |