Commit a23447bf2309a3f2c0736e8a2ccaeb2badcb220d
1 parent
2200d533
Exists in
master
and in
1 other branch
head and hidden tail for long tables
Showing
3 changed files
with
36 additions
and
5 deletions
Show diff stats
app/assets/javascripts/errbit.js
@@ -130,5 +130,10 @@ $(function() { | @@ -130,5 +130,10 @@ $(function() { | ||
130 | // Hide external backtrace on page load | 130 | // Hide external backtrace on page load |
131 | hide_external_backtrace(); | 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 | init(); | 138 | init(); |
134 | }); | 139 | }); |
app/helpers/application_helper.rb
@@ -61,9 +61,22 @@ module ApplicationHelper | @@ -61,9 +61,22 @@ module ApplicationHelper | ||
61 | render "errs/tally_table", :rows => rows | 61 | render "errs/tally_table", :rows => rows |
62 | end | 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 | private | 72 | private |
65 | def total_from_tallies(tallies) | 73 | def total_from_tallies(tallies) |
66 | tallies.values.inject(0) {|sum, n| sum + n} | 74 | tallies.values.inject(0) {|sum, n| sum + n} |
67 | end | 75 | end |
76 | + | ||
77 | + def head_size | ||
78 | + 4 | ||
79 | + end | ||
80 | + | ||
68 | end | 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] |