diff options
| author | Marius Peter <dev@marius-peter.com> | 2025-11-23 17:54:45 +0100 |
|---|---|---|
| committer | Marius Peter <dev@marius-peter.com> | 2025-11-23 17:54:45 +0100 |
| commit | fa77a691ce0cc8941fe470a762f352b27f4f0563 (patch) | |
| tree | 08916174840a7896fc59633cc59fab931e7012c2 /app/views/dashboard/_nutrient_target_table.html.erb | |
| parent | 73283f2f5153c77f72b6a29e98f173628f5e1057 (diff) | |
Diffstat (limited to 'app/views/dashboard/_nutrient_target_table.html.erb')
| -rw-r--r-- | app/views/dashboard/_nutrient_target_table.html.erb | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/app/views/dashboard/_nutrient_target_table.html.erb b/app/views/dashboard/_nutrient_target_table.html.erb index 7cf294c..006d262 100644 --- a/app/views/dashboard/_nutrient_target_table.html.erb +++ b/app/views/dashboard/_nutrient_target_table.html.erb @@ -2,40 +2,33 @@ <div class="card-header d-flex justify-content-between align-items-center"> <h4 class="mb-0">Complémentation</h4> <div class="btn-group"> - <%= link_to "Nouvelle cible", new_target_path, class: "btn btn-sm btn-primary" %> - <%= link_to "Voir la recette", root_path, class: "btn btn-sm btn-secondary" %> + <%= link_to "Nouvelle cible", new_target_path, class: "btn btn-sm btn-outline-primary" %> + <%= link_to "Liste des cibles", targets_path, class: "btn btn-sm btn-outline-secondary" %> + <%= link_to "Voir la recette", root_path, class: "btn btn-sm btn-outline-secondary" %> </div> </div> <div class="card-body p-0"> <div class="table-responsive"> - <table class="table table-sm table-striped table-hover align-middle mb-0"> + <table class="table table-striped table-hover align-middle mb-0"> <thead class="table-light"> <tr> <th>Nutriment</th> <th class="text-end">Relevé</th> - <th class="text-end">Cible</th> - <th class="text-end">Delta</th> + <th class="text-end"><%= @latest_target&.name || "Cible" %></th> + <th class="text-end">Delta (%)</th> </tr> </thead> <tbody> - <% wr = @weighted || {} %> - <% lm = @latest_measurements || {} %> + <% Nutrient.all.each do |nutrient| %> + <% measured = @latest_measurement.send(nutrient.formula.downcase) %> + <% target = @latest_target.send(nutrient.formula.downcase) %> + <% delta = (target.to_f - measured.to_f) / 100.0 if measured || target %> - <% keys = (wr.keys + lm.keys).map(&:to_s).uniq.sort %> - <% keys.each do |nut| %> - <% measured = lm[nut] %> - <% target = wr[nut] %> - <% delta = (measured.to_f - target.to_f) if measured || target %> <tr> - <td class="fw-semibold"><%= nut.upcase %></td> - + <td class="fw-semibold"><%= nutrient.formula %></td> <td class="text-end"> - <% if measured.nil? %> - <span class="text-muted">—</span> - <% else %> - <%= number_with_precision(measured, precision: 2) %> - <% end %> + <%= measured.present? ? number_with_precision(measured, precision: 2) : — %> </td> <td class="text-end"> @@ -50,7 +43,7 @@ <% if measured.nil? && target.nil? %> <span class="text-muted">—</span> <% else %> - <% badge = + <% badge_class = if delta.nil? "text-bg-secondary" elsif delta.abs <= 0.01 @@ -60,7 +53,7 @@ else "text-bg-danger" end %> - <span class="badge <%= badge %>"> + <span class="badge <%= badge_class %>"> <%= number_with_precision(delta.to_f, precision: 2) %> </span> <% end %> |