summaryrefslogtreecommitdiff
path: root/app/views/targets/index.html.erb
blob: e536debbb1abacbb0edeab768b141891bbd0a3c4 (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
<h1 class="display-1">Cibles</h1>

<div class="btn-group my-3">
    <%= link_to "Nouvelle Cible", new_target_path, class: "btn btn-primary" %>
</div>

<div class="table-responsive">
    <table class="table table-hover align-middle">
	<thead class="table-light">
	    <tr>
		<th>Nom</th>
		<th>Répartition</th>
		<th>Date de Création</th>
	    </tr>
	</thead>
	<tbody>
	    <% if @targets.present? %>
		<% @targets.each do |target| %>
		    <% sum_pct = target.allocations.sum { |a| a.percentage.to_f } %>
		    <% badge_class = (sum_pct - 100.0).abs <= 0.01 ? "bg-success" : "bg-danger" %>
		    <tr>
			<td class="fw-semibold">
			    <%= link_to target.name.presence || "Cible ##{t.id}", target %>
			</td>
			<td>
			    <% if target.allocations.empty? %>
				<span class="text-muted">Aucune répartition définie</span>
			    <% else %>
				<ul class="list-unstyled mb-0 d-flex flex-wrap gap-3">
				    <% target.allocations.each do |a| %>
					<li class="badge text-bg-light border">
					    <%= a.nutrient_profile&.name || "Profil ##{a.nutrient_profile_id}" %>
					    — <%= number_with_precision(a.percentage.to_f, precision: 2) %>%
					</li>
				    <% end %>
				</ul>
			    <% end %>
			</td>
			<td class="text-nowrap">
			    <%= l(target.created_at, format: :short) %>
			</td>
		    </tr>
		<% end %>
	    <% else %>
		<tr>
		    <td colspan="5" class="text-center py-4 text-muted">
			Aucun objectif pour le moment.&nbsp;
			<%= link_to "Créer le premier", new_target_path %>.
		    </td>
		</tr>
	    <% end %>
	</tbody>
    </table>
</div>
Copyright 2019--2026 Marius PETER