1
0

Display readout list in tree format

This commit is contained in:
cryptogopher
2021-05-12 21:34:00 +02:00
parent bb43370329
commit 96d1c40cb8
9 changed files with 51 additions and 60 deletions

View File

@@ -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

View File

@@ -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"}) +