blob: 006d262bc58d86a6c63da3b28f75710da2844d3b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
<div class="card shadow my-3">
<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-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-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"><%= @latest_target&.name || "Cible" %></th>
<th class="text-end">Delta (%)</th>
</tr>
</thead>
<tbody>
<% 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 %>
<tr>
<td class="fw-semibold"><%= nutrient.formula %></td>
<td class="text-end">
<%= measured.present? ? number_with_precision(measured, precision: 2) : — %>
</td>
<td class="text-end">
<% if target.nil? %>
<span class="text-muted">—</span>
<% else %>
<%= number_with_precision(target, precision: 2) %>
<% end %>
</td>
<td class="text-end">
<% if measured.nil? && target.nil? %>
<span class="text-muted">—</span>
<% else %>
<% badge_class =
if delta.nil?
"text-bg-secondary"
elsif delta.abs <= 0.01
"text-bg-success"
elsif delta > 0
"text-bg-warning"
else
"text-bg-danger"
end %>
<span class="badge <%= badge_class %>">
<%= number_with_precision(delta.to_f, precision: 2) %>
</span>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>
|