diff --git a/app/views/longterm/index.html.erb b/app/views/longterm/index.html.erb index 443907d..38fde1b 100644 --- a/app/views/longterm/index.html.erb +++ b/app/views/longterm/index.html.erb @@ -9,7 +9,7 @@ class: "btn #{button_name metric} pull-right" %> -<%= render partial: 'shared/table', locals: { +<%= render partial: 'shared/accordion_table', locals: { metrics: metric, with_year: true } %> diff --git a/app/views/shared/_accordion_table.html.erb b/app/views/shared/_accordion_table.html.erb new file mode 100644 index 0000000..736f2c2 --- /dev/null +++ b/app/views/shared/_accordion_table.html.erb @@ -0,0 +1,28 @@ +<% id = metrics.first.class.name.underscore.gsub('_', '-') %> + + <% count = 0 %> + <% date_sift(metrics).each_pair do |day, values| %> + 0 %> class='collapse <%= id %>-accordion'<% end %>> + + + + <% values.each do |value| %> + <%= render partial: 'shared/table_row', locals: { + value: value, + count: count, + id: id + } %> + <% count += 1 %> + <% end %> + <% end %> +
+ <% 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 %> + Show / Hide + <% end %> +
diff --git a/app/views/shared/_table_row.html.erb b/app/views/shared/_table_row.html.erb index c2bc811..c2c7b2b 100644 --- a/app/views/shared/_table_row.html.erb +++ b/app/views/shared/_table_row.html.erb @@ -1,6 +1,6 @@ - + 0 %> class='collapse <%= id %>-accordion'<% end %>> - <%= link_to value.datetime.strftime('%H:%M'), + <%= link_to value.datetime.strftime('%H:%M'), send(edit_path(value), value), title: 'Edit this metric' %>