diff options
Diffstat (limited to 'app/views')
| -rw-r--r-- | app/views/dashboard/_nutrient_measurements_table.html.erb | 4 | ||||
| -rw-r--r-- | app/views/dashboard/_nutrient_target_table.html.erb | 35 | ||||
| -rw-r--r-- | app/views/dashboard/_raft_allocation.html.erb | 9 | ||||
| -rw-r--r-- | app/views/dashboard/_target_table.html.erb | 39 | ||||
| -rw-r--r-- | app/views/dashboard/index.html.erb | 4 | ||||
| -rw-r--r-- | app/views/targets/index.html.erb | 34 | ||||
| -rw-r--r-- | app/views/targets/new.html.erb | 85 |
7 files changed, 26 insertions, 184 deletions
diff --git a/app/views/dashboard/_nutrient_measurements_table.html.erb b/app/views/dashboard/_nutrient_measurements_table.html.erb index 82ea6ff..4d516bd 100644 --- a/app/views/dashboard/_nutrient_measurements_table.html.erb +++ b/app/views/dashboard/_nutrient_measurements_table.html.erb @@ -2,8 +2,8 @@ <div class="card-header d-flex justify-content-between align-items-center"> <h4 class="mb-0">Relevé des Nutriments</h4> <div class="btn-group"> - <%= link_to "Ajouter un relevé", new_nutrient_measurement_path, class: "btn btn-sm btn-primary" %> - <%= link_to "Liste des relevés", nutrient_measurements_path, class: "btn btn-sm btn-secondary" %> + <%= link_to "Ajouter un relevé", new_nutrient_measurement_path, class: "btn btn-sm btn-outline-primary" %> + <%= link_to "Liste des relevés", nutrient_measurements_path, class: "btn btn-sm btn-outline-secondary" %> </div> </div> diff --git a/app/views/dashboard/_nutrient_target_table.html.erb b/app/views/dashboard/_nutrient_target_table.html.erb index 7cf294c..006d262 100644 --- a/app/views/dashboard/_nutrient_target_table.html.erb +++ b/app/views/dashboard/_nutrient_target_table.html.erb @@ -2,40 +2,33 @@ <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" %> + <%= link_to "Nouvelle cible", new_target_path, class: "btn btn-sm btn-outline-primary" %> + <%= link_to "Liste des cibles", targets_path, class: "btn btn-sm btn-outline-secondary" %> + <%= link_to "Voir la recette", root_path, class: "btn btn-sm btn-outline-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"> + <table class="table 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> + <th class="text-end"><%= @latest_target&.name || "Cible" %></th> + <th class="text-end">Delta (%)</th> </tr> </thead> <tbody> - <% wr = @weighted || {} %> - <% lm = @latest_measurements || {} %> + <% Nutrient.all.each do |nutrient| %> + <% measured = @latest_measurement.send(nutrient.formula.downcase) %> + <% target = @latest_target.send(nutrient.formula.downcase) %> + <% delta = (target.to_f - measured.to_f) / 100.0 if measured || target %> - <% 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="fw-semibold"><%= nutrient.formula %></td> <td class="text-end"> - <% if measured.nil? %> - <span class="text-muted">—</span> - <% else %> - <%= number_with_precision(measured, precision: 2) %> - <% end %> + <%= measured.present? ? number_with_precision(measured, precision: 2) : — %> </td> <td class="text-end"> @@ -50,7 +43,7 @@ <% if measured.nil? && target.nil? %> <span class="text-muted">—</span> <% else %> - <% badge = + <% badge_class = if delta.nil? "text-bg-secondary" elsif delta.abs <= 0.01 @@ -60,7 +53,7 @@ else "text-bg-danger" end %> - <span class="badge <%= badge %>"> + <span class="badge <%= badge_class %>"> <%= number_with_precision(delta.to_f, precision: 2) %> </span> <% end %> diff --git a/app/views/dashboard/_raft_allocation.html.erb b/app/views/dashboard/_raft_allocation.html.erb deleted file mode 100644 index 1c9ef9a..0000000 --- a/app/views/dashboard/_raft_allocation.html.erb +++ /dev/null @@ -1,9 +0,0 @@ -<div class="card shadow mb-4"> - <div class="card-header d-flex justify-content-between align-items-center"> - <h5 class="mb-0">Crop Allocation</h5> - <%#= link_to "Edit allocation", beds_path, class: "btn btn-sm btn-primary" %> - </div> - - <%= bar_chart @raft_data, stacked: true %> -</div> - diff --git a/app/views/dashboard/_target_table.html.erb b/app/views/dashboard/_target_table.html.erb deleted file mode 100644 index b1553dc..0000000 --- a/app/views/dashboard/_target_table.html.erb +++ /dev/null @@ -1,39 +0,0 @@ -<div class="card shadow mb-4"> - <div class="card-header d-flex justify-content-between align-items-center"> - <h5 class="mb-0">Target nutrient concentrations</h5> - <%= link_to "Get Ferti© recipe", ferti_recipe_path, class: "btn btn-sm btn-primary" %> - </div> - - <div class="table-responsive"> - <table class="table table-sm align-middle mb-0"> - <thead class="table-light"> - <tr> - <th scope="col" class="text-nowrap">Nutrient</th> - <th scope="col" class="text-end"> Latest (mg/L)</th> - <th scope="col" class="text-end">Target (mg/L)</th> - <th scope="col" class="text-end">Δ %</th> - </tr> - </thead> - <tbody> - <% NutrientsHelper::NUTRIENTS.each do |n| %> - <% latest = @latest_measurement[n] || 0 %> - <% target = @target[n] || 0 %> - <% delta = target - latest %> - <tr> - <th scope="row" class="text-nowrap"><%= n.upcase %></th> - <td class="text-end"><%= fmt(latest) %></td> - <td class="text-end"><%= fmt(target) %></td> - <td class="text-end"> - <span class="badge <%= delta_badge_class(delta) %>"> - <%= fmt(delta) %>% - </span> - </td> - </tr> - <% end %> - </tbody> - </table> - </div> - <div class="card-footer"> - Latest measurement: <%= @latest_measurement.measured_on || "none yet" %> - </div> -</div> diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index a954e4c..50fab18 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -2,8 +2,4 @@ <%= render "nutrient_target_table", nutrient_profiles: @nutrient_profiles %> -<%#= render "raft_allocation" %> - -<%#= render "target_table" %> - <%= render "nutrient_measurements_table" %> diff --git a/app/views/targets/index.html.erb b/app/views/targets/index.html.erb index b552038..e536deb 100644 --- a/app/views/targets/index.html.erb +++ b/app/views/targets/index.html.erb @@ -5,31 +5,29 @@ </div> <div class="table-responsive"> - <table class="table table-sm table-striped table-hover align-middle mb-0"> + <table class="table table-hover align-middle"> <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> + <th>Répartition</th> + <th>Date de Création</th> </tr> </thead> <tbody> <% if @targets.present? %> - <% @targets.each do |t| %> - <% sum_pct = t.target_allocations.sum { |a| a.percentage.to_f } %> + <% @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 t.name.presence || "Objectif ##{t.id}", t %> + <%= link_to target.name.presence || "Cible ##{t.id}", target %> </td> <td> - <% if t.target_allocations.empty? %> + <% 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-2"> - <% t.target_allocations.each do |a| %> + <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) %>% @@ -38,20 +36,8 @@ </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 ?" } %> + <%= l(target.created_at, format: :short) %> </td> </tr> <% end %> diff --git a/app/views/targets/new.html.erb b/app/views/targets/new.html.erb index 42cb7bd..e69de29 100644 --- a/app/views/targets/new.html.erb +++ b/app/views/targets/new.html.erb @@ -1,85 +0,0 @@ -<% content_for :title, "Ajouter une Cible" %> - -<h1 class="display-1">Ajouter une Cible</h1> - -<%= form_with(model: @target) do |f| %> - <div class="card shadow-sm"> - <div class="card-header"> - <%= f.text_field :name, class: "form-control", placeholder: "Nom de la cible" %> - </div> - - <div class="card-body p-0"> - <div class="table-responsive"> - <table class="table table-hover align-middle mb-0"> - <thead class="table-light"> - <tr> - <th>Profil</th> - <th class="text-end" style="width: 180px;">Proportion</th> - </tr> - </thead> - <tbody id="alloc-table-body"> - <%= f.fields_for :target_allocations do |af| %> - <% np = af.object.nutrient_profile %> - <tr> - <td> - <%= af.hidden_field :nutrient_profile_id %> - <strong><%= np&.name.capitalize || "Profil ##{af.object.nutrient_profile_id}" %></strong> - </td> - <td class="text-end"> - <div class="input-group input-group-sm" style="max-width: 160px; margin-left:auto;"> - <%= af.number_field :percentage, - in: 0..100, step: 0.5, - class: "form-control text-end alloc-input", - placeholder: "0.0", - data: { action: "input->alloc#sum" } %> - <span class="input-group-text">%</span> - </div> - </td> - </tr> - <% end %> - </tbody> - <tfoot> - <tr> - <td class="small text-muted">Ajustez chaque pourcentage pour totaliser 100%.</td> - <td class="text-end"> - <span class="badge bg-secondary" id="alloc-total">Total : 0%</span> - </td> - </tr> - </tfoot> - </table> - </div> - </div> - - <div class="card-footer d-flex gap-2 justify-content-end"> - <div class="btn-group"> - <%= f.submit "Enregistrer l’objectif", class: "btn btn-primary", id: "submit-btn" %> - <%= link_to "Annuler", targets_path, class: "btn btn-secondary" %> - </div> - </div> - </div> -<% end %> - -<script> - // Lightweight client-side sum check (no Stimulus required). - document.addEventListener("turbo:load", initAllocSum); - document.addEventListener("DOMContentLoaded", initAllocSum); - - function initAllocSum() { - const inputs = document.querySelectorAll(".alloc-input"); - const totalBadge = document.getElementById("alloc-total"); - const submitBtn = document.getElementById("submit-btn"); - if (!inputs.length || !totalBadge) return; - - function updateTotal() { - let sum = 0; - inputs.forEach(i => sum += parseFloat(i.value || "0")); - const rounded = Math.round(sum * 100) / 100; - totalBadge.textContent = `Total : ${rounded}%`; - totalBadge.className = "badge " + (Math.abs(rounded - 100) < 0.01 ? "bg-success" : "bg-danger"); - if (submitBtn) submitBtn.disabled = !(Math.abs(rounded - 100) < 0.01); - } - - inputs.forEach(i => i.addEventListener("input", updateTotal)); - updateTotal(); - } -</script> |