From a23447bf2309a3f2c0736e8a2ccaeb2badcb220d Mon Sep 17 00:00:00 2001 From: Marcin Ciunelis Date: Thu, 9 Aug 2012 23:17:14 +0200 Subject: [PATCH] head and hidden tail for long tables --- app/assets/javascripts/errbit.js | 5 +++++ app/helpers/application_helper.rb | 13 +++++++++++++ app/views/errs/_tally_table.html.haml | 23 ++++++++++++++++++----- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/errbit.js b/app/assets/javascripts/errbit.js index 011b7cb..5bc03d9 100644 --- a/app/assets/javascripts/errbit.js +++ b/app/assets/javascripts/errbit.js @@ -130,5 +130,10 @@ $(function() { // Hide external backtrace on page load hide_external_backtrace(); + $('.head a.show_tail').click(function(e) { + $(this).hide().closest('.head_and_tail').find('.tail').show(); + e.preventDefault(); + }); + init(); }); diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 57539b2..19b9a5d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -61,9 +61,22 @@ module ApplicationHelper render "errs/tally_table", :rows => rows end + def head(collection) + collection.first(head_size) + end + + def tail(collection) + collection.to_a[head_size..-1].to_a + end + private def total_from_tallies(tallies) tallies.values.inject(0) {|sum, n| sum + n} end + + def head_size + 4 + end + end diff --git a/app/views/errs/_tally_table.html.haml b/app/views/errs/_tally_table.html.haml index bf54ce5..a09abde 100644 --- a/app/views/errs/_tally_table.html.haml +++ b/app/views/errs/_tally_table.html.haml @@ -1,5 +1,18 @@ -%table.tally - - rows.each do |row| - %tr - %td.percent= number_to_percentage(row[0], :precision => 1) - %th.value= row[1] +.head_and_tail + %table.tally.head + %tbody + - head(rows).each do |row| + %tr + %td.percent= number_to_percentage(row[0], :precision => 1) + %th.value= row[1] + - if rows.size > head_size + %tfoot + %tr + %td{colspan: 2} + = link_to 'Show more...', '#', class: :show_tail + %table.tally.tail{style: "display: none"} + %tbody + - tail(rows).each do |row| + %tr + %td.percent= number_to_percentage(row[0], :precision => 1) + %th.value= row[1] -- libgit2 0.21.2