From 7116826b854188604e21e2a613ac6672b6fd81f3 Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Mon, 8 Sep 2025 21:21:56 +0200 Subject: Create Target and nutrient target table on dashboard. --- .../dashboard/_nutrient_measurements.html.erb | 22 --- .../_nutrient_measurements_table.html.erb | 18 ++ .../dashboard/_nutrient_profile_allocator.html.erb | 187 --------------------- .../dashboard/_nutrient_target_table.html.erb | 74 ++++++++ app/views/dashboard/_target_table.html.erb | 3 +- app/views/dashboard/index.html.erb | 4 +- app/views/nutrient_measurement/index.html.erb | 27 --- app/views/nutrient_measurements/_form.html.erb | 49 ++++++ app/views/nutrient_measurements/index.html.erb | 41 +++++ app/views/nutrient_measurements/new.html.erb | 11 ++ app/views/targets/create.html.erb | 2 + app/views/targets/edit.html.erb | 2 + app/views/targets/index.html.erb | 68 ++++++++ app/views/targets/new.html.erb | 85 ++++++++++ app/views/targets/show.html.erb | 3 + app/views/targets/update.html.erb | 2 + 16 files changed, 358 insertions(+), 240 deletions(-) delete mode 100644 app/views/dashboard/_nutrient_measurements.html.erb create mode 100644 app/views/dashboard/_nutrient_measurements_table.html.erb delete mode 100644 app/views/dashboard/_nutrient_profile_allocator.html.erb create mode 100644 app/views/dashboard/_nutrient_target_table.html.erb delete mode 100644 app/views/nutrient_measurement/index.html.erb create mode 100644 app/views/nutrient_measurements/_form.html.erb create mode 100644 app/views/nutrient_measurements/index.html.erb create mode 100644 app/views/nutrient_measurements/new.html.erb create mode 100644 app/views/targets/create.html.erb create mode 100644 app/views/targets/edit.html.erb create mode 100644 app/views/targets/index.html.erb create mode 100644 app/views/targets/new.html.erb create mode 100644 app/views/targets/show.html.erb create mode 100644 app/views/targets/update.html.erb (limited to 'app/views') diff --git a/app/views/dashboard/_nutrient_measurements.html.erb b/app/views/dashboard/_nutrient_measurements.html.erb deleted file mode 100644 index bc63a60..0000000 --- a/app/views/dashboard/_nutrient_measurements.html.erb +++ /dev/null @@ -1,22 +0,0 @@ -
-
-
Nutrient Measurements
-
- <%#= link_to "Add new measurement", editor_rafts_path, class: "btn btn-sm btn-primary" %> - <%#= link_to "View all", editor_rafts_path, class: "btn btn-sm btn-secondary" %> -
-
- -
-
- <%= line_chart @npk_measurement_data, - title: "NPK", - ytitle: "Concentration (mg/L)" %> -
-
- <%= line_chart @ammonium_measurement_data, - title: "Ammonium", - ytitle: "Concentration (mg/L)" %> -
-
-
diff --git a/app/views/dashboard/_nutrient_measurements_table.html.erb b/app/views/dashboard/_nutrient_measurements_table.html.erb new file mode 100644 index 0000000..82ea6ff --- /dev/null +++ b/app/views/dashboard/_nutrient_measurements_table.html.erb @@ -0,0 +1,18 @@ +
+
+

Relevé des Nutriments

+
+ <%= 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" %> +
+
+ +
+ <%= line_chart @npk_measurement_data, + title: "NPK", + ytitle: "Concentration (mg/L)" %> + <%= line_chart @ammonium_measurement_data, + title: "Ammonium", + ytitle: "Concentration (mg/L)" %> +
+
diff --git a/app/views/dashboard/_nutrient_profile_allocator.html.erb b/app/views/dashboard/_nutrient_profile_allocator.html.erb deleted file mode 100644 index d402ace..0000000 --- a/app/views/dashboard/_nutrient_profile_allocator.html.erb +++ /dev/null @@ -1,187 +0,0 @@ -<%# Props: nutrient_profiles: ActiveRecord::Relation %> -<%# Fallback if controller didn't set @nutrient_profiles yet %> -<% profiles = (local_assigns[:nutrient_profiles] || []).presence || [] %> - -<%# We'll render a form purely for structure (no real submit yet) %> -<%= form_with url: "#", method: :post, local: true, html: { id: "np-mix-form", "data-controller": "np-mix" } do %> -
-
- -
-
- Choisissez des profils de croissance et répartissez-les pour totaliser 100%. -
-
- Somme : 0% -
-
- -
- <%# Rows are injected by JS from the template below, including defaults %> -
- -
- - - <%# Placeholder "save" button for later backend wiring; disabled until total == 100 %> - -
-
-
- - <%# --- Hidden template for a single row --- %> - - - <%# --- Defaults to inject on load --- %> - - - <%# --- Tiny inline JS to keep this self-contained (no Stimulus required) --- %> - - - -<% end %> diff --git a/app/views/dashboard/_nutrient_target_table.html.erb b/app/views/dashboard/_nutrient_target_table.html.erb new file mode 100644 index 0000000..7cf294c --- /dev/null +++ b/app/views/dashboard/_nutrient_target_table.html.erb @@ -0,0 +1,74 @@ +
+
+

Complémentation

+
+ <%= 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" %> +
+
+ +
+
+ + + + + + + + + + + <% 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 %> + + + + + + + + + + <% end %> + +
NutrimentRelevéCibleDelta
<%= nut.upcase %> + <% if measured.nil? %> + + <% else %> + <%= number_with_precision(measured, precision: 2) %> + <% end %> + + <% if target.nil? %> + + <% else %> + <%= number_with_precision(target, precision: 2) %> + <% end %> + + <% if measured.nil? && target.nil? %> + + <% 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 %> + + <%= number_with_precision(delta.to_f, precision: 2) %> + + <% end %> +
+
+
+
diff --git a/app/views/dashboard/_target_table.html.erb b/app/views/dashboard/_target_table.html.erb index b8f7e66..b1553dc 100644 --- a/app/views/dashboard/_target_table.html.erb +++ b/app/views/dashboard/_target_table.html.erb @@ -9,8 +9,7 @@ Nutrient - Latest (mg/L) - + Latest (mg/L) Target (mg/L) Δ % diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index b8f9145..a954e4c 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -1,9 +1,9 @@

Ferti

-<%= render "nutrient_profile_allocator", nutrient_profiles: @nutrient_profiles %> +<%= render "nutrient_target_table", nutrient_profiles: @nutrient_profiles %> <%#= render "raft_allocation" %> <%#= render "target_table" %> -<%#= render "nutrient_measurements" %> +<%= render "nutrient_measurements_table" %> diff --git a/app/views/nutrient_measurement/index.html.erb b/app/views/nutrient_measurement/index.html.erb deleted file mode 100644 index d9f522e..0000000 --- a/app/views/nutrient_measurement/index.html.erb +++ /dev/null @@ -1,27 +0,0 @@ -

NutrientMeasurement#index

-

Find me in app/views/nutrient_measurement/index.html.erb

- -
- - - - - - - - - - - - <% @measurements.each do |m| %> - - - - - - - - <% end %> - -
DateN (total)PKNH₄‑N
<%= l(m.measured_on) %><%= fmt2(total_n(m)) %><%= fmt2(m.p) %><%= fmt2(m.k) %><%= fmt2(m.nnh4) %>
-
diff --git a/app/views/nutrient_measurements/_form.html.erb b/app/views/nutrient_measurements/_form.html.erb new file mode 100644 index 0000000..9689c57 --- /dev/null +++ b/app/views/nutrient_measurements/_form.html.erb @@ -0,0 +1,49 @@ +<%= form_with(model: nutrient_measurement) do |form| %> + <% if nutrient_measurement.errors.any? %> +
+

<%= pluralize(nutrient_measurement.errors.count, "erreur") %> empêchent l’enregistrement :

+
    + <% nutrient_measurement.errors.full_messages.each do |msg| %> +
  • <%= msg %>
  • + <% end %> +
+
+ <% end %> + +
+ <%= form.label :measured_on, "Date du relevé", class: "form-label" %> + <%= form.date_field :measured_on, class: "form-control", required: true %> +
+ +

Concentrations de nutriments — laisser vide si non mesuré

+ +
+ <% # You can reorganize into macros/micros if you prefer %> + <% labels = { + nno3: "Nitrate (N-NO₃)", p: "Phosphore (P)", k: "Potassium (K)", + ca: "Calcium (Ca)", mg: "Magnésium (Mg)", s: "Soufre (S)", + na: "Sodium (Na)", cl: "Chlore (Cl)", si: "Silicium (Si)", + fe: "Fer (Fe)", zn: "Zinc (Zn)", b: "Bore (B)", + mn: "Manganèse (Mn)", cu: "Cuivre (Cu)", mo: "Molybdène (Mo)", + nnh4: "Ammonium (N-NH₄)" + } %> + + <% NutrientMeasurement::NUTRIENT_FIELDS.each do |field| %> +
+
+ <%= form.number_field field, + class: "form-control", + placeholder: "—", + step: "0.01", + min: "0" %> + mg/L +
+ +
+ <% end %> +
+ +
+ <%= form.submit "Ajouter le relevé", class: "btn btn-primary" %> +
+<% end %> diff --git a/app/views/nutrient_measurements/index.html.erb b/app/views/nutrient_measurements/index.html.erb new file mode 100644 index 0000000..c01d0cc --- /dev/null +++ b/app/views/nutrient_measurements/index.html.erb @@ -0,0 +1,41 @@ +<% content_for :title, "Liste des Relevé" %> + +

Liste des Relevés

+ +
+
+ <%= link_to "Nouvelle mesure", new_nutrient_measurement_path, class: "btn btn-primary" %> + <%= link_to "Retour", root_path, class: "btn btn-outline-secondary" %> +
+
+ +
+ + + + + + + + + + + + <% @nutrient_measurements.each do |m| %> + + + + + + + + <% end %> + +
DateN (total)PKNH₄-N
<%= l(m.measured_on) %> + <%= number_with_precision(m.nno3.to_f + m.nnh4.to_f, precision: 2) if m.nno3 || m.nnh4 %> + <%= number_with_precision(m.p, precision: 2) if m.p %><%= number_with_precision(m.k, precision: 2) if m.k %><%= number_with_precision(m.nnh4, precision: 2) if m.nnh4 %>
+
+ +<%= line_chart @npk_measurement_data, + title: "NPK", + ytitle: "Concentration (mg/L)" %> diff --git a/app/views/nutrient_measurements/new.html.erb b/app/views/nutrient_measurements/new.html.erb new file mode 100644 index 0000000..82a913e --- /dev/null +++ b/app/views/nutrient_measurements/new.html.erb @@ -0,0 +1,11 @@ +<% content_for :title, "Ajouter un Relevé" %> + +

Ajouter un Relevé

+ +<%= render "form", nutrient_measurement: @nutrient_measurement %> + +
+ +
+ <%= link_to "Retour", root_path, class: "btn btn-secondary" %> +
diff --git a/app/views/targets/create.html.erb b/app/views/targets/create.html.erb new file mode 100644 index 0000000..51e2782 --- /dev/null +++ b/app/views/targets/create.html.erb @@ -0,0 +1,2 @@ +

Targets#create

+

Find me in app/views/targets/create.html.erb

diff --git a/app/views/targets/edit.html.erb b/app/views/targets/edit.html.erb new file mode 100644 index 0000000..849bf7f --- /dev/null +++ b/app/views/targets/edit.html.erb @@ -0,0 +1,2 @@ +

Targets#edit

+

Find me in app/views/targets/edit.html.erb

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 @@ +

Cibles

+ +
+ <%= link_to "Nouvelle Cible", new_target_path, class: "btn btn-primary" %> +
+ +
+ + + + + + + + + + + + <% 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" %> + + + + + + + + <% end %> + <% else %> + + + + <% end %> + +
NomRépartition
Total %Créé leActions
+ <%= link_to t.name.presence || "Objectif ##{t.id}", t %> + + <% if t.target_allocations.empty? %> + Aucune répartition définie + <% else %> +
    + <% t.target_allocations.each do |a| %> +
  • + <%= a.nutrient_profile&.name || "Profil ##{a.nutrient_profile_id}" %> + — <%= number_with_precision(a.percentage.to_f, precision: 2) %>% +
  • + <% end %> +
+ <% end %> +
+ + <%= number_with_precision(sum_pct, precision: 2) %>% + + + <%= l(t.created_at, format: :short) %> + + <%= 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 ?" } %> +
+ Aucun objectif pour le moment.  + <%= link_to "Créer le premier", new_target_path %>. +
+
diff --git a/app/views/targets/new.html.erb b/app/views/targets/new.html.erb new file mode 100644 index 0000000..42cb7bd --- /dev/null +++ b/app/views/targets/new.html.erb @@ -0,0 +1,85 @@ +<% content_for :title, "Ajouter une Cible" %> + +

Ajouter une Cible

+ +<%= form_with(model: @target) do |f| %> +
+
+ <%= f.text_field :name, class: "form-control", placeholder: "Nom de la cible" %> +
+ +
+
+ + + + + + + + + <%= f.fields_for :target_allocations do |af| %> + <% np = af.object.nutrient_profile %> + + + + + <% end %> + + + + + + + +
ProfilProportion
+ <%= af.hidden_field :nutrient_profile_id %> + <%= np&.name.capitalize || "Profil ##{af.object.nutrient_profile_id}" %> + +
+ <%= 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" } %> + % +
+
Ajustez chaque pourcentage pour totaliser 100%. + Total : 0% +
+
+
+ + +
+<% end %> + + diff --git a/app/views/targets/show.html.erb b/app/views/targets/show.html.erb new file mode 100644 index 0000000..1525609 --- /dev/null +++ b/app/views/targets/show.html.erb @@ -0,0 +1,3 @@ +

Targets#show

+ +<%# TODO: add table comparing this target with the most recent measurement. %> diff --git a/app/views/targets/update.html.erb b/app/views/targets/update.html.erb new file mode 100644 index 0000000..a39287c --- /dev/null +++ b/app/views/targets/update.html.erb @@ -0,0 +1,2 @@ +

Targets#update

+

Find me in app/views/targets/update.html.erb

-- cgit v1.2.3