summaryrefslogtreecommitdiff
path: root/app/views/targets/index.html.erb
diff options
context:
space:
mode:
authorMarius Peter <dev@marius-peter.com>2025-09-08 21:21:56 +0200
committerMarius Peter <dev@marius-peter.com>2025-09-08 21:21:56 +0200
commit7116826b854188604e21e2a613ac6672b6fd81f3 (patch)
tree33150bf2e04e69b8e1fa7d37901d2643b1955534 /app/views/targets/index.html.erb
parent8ba568ae0ebe715b5da453681eb141886f1977a8 (diff)
Create Target and nutrient target table on dashboard.
Diffstat (limited to 'app/views/targets/index.html.erb')
-rw-r--r--app/views/targets/index.html.erb68
1 files changed, 68 insertions, 0 deletions
diff --git a/app/views/targets/index.html.erb b/app/views/targets/index.html.erb
new file mode 100644
index 0000000..b552038
--- /dev/null
+++ b/app/views/targets/index.html.erb
@@ -0,0 +1,68 @@
+<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-sm table-striped table-hover align-middle mb-0">
+ <thead class="table-light">
+ <tr>
+ <th>Nom</th>
+ <th>Répartition</tr>
+ <th class="text-end" style="width: 140px;">Total %</th>
+ <th class="text-nowrap" style="width: 190px;">Créé le</th>
+ <th class="text-end" style="width: 180px;">Actions</th>
+ </tr>
+ </thead>
+ <tbody>
+ <% if @targets.present? %>
+ <% @targets.each do |t| %>
+ <% sum_pct = t.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 t.name.presence || "Objectif ##{t.id}", t %>
+ </td>
+ <td>
+ <% if t.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-2">
+ <% t.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-end">
+ <span class="badge <%= badge_class %>">
+ <%= number_with_precision(sum_pct, precision: 2) %>%
+ </span>
+ </td>
+ <td class="text-nowrap">
+ <%= l(t.created_at, format: :short) %>
+ </td>
+ <td class="text-end text-nowrap">
+ <%= link_to "Voir", t, class: "btn btn-outline-secondary btn-sm" %>
+ <%= link_to "Modifier", edit_target_path(t), class: "btn btn-outline-primary btn-sm" %>
+ <%# FIXME: Doesn't work. %>
+ <%= link_to "Supprimer", t, class: "btn btn-outline-danger btn-sm",
+ data: { turbo_method: :delete, turbo_confirm: "Supprimer cet objectif ?" } %>
+ </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--2025 Marius PETER