summaryrefslogtreecommitdiff
path: root/app/views/dashboard/_nutrient_target_table.html.erb
blob: 7cf294c09323c21095943e884bb6e8303212ac35 (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
68
69
70
71
72
73
74
<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-primary" %>
	    <%= link_to "Voir la recette", root_path, class: "btn btn-sm btn-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">
		<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>
		    </tr>
		</thead>
		<tbody>
		    <% wr = @weighted || {} %>
		    <% lm = @latest_measurements || {} %>

		    <% 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="text-end">
				<% if measured.nil? %>
				    <span class="text-muted">—</span>
				<% else %>
				    <%= number_with_precision(measured, precision: 2) %>
				<% end %>
			    </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 =
				    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 %>">
					<%= number_with_precision(delta.to_f, precision: 2) %>
				    </span>
				<% end %>
			    </td>
			</tr>
		    <% end %>
		</tbody>
	    </table>
	</div>
    </div>
</div>
Copyright 2019--2025 Marius PETER