Skip to content

Commit

Permalink
Collapsible
Browse files Browse the repository at this point in the history
  • Loading branch information
pikesley committed Feb 21, 2016
1 parent 79faf01 commit 44bee4b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/views/longterm/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class: "btn #{button_name metric} pull-right" %>
</div>
</div>
<%= render partial: 'shared/table', locals: {
<%= render partial: 'shared/accordion_table', locals: {
metrics: metric,
with_year: true
} %>
Expand Down
28 changes: 28 additions & 0 deletions app/views/shared/_accordion_table.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<% id = metrics.first.class.name.underscore.gsub('_', '-') %>
<table class='table table-bordered table-hover' id='<%= id %>-table'>
<% count = 0 %>
<% date_sift(metrics).each_pair do |day, values| %>
<tr<% if count > 0 %> class='collapse <%= id %>-accordion'<% end %>>
<th colspan='4' class='day-marker'> <!-- bootstrap ignores this maybe? -->
<% date = Time.parse(day) %>
<% header = date.strftime "%A %B #{date.day.ordinalize}" %>
<% if with_year %>
<% header = date.strftime "%A %B #{date.day.ordinalize} %Y" %>
<% end %>
<%= header %>
<% if count == 0 %>
<span class='pull-right clickable' data-toggle='collapse' data-target='.<%= id %>-accordion' class='clickable'>Show / Hide</span>
<% end %>
</th>
</tr>

<% values.each do |value| %>
<%= render partial: 'shared/table_row', locals: {
value: value,
count: count,
id: id
} %>
<% count += 1 %>
<% end %>
<% end %>
</table>
4 changes: 2 additions & 2 deletions app/views/shared/_table_row.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<tr>
<tr<% if count > 0 %> class='collapse <%= id %>-accordion'<% end %>>
<td>
<%= link_to value.datetime.strftime('%H:%M'),
<%= link_to value.datetime.strftime('%H:%M'),
send(edit_path(value), value),
title: 'Edit this metric'
%>
Expand Down

0 comments on commit 44bee4b

Please sign in to comment.