Dispplaying units of computed values
Fixed formula error messages display when filter formula not given
This commit is contained in:
parent
2efdc08931
commit
e7a33c684f
@ -1,13 +1,13 @@
|
||||
module BodyTrackersHelper
|
||||
def format_value(value)
|
||||
amount, unitname = value
|
||||
amount, unit = value
|
||||
case
|
||||
when amount.nil?
|
||||
'-'
|
||||
when amount.nan?
|
||||
'?'
|
||||
else
|
||||
"#{amount} [#{unitname || '-'}]"
|
||||
"#{amount} [#{unit.shortname || '-'}]"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -33,7 +33,7 @@ class Formula < ActiveRecord::Base
|
||||
"length.times.map { |index| #{p[:content]} }" : p[:content]
|
||||
args << get_binding(quantities, args, length).eval(code)
|
||||
end
|
||||
args.last.map { |v| [v, nil] }
|
||||
args.last.map { |v| [v, self.unit] }
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -2,7 +2,7 @@
|
||||
locals: {url: filter_project_ingredients_path(@project)} %>
|
||||
|
||||
<% if @ingredients.any? { |i| i.persisted? } %>
|
||||
<%= error_messages_for @formula_q.formula %>
|
||||
<%= error_messages_for @formula_q.formula if @formula_q %>
|
||||
|
||||
<table class="list">
|
||||
<thead>
|
||||
|
@ -4,7 +4,9 @@
|
||||
<% if @ingredients.any? %>
|
||||
<%= render partial: 'ingredients/options' %>
|
||||
|
||||
<%= error_messages_for @formula_q.formula, *@quantities.map { |q| q.formula } %>
|
||||
<% formulas = @quantities.map { |q| q.formula } %>
|
||||
<% formulas.unshift(@formula_q.formula) if @formula_q %>
|
||||
<%= error_messages_for *formulas %>
|
||||
|
||||
<table class="nutrients list odd-even">
|
||||
<thead>
|
||||
|
@ -2,7 +2,7 @@
|
||||
locals: {url: filter_project_measurements_path(@project)} %>
|
||||
|
||||
<% if @measurements.any? { |m| m.persisted? } %>
|
||||
<%= error_messages_for @formula_q.formula %>
|
||||
<%= error_messages_for @formula_q.formula if @formula_q %>
|
||||
|
||||
<table class="list">
|
||||
<thead>
|
||||
|
@ -4,7 +4,9 @@
|
||||
<% if @measurements.any? %>
|
||||
<%= render partial: 'measurements/options' %>
|
||||
|
||||
<%= error_messages_for @formula_q.formula, *@quantities.map { |q| q.formula } %>
|
||||
<% formulas = @quantities.map { |q| q.formula } %>
|
||||
<% formulas.unshift(@formula_q.formula) if @formula_q %>
|
||||
<%= error_messages_for *formulas %>
|
||||
|
||||
<table class="readouts list odd-even">
|
||||
<thead>
|
||||
|
@ -50,14 +50,12 @@ module BodyTracking
|
||||
subitem_reflection = item_class.reflections[subitem_type]
|
||||
subitem_class = subitem_reflection.klass
|
||||
subitems_scope = subitem_class.where(subitem_reflection.options[:inverse_of] => items)
|
||||
item_foreign_key = subitem_reflection.foreign_key
|
||||
subitems = Hash.new { |h,k| h[k] = {} }
|
||||
subitems_scope.includes(:quantity, :unit)
|
||||
.order('quantities.lft')
|
||||
.pluck('quantities.id', item_foreign_key, VALUE_COLUMNS[item_class],
|
||||
'units.shortname')
|
||||
.each { |q_id, item_id, a, u_id| subitems[q_id][item_id] = [a, u_id] }
|
||||
Quantity.find(subitems.keys).each { |q| subitems[q] = subitems.delete(q.id) }
|
||||
subitems_scope.includes(:quantity, :unit).order('quantities.lft').each do |s|
|
||||
item_id = s.send(subitem_reflection.foreign_key)
|
||||
subitem_value = s.send(VALUE_COLUMNS[item_class])
|
||||
subitems[s.quantity][item_id] = [subitem_value, s.unit]
|
||||
end
|
||||
|
||||
extra_q = subitems.keys - requested_q
|
||||
|
||||
|
Reference in New Issue
Block a user