[Rails] Fertilizer recipe solver for the FAPG.
1
<div class="card shadow my-3">
2
<div class="card-header d-flex justify-content-between align-items-center">
3
<h4 class="mb-0">Complémentation</h4>
4
<div class="btn-group">
5
<%= link_to "Nouvelle cible", new_target_path, class: "btn btn-sm btn-outline-primary" %>
6
<%= link_to "Liste des cibles", targets_path, class: "btn btn-sm btn-outline-secondary" %>
7
<%= link_to "Voir la recette", root_path, class: "btn btn-sm btn-outline-secondary" %>
8
</div>
9
</div>
10
11
<div class="card-body p-0">
12
<div class="table-responsive">
13
<table class="table table-striped table-hover align-middle mb-0">
14
<thead class="table-light">
15
<tr>
16
<th>Nutriment</th>
17
<th class="text-end">Relevé</th>
18
<th class="text-end"><%= @latest_target&.name || "Cible" %></th>
19
<th class="text-end">Delta (%)</th>
20
</tr>
21
</thead>
22
<tbody>
23
<% Nutrient.all.each do |nutrient| %>
24
<% measured = @latest_measurement.send(nutrient.formula.downcase) %>
25
<% target = @latest_target.send(nutrient.formula.downcase) %>
26
<% delta = (target.to_f - measured.to_f) / 100.0 if measured || target %>
27
28
<tr>
29
<td class="fw-semibold"><%= nutrient.formula %></td>
30
<td class="text-end">
31
<%= measured.present? ? number_with_precision(measured, precision: 2) : — %>
32
</td>
33
34
<td class="text-end">
35
<% if target.nil? %>
36
<span class="text-muted">—</span>
37
<% else %>
38
<%= number_with_precision(target, precision: 2) %>
39
<% end %>
40
</td>
41
42
<td class="text-end">
43
<% if measured.nil? && target.nil? %>
44
<span class="text-muted">—</span>
45
<% else %>
46
<% badge_class =
47
if delta.nil?
48
"text-bg-secondary"
49
elsif delta.abs <= 0.01
50
"text-bg-success"
51
elsif delta > 0
52
"text-bg-warning"
53
else
54
"text-bg-danger"
55
end %>
56
<span class="badge <%= badge_class %>">
57
<%= number_with_precision(delta.to_f, precision: 2) %>
58
</span>
59
<% end %>
60
</td>
61
</tr>
62
<% end %>
63
</tbody>
64
</table>
65
</div>
66
</div>
67
</div>
68