diff --git a/app/controllers/readouts_controller.rb b/app/controllers/readouts_controller.rb
index ce193f3..77dfb51 100644
--- a/app/controllers/readouts_controller.rb
+++ b/app/controllers/readouts_controller.rb
@@ -27,5 +27,13 @@ class ReadoutsController < ApplicationController
@measurements, @filter_q = @routine.measurements.includes(:routine, :source)
.filter(session[:m_filters], @quantities)
+
+ # Keep only non-nil readouts and their ancestors
+ @measurements.each do |measurement, readouts|
+ ancestors = {}
+ readouts.keep_if do |q, readout|
+ (readout || ancestors[q]) && (ancestors[q.parent] = true)
+ end
+ end
end
end
diff --git a/app/helpers/body_trackers_helper.rb b/app/helpers/body_trackers_helper.rb
index eae7aca..11668f3 100644
--- a/app/helpers/body_trackers_helper.rb
+++ b/app/helpers/body_trackers_helper.rb
@@ -1,15 +1,17 @@
module BodyTrackersHelper
- def format_value(value, precision=2, mfu_unit=nil)
- amount, unit = value
+ def format_amount(amount, precision=2, mfu_unit=nil)
+ value = amount.respond_to?(:value) ? amount.value : amount&.first
+ unit = amount.respond_to?(:unit) ? amount.unit : amount&.last
+
case
- when amount.nil?
- '-'
- when amount.nan?
+ when value.nil?
+ ''
+ when value.nan?
'?'
else
- a = amount.round(precision)
- a_desc = a.nonzero? ? "%.#{precision}f" % a : '-'
- u_desc = unit && " [#{unit.shortname}]" || ' [-]' if unit != mfu_unit && a.nonzero?
+ value = value.round(precision)
+ a_desc = value.nonzero? ? "%.#{precision}f" % value : '-'
+ u_desc = unit ? " [#{unit.shortname}]" : ' [-]' if unit != mfu_unit && value.nonzero?
"#{a_desc}#{u_desc}"
end
end
diff --git a/app/helpers/measurements_helper.rb b/app/helpers/measurements_helper.rb
index 021774d..0f5a46c 100644
--- a/app/helpers/measurements_helper.rb
+++ b/app/helpers/measurements_helper.rb
@@ -1,4 +1,10 @@
module MeasurementsHelper
+ def readout_markup(quantity, readout)
+ content = "#{' '*quantity.depth}#{quantity.name} #{format_amount(readout)}"
+ classes = 'bolded' if @routine.quantities.include?(quantity)
+ content_tag(:span, content, {class: classes}, false)
+ end
+
def action_links(m)
link_to(l(:button_retake), retake_measurement_path(m, @view_params),
{remote: true, class: "icon icon-reload"}) +
diff --git a/app/views/foods/_nutrients.html.erb b/app/views/foods/_nutrients.html.erb
index cf5d8fa..daf8bb5 100644
--- a/app/views/foods/_nutrients.html.erb
+++ b/app/views/foods/_nutrients.html.erb
@@ -42,8 +42,8 @@
<% @quantities.each do |q| %>
- <%= format_value(nutrients[q], @food_summary[:precision][q],
- @food_summary[:mfu_unit][q]) %>
+ <%= format_amount(nutrients[q], @food_summary[:precision][q],
+ @food_summary[:mfu_unit][q]) %>
|
<% end %>
<%= action_links(food, :nutrients) %> |
@@ -62,7 +62,7 @@
<% @quantities.each do |q| %>
<%= q.name %>
- <%= format_value(nutrients[q]) %>
+ <%= format_amount(nutrients[q]) %>
|
<% end %>
@@ -76,7 +76,7 @@
<% eqs.each do |q| %>
|
<% end %>
<% if @quantities.length > eqs.length %>
diff --git a/app/views/meals/_show.html.erb b/app/views/meals/_show.html.erb
index 858d010..118241f 100644
--- a/app/views/meals/_show.html.erb
+++ b/app/views/meals/_show.html.erb
@@ -37,7 +37,7 @@
|
<% @quantities.each do |q| %>
- <%= format_value(@ingredient_summary[m][q], @ingredient_summary[:precision][q]) %>
+ <%= format_amount(@ingredient_summary[m][q], @ingredient_summary[:precision][q]) %>
|
<% end %>
diff --git a/app/views/meals/_show_date.html.erb b/app/views/meals/_show_date.html.erb
index 23daa09..f8c1353 100644
--- a/app/views/meals/_show_date.html.erb
+++ b/app/views/meals/_show_date.html.erb
@@ -7,7 +7,7 @@
|
<% @quantities.each do |q| %>
- <%= format_value(@ingredient_summary[date][q], @ingredient_summary[:precision][q]) %>
+ <%= format_amount(@ingredient_summary[date][q], @ingredient_summary[:precision][q]) %>
|
<% end %>
|
diff --git a/app/views/meals/_show_ingredient.html.erb b/app/views/meals/_show_ingredient.html.erb
index 6547c22..76e961c 100644
--- a/app/views/meals/_show_ingredient.html.erb
+++ b/app/views/meals/_show_ingredient.html.erb
@@ -6,8 +6,8 @@
<% @quantities.each do |q| %>
- <%= format_value(@ingredients[i][q], @ingredient_summary[:precision][q],
- @ingredient_summary[:mfu_unit][q]) %>
+ <%= format_amount(@ingredients[i][q], @ingredient_summary[:precision][q],
+ @ingredient_summary[:mfu_unit][q]) %>
|
<% end %>
<%# Moved buttons to helper to avoid spaces between buttons %>
diff --git a/app/views/readouts/_index.html.erb b/app/views/readouts/_index.html.erb
index ed9a751..e698664 100644
--- a/app/views/readouts/_index.html.erb
+++ b/app/views/readouts/_index.html.erb
@@ -16,58 +16,33 @@
<% extra_quantities = @measurements.values.first.keys - @quantities %>
<% @measurements.each do |measurement, readouts| %>
- <% row_class = "measurement #{cycle('odd', 'even')}" %>
-
-
-
- <%= format_datetime(measurement.taken_at) %>
-
+ |
+
+ <%= link_to format_datetime(measurement.taken_at), '',
+ {class: 'icon icon-arrow-right',
+ onclick: "$(this).closest('tr').nextUntil('tr.measurement', '.details')
+ .show(); return false;"} %>
|
<% @quantities.each do |q| %>
- <%= format_value(readouts[q]) %> |
+ <%= format_amount(readouts[q]) %> |
<% end %>
<%= action_links(measurement) %> |
-
- <% if @quantities.length > 0
- rows = (readouts.length - 1) / @quantities.length + 1
- else
- rows = 1
- end %>
-
-
- <%= format_datetime(measurement.taken_at) %>
-
+ |
+
+ <%= link_to l(:button_close), "#", {class: 'icon icon-close',
+ onclick: '$(this).closest("tr")
+ .nextUntil("tr.measurement", ":not(.details)")
+ .show().addBack().first().hide(); return false;'} %>
|
- <% @quantities.each do |q| %>
-
- <%= q.name %>
- <%= format_value(readouts[q]) %>
- |
+ <% content = readouts.keys.inject('') do |output, q| %>
+ <% raw "#{output}#{readout_markup(q, readouts[q])}\n" %>
<% end %>
-
- <%= action_links(measurement) %>
- |
+ <%= content %> |
-
- <% next if @quantities.empty? %>
- <% extra_quantities.each_slice(@quantities.length) do |eqs| %>
-
- <% end %>
-
<% end %>
diff --git a/lib/body_tracking/items_with_quantities.rb b/lib/body_tracking/items_with_quantities.rb
index 8a75ac1..d216153 100644
--- a/lib/body_tracking/items_with_quantities.rb
+++ b/lib/body_tracking/items_with_quantities.rb
@@ -109,7 +109,7 @@ module BodyTracking
filter_values = completed_q.delete(filter_q)
items.to_a.keep_if { |i| filter_values[i][0] } if filter_values
subitems.merge!(completed_q)
- subitem_keys = subitems.keys.select { |k| k.class == Quantity }.sort_by { |q| q.lft }
+ subitem_keys = subitems.keys.select { |k| k.instance_of?(Quantity) }.sort_by(&:lft)
items.map { |i| [i, subitem_keys.map { |q| [q, subitems[q][i]] }.to_h] }.to_h
end
end