View raw

1 <h1 class="display-1">Cibles</h1> 2 3 <div class="btn-group my-3"> 4 <%= link_to "Nouvelle Cible", new_target_path, class: "btn btn-primary" %> 5 </div> 6 7 <div class="table-responsive"> 8 <table class="table table-hover align-middle"> 9 <thead class="table-light"> 10 <tr> 11 <th>Nom</th> 12 <th>Répartition</th> 13 <th>Date de Création</th> 14 </tr> 15 </thead> 16 <tbody> 17 <% if @targets.present? %> 18 <% @targets.each do |target| %> 19 <% sum_pct = target.allocations.sum { |a| a.percentage.to_f } %> 20 <% badge_class = (sum_pct - 100.0).abs <= 0.01 ? "bg-success" : "bg-danger" %> 21 <tr> 22 <td class="fw-semibold"> 23 <%= link_to target.name.presence || "Cible ##{t.id}", target %> 24 </td> 25 <td> 26 <% if target.allocations.empty? %> 27 <span class="text-muted">Aucune répartition définie</span> 28 <% else %> 29 <ul class="list-unstyled mb-0 d-flex flex-wrap gap-3"> 30 <% target.allocations.each do |a| %> 31 <li class="badge text-bg-light border"> 32 <%= a.nutrient_profile&.name || "Profil ##{a.nutrient_profile_id}" %> 33 — <%= number_with_precision(a.percentage.to_f, precision: 2) %>% 34 </li> 35 <% end %> 36 </ul> 37 <% end %> 38 </td> 39 <td class="text-nowrap"> 40 <%= l(target.created_at, format: :short) %> 41 </td> 42 </tr> 43 <% end %> 44 <% else %> 45 <tr> 46 <td colspan="5" class="text-center py-4 text-muted"> 47 Aucun objectif pour le moment.&nbsp; 48 <%= link_to "Créer le premier", new_target_path %>. 49 </td> 50 </tr> 51 <% end %> 52 </tbody> 53 </table> 54 </div> 55