diff --git a/app/helpers/body_trackers_helper.rb b/app/helpers/body_trackers_helper.rb index 4b5f287..39158e7 100644 --- a/app/helpers/body_trackers_helper.rb +++ b/app/helpers/body_trackers_helper.rb @@ -58,7 +58,7 @@ module BodyTrackersHelper # 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 + # * 0 - non-labelled cell without col-/rowspan spec = [] default_row = Hash.new(0) @@ -68,16 +68,16 @@ module BodyTrackersHelper 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 + spec[ancestors.length...spec.length].each { |row| row[ancestors.last] = 0 } + default_row[ancestors.last] = 0 end # ...then rowspans single_columns = [] spec[1..-1].each_with_index do |row, i| row.each do |q, span| - # Current span is nil and previous span == 1 - if span.nil? && (spec[i][q] == 1) + # Current span is 0 and previous span == 1 + if (span == 0) && (spec[i][q] == 1) spec[i][q] = -(spec.length - i) single_columns << q end diff --git a/app/views/targets/_index.html.erb b/app/views/targets/_index.html.erb index 3477220..6fd2ffe 100644 --- a/app/views/targets/_index.html.erb +++ b/app/views/targets/_index.html.erb @@ -21,14 +21,14 @@ <% row.each do |q, span| %> <% row_classes = [] %> - <% row_classes << 'quantity' unless i == header.length-1 %> - <% row_classes << 'empty' unless span %> + <% row_classes << 'quantity' if (i < header.length-1) && (span >= 0) %> + <% row_classes << 'empty' if span == 0 %> - <%= "colspan=#{span}" if span && span > 0 %> - <%= "rowspan=#{-span}" if span && span < 0 %> - style="width: <%= (span && span > 0 ? span : 1) * 100/total_width %>%;" + <%= "colspan=#{span}" if span > 0 %> + <%= "rowspan=#{-span}" if span < 0 %> + style="width: <%= [span, 1].max * 100/total_width %>%;" title="<%= q.description %>"> - <%= q.name if span %> + <%= q.name unless span == 0 %> <% end %>