diff --git a/app/controllers/meals_controller.rb b/app/controllers/meals_controller.rb index 915f6ff..a7de62d 100644 --- a/app/controllers/meals_controller.rb +++ b/app/controllers/meals_controller.rb @@ -92,9 +92,10 @@ class MealsController < ApplicationController [i, [n_amount && n_amount * i.amount / i.food.ref_amount, n_unit]] end.to_h max_value = @nutrients[q].values.max_by { |a, u| a || 0 }.first - @nutrients[q][:mfu_unit] = @nutrients[q].values.map(&:last) - .each_with_object(Hash.new(0)) { |u, h| h[u] += 1 }.max_by(&:last).first - @nutrients[q][:precision] = [3 - max_value.exponent, 0].max + + @nutrients[q][:mfu_unit] = @nutrients[q] + .each_with_object(Hash.new(0)) { |(i, v), h| h[v.last] += 1 }.max_by(&:last).first + @nutrients[q][:precision] = max_value && [3 - max_value.exponent, 0].max end @meals_by_date = @project.meals.reject { |m,*| m.new_record? } diff --git a/app/helpers/body_trackers_helper.rb b/app/helpers/body_trackers_helper.rb index 9e47de2..bcd85cd 100644 --- a/app/helpers/body_trackers_helper.rb +++ b/app/helpers/body_trackers_helper.rb @@ -19,13 +19,17 @@ module BodyTrackersHelper end def toggle_exposure_options(enabled, domain) - disabled = [] - enabled = enabled.to_a - options = nested_set_options(@project.quantities.send(domain)) do |q| - disabled << q.id if enabled.include?(q) + enabled = enabled.map { |q| [q.name, q.id] } + enabled_ids = enabled.map(&:last) + + options = [[t('body_trackers.helpers.exposures_available'), 0]] + options += nested_set_options(@project.quantities.send(domain)) do |q| raw("#{' ' * q.level}#{q.name}") end - options_for_select(options, disabled: disabled) + options.collect! { |name, id| [name, enabled_ids.include?(id) ? 0 : id] } + + options = [[t('body_trackers.helpers.exposures_enabled'), 0]] + enabled + options + options_for_select(options, disabled: 0) end def unit_options diff --git a/app/views/meals/_index.html.erb b/app/views/meals/_index.html.erb index 0548736..d3c2755 100644 --- a/app/views/meals/_index.html.erb +++ b/app/views/meals/_index.html.erb @@ -10,23 +10,27 @@ <% total_width = 4 + @quantities.length %> <% @meals_by_date.reverse_each do |date, meals| %>