diff --git a/app/helpers/body_trackers_helper.rb b/app/helpers/body_trackers_helper.rb index bcd85cd..36c2c0c 100644 --- a/app/helpers/body_trackers_helper.rb +++ b/app/helpers/body_trackers_helper.rb @@ -37,4 +37,38 @@ module BodyTrackersHelper [u.shortname, u.id] end end + + def table_header_spec(quantities) + # spec: table of rows (tr), where each row is a hash of cells (td) (hash keeps items + # ordered the way they were added). Hash values determine cell property: + # * int > 0 - quantity name-labelled cell with 'int' size colspan + # * int < 0 - quantity name-labelled cell with 'int' size rowspan + # * nil - non-labelled cell without col-/rowspan + spec = [] + default_row = Hash.new(0) + + # Determine colspans first... + quantities.each do |q| + ancestors = q.self_and_ancestors.each_with_index do |a, i| + spec[i] ||= default_row.dup + spec[i][a] += 1 + end + spec[ancestors.length...spec.length].each { |row| row[ancestors.last] = nil } + default_row[ancestors.last] = nil + end + + # ...then rowspans + single_columns = [] + spec.each_with_index do |row, i| + single_columns.each { |q| row.delete(q) } + row.each do |q, span| + if span == 1 + row[q] = -(spec.length - i) + single_columns << q + end + end + end + + spec + end end diff --git a/app/views/meals/_index.html.erb b/app/views/meals/_index.html.erb index 3d63f6c..deaaea3 100644 --- a/app/views/meals/_index.html.erb +++ b/app/views/meals/_index.html.erb @@ -8,21 +8,33 @@
- | - <%= l(:field_amount) %> - | - <% @quantities.each do |q| %> -- <%= q.name %> - | - <% end %> -- | |
+ | <%= l(:field_amount) %> | + <% end %> + + <% row.each do |q, span| %> +0 %> + <%= "rowspan=#{-span}" if span && span < 0 %> + style="width: <%= (span && span > 0 ? span : 1) * 100/total_width %>%;" + title="<%= q.description %>"> + <%= q.name if span %> + | + <% end %> + + <% if i == 0 %> ++ <% end %> + | |
<%= "[#{@amount_mfu_unit.shortname}]" %> | diff --git a/assets/stylesheets/body_tracking.css b/assets/stylesheets/body_tracking.css index 3495a01..b02e4c4 100644 --- a/assets/stylesheets/body_tracking.css +++ b/assets/stylesheets/body_tracking.css @@ -8,11 +8,11 @@ table.list .quantity {text-align: left;} /* TODO: merge with .closable */ table.list .quantityhead { text-align: center; - vertical-align: bottom; position: relative; padding: 2px 0; - border: none; + border-bottom: none; } +table.list .quantityheadempty {border-top: none; border-bottom: none;} table.list .action, table.list .value {text-align: right; padding-right: 2px;}