Commit a23447bf2309a3f2c0736e8a2ccaeb2badcb220d

Authored by Marcin Ciunelis
1 parent 2200d533
Exists in master and in 1 other branch production

head and hidden tail for long tables

app/assets/javascripts/errbit.js
... ... @@ -130,5 +130,10 @@ $(function() {
130 130 // Hide external backtrace on page load
131 131 hide_external_backtrace();
132 132  
  133 + $('.head a.show_tail').click(function(e) {
  134 + $(this).hide().closest('.head_and_tail').find('.tail').show();
  135 + e.preventDefault();
  136 + });
  137 +
133 138 init();
134 139 });
... ...
app/helpers/application_helper.rb
... ... @@ -61,9 +61,22 @@ module ApplicationHelper
61 61 render "errs/tally_table", :rows => rows
62 62 end
63 63  
  64 + def head(collection)
  65 + collection.first(head_size)
  66 + end
  67 +
  68 + def tail(collection)
  69 + collection.to_a[head_size..-1].to_a
  70 + end
  71 +
64 72 private
65 73 def total_from_tallies(tallies)
66 74 tallies.values.inject(0) {|sum, n| sum + n}
67 75 end
  76 +
  77 + def head_size
  78 + 4
  79 + end
  80 +
68 81 end
69 82  
... ...
app/views/errs/_tally_table.html.haml
1   -%table.tally
2   - - rows.each do |row|
3   - %tr
4   - %td.percent= number_to_percentage(row[0], :precision => 1)
5   - %th.value= row[1]
  1 +.head_and_tail
  2 + %table.tally.head
  3 + %tbody
  4 + - head(rows).each do |row|
  5 + %tr
  6 + %td.percent= number_to_percentage(row[0], :precision => 1)
  7 + %th.value= row[1]
  8 + - if rows.size > head_size
  9 + %tfoot
  10 + %tr
  11 + %td{colspan: 2}
  12 + = link_to 'Show more...', '#', class: :show_tail
  13 + %table.tally.tail{style: "display: none"}
  14 + %tbody
  15 + - tail(rows).each do |row|
  16 + %tr
  17 + %td.percent= number_to_percentage(row[0], :precision => 1)
  18 + %th.value= row[1]
... ...