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. --- 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 + 6 files changed, 162 insertions(+) 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/targets') 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