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 +- 6 files changed, 95 insertions(+), 213 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 (limited to 'app/views/dashboard') 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" %> -- cgit v1.2.3