From ceea4e8d869c0273d6bf20f62f96dbd84204b3c2 Mon Sep 17 00:00:00 2001 From: B_Rass Date: Wed, 16 Oct 2024 17:44:16 +0200 Subject: [PATCH 1/3] Update Network types locales + add help text on form --- app/views/modeles/_form.html.erb | 11 ++++++++++- app/views/modeles/show.html.erb | 8 ++++++-- app/views/servers/_form.html.erb | 11 ++++++++++- app/views/servers/show.html.erb | 6 +++++- config/locales/activerecord.fr.yml | 13 +++++++------ 5 files changed, 38 insertions(+), 11 deletions(-) diff --git a/app/views/modeles/_form.html.erb b/app/views/modeles/_form.html.erb index 2288f2481..e5e026691 100644 --- a/app/views/modeles/_form.html.erb +++ b/app/views/modeles/_form.html.erb @@ -56,7 +56,16 @@ <%= f.select :network_types, Modele::Network::TYPES.map { |type| [Modele.human_attribute_name("network_types.#{type}"), type] }, { prompt: true, include_blank: true }, - { class: "form-select", data: { controller: "select" }, multiple: true } %> + { + class: "form-select", + data: { controller: "select" }, + multiple: true, + placeholder: Modele.human_attribute_name("network_types.blank") + } + %> +
+ <%= Modele.human_attribute_name("network_types.help") %> +
diff --git a/app/views/modeles/show.html.erb b/app/views/modeles/show.html.erb index f138903c2..e623b9019 100644 --- a/app/views/modeles/show.html.erb +++ b/app/views/modeles/show.html.erb @@ -16,9 +16,13 @@
<%= @modele.public_send(attribute_name) %>
<% end %> -
<%= Modele.human_attribute_name(:network_types) %> :
+
<%= Modele.human_attribute_name(:network_types) %>
- <%= @modele.network_types.map { |type| Modele.human_attribute_name("network_types.#{type}") }.join(", ") %> + <% if network_types = @modele.network_types.presence %> + <%= network_types.map { |type| Modele.human_attribute_name("network_types.#{type}") }.join(", ") %> + <% else %> + <%= Modele.human_attribute_name("network_types.blank") %> + <% end %>
<% end %> diff --git a/app/views/servers/_form.html.erb b/app/views/servers/_form.html.erb index 0fd5d6a0d..e89ab6a24 100644 --- a/app/views/servers/_form.html.erb +++ b/app/views/servers/_form.html.erb @@ -68,7 +68,16 @@ <%= f.select :network_types, Modele::Network::TYPES.map { |type| [Modele.human_attribute_name("network_types.#{type}"), type] }, { prompt: true, include_blank: true }, - { class: "form-select", data: { controller: "select" }, multiple: true } %> + { + class: "form-select", + data: { controller: "select" }, + multiple: true, + placeholder: Modele.human_attribute_name("network_types.blank") + } + %> +
+ <%= Modele.human_attribute_name("network_types.help") %> +
diff --git a/app/views/servers/show.html.erb b/app/views/servers/show.html.erb index b3fc50d1d..5976d3697 100644 --- a/app/views/servers/show.html.erb +++ b/app/views/servers/show.html.erb @@ -200,7 +200,11 @@
<%= Server.human_attribute_name(:network_types) %>
- <%= @server.network_types.map { |type| Modele.human_attribute_name("network_types.#{type}") }.join(", ") %> + <% if network_types = @server.network_types.presence %> + <%= network_types.map { |type| Modele.human_attribute_name("network_types.#{type}") }.join(", ") %> + <% else %> + <%= Modele.human_attribute_name("network_types.blank") %> + <% end %>
<% end %> diff --git a/config/locales/activerecord.fr.yml b/config/locales/activerecord.fr.yml index 29da0d6ee..25d00bc0b 100644 --- a/config/locales/activerecord.fr.yml +++ b/config/locales/activerecord.fr.yml @@ -96,7 +96,7 @@ fr: modele_id: Modèle critique: Critique gestion_id: Gestionnaire - network_types: Type de visualisation + network_types: Composant réseau stack: Stack stack_id: Stack comment: Commentaire @@ -236,12 +236,13 @@ fr: manufacturer_id: Constructeur nb_elts: Nb d'éléments color: Couleur - network_types: Type de visualisation + network_types: Composant réseau modele/network_types: - gbe: Composant Réseau Gb - 10gbe: Composant Réseau 10 Gb - fiber: Composant Réseau Fibre - blank: Pas de + gbe: Backbone Gbps + 10gbe: Backbone 10Gbps + fiber: Backbone Fibre + blank: Non (par défaut) + help: Représentation ou non sur les dashboard d'infrastructure réseau short_gbe: Gb short_10gbe: 10 Gb short_fiber: Fibre From 22f31d2d7f3989a1ed194aeffa98a32693849bfe Mon Sep 17 00:00:00 2001 From: B_Rass Date: Tue, 29 Oct 2024 11:04:24 +0100 Subject: [PATCH 2/3] Create Modele & Server decorators for network_types to sentence methods --- app/decorators/modele_decorator.rb | 9 ++++++++ app/decorators/server_decorator.rb | 9 ++++++++ app/views/modeles/index.html.erb | 2 +- app/views/modeles/show.html.erb | 8 +------ app/views/servers/index.html.erb | 2 +- app/views/servers/show.html.erb | 8 +------ spec/decorators/modele_decorator_spec.rb | 28 ++++++++++++++++++++++++ spec/decorators/server_decorator_spec.rb | 28 ++++++++++++++++++++++++ 8 files changed, 78 insertions(+), 16 deletions(-) create mode 100644 app/decorators/modele_decorator.rb create mode 100644 app/decorators/server_decorator.rb create mode 100644 spec/decorators/modele_decorator_spec.rb create mode 100644 spec/decorators/server_decorator_spec.rb diff --git a/app/decorators/modele_decorator.rb b/app/decorators/modele_decorator.rb new file mode 100644 index 000000000..13286171b --- /dev/null +++ b/app/decorators/modele_decorator.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class ModeleDecorator < ApplicationDecorator + def network_types_to_s + return Modele.human_attribute_name("network_types.blank") unless (n_t = network_types.presence) + + n_t.map { |type| Modele.human_attribute_name("network_types.#{type}") }.join(", ") + end +end diff --git a/app/decorators/server_decorator.rb b/app/decorators/server_decorator.rb new file mode 100644 index 000000000..b6e7940e2 --- /dev/null +++ b/app/decorators/server_decorator.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class ServerDecorator < ApplicationDecorator + def network_types_to_s + return Modele.human_attribute_name("network_types.blank") unless (n_t = network_types.presence) + + n_t.map { |type| Modele.human_attribute_name("network_types.#{type}") }.join(", ") + end +end diff --git a/app/views/modeles/index.html.erb b/app/views/modeles/index.html.erb index 618fd1dbf..cbd387421 100644 --- a/app/views/modeles/index.html.erb +++ b/app/views/modeles/index.html.erb @@ -93,7 +93,7 @@ <% end %> <% table.with_column(Modele.human_attribute_name(:network_types)) do |modele| %> - <%= modele.network_types.map { |type| Modele.human_attribute_name("network_types.#{type}") }.join(", ") %> + <%= modele.decorated.network_types_to_s %> <% end %> <% table.with_column(style: "min-width: 70px; width: 70px") do |modele| %> diff --git a/app/views/modeles/show.html.erb b/app/views/modeles/show.html.erb index e623b9019..00063cb03 100644 --- a/app/views/modeles/show.html.erb +++ b/app/views/modeles/show.html.erb @@ -17,13 +17,7 @@ <% end %>
<%= Modele.human_attribute_name(:network_types) %>
-
- <% if network_types = @modele.network_types.presence %> - <%= network_types.map { |type| Modele.human_attribute_name("network_types.#{type}") }.join(", ") %> - <% else %> - <%= Modele.human_attribute_name("network_types.blank") %> - <% end %> -
+
<%= @modele.decorated.network_types_to_s %>
<% end %> diff --git a/app/views/servers/index.html.erb b/app/views/servers/index.html.erb index fac78c88f..f0f2d0593 100644 --- a/app/views/servers/index.html.erb +++ b/app/views/servers/index.html.erb @@ -152,7 +152,7 @@ <% end %> <% table.with_column(Server.human_attribute_name(:network_types)) do |server| %> - <%= server.network_types.map { |type| Modele.human_attribute_name("network_types.#{type}") }.join(", ") %> + <%= server.decorated.network_types_to_s %> <% end %> <% table.with_column(style: "min-width: 100px; width: 100px") do |server| %> diff --git a/app/views/servers/show.html.erb b/app/views/servers/show.html.erb index 5976d3697..fb8645f3d 100644 --- a/app/views/servers/show.html.erb +++ b/app/views/servers/show.html.erb @@ -199,13 +199,7 @@
<%= Server.human_attribute_name(:network_types) %>
-
- <% if network_types = @server.network_types.presence %> - <%= network_types.map { |type| Modele.human_attribute_name("network_types.#{type}") }.join(", ") %> - <% else %> - <%= Modele.human_attribute_name("network_types.blank") %> - <% end %> -
+
<%= @server.decorated.network_types_to_s %>
<% end %> diff --git a/spec/decorators/modele_decorator_spec.rb b/spec/decorators/modele_decorator_spec.rb new file mode 100644 index 000000000..3dbd13300 --- /dev/null +++ b/spec/decorators/modele_decorator_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe ModeleDecorator, type: :decorator do + let(:modele) { modeles(:one) } + let(:decorated_modele) { modele.decorated } + + describe "#network_types_to_s" do + subject(:network_types_sentence) { decorated_modele.network_types_to_s } + + context "when modele has no network type" do + it { is_expected.to eq("Non (par défaut)") } + end + + context "when modele has one network type" do + before { modele.network_types = %w[gbe] } + + it { is_expected.to eq("Backbone Gbps") } + end + + context "when modele has many network types" do + before { modele.network_types = %w[10gbe fiber] } + + it { is_expected.to eq("Backbone 10Gbps, Backbone Fibre") } + end + end +end diff --git a/spec/decorators/server_decorator_spec.rb b/spec/decorators/server_decorator_spec.rb new file mode 100644 index 000000000..e0ccce20f --- /dev/null +++ b/spec/decorators/server_decorator_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe ServerDecorator, type: :decorator do + let(:server) { servers(:one) } + let(:decorated_server) { server.decorated } + + describe "#network_types_to_s" do + subject(:network_types_sentence) { decorated_server.network_types_to_s } + + context "when server has no network type" do + it { is_expected.to eq("Non (par défaut)") } + end + + context "when server has one network type" do + before { server.network_types = %w[gbe] } + + it { is_expected.to eq("Backbone Gbps") } + end + + context "when server has many network types" do + before { server.network_types = %w[10gbe fiber] } + + it { is_expected.to eq("Backbone 10Gbps, Backbone Fibre") } + end + end +end From 3c3f99f6f76777afde231fe7901a5770a98f9bee Mon Sep 17 00:00:00 2001 From: B_Rass Date: Tue, 29 Oct 2024 11:31:40 +0100 Subject: [PATCH 3/3] Clean code (rename the new method) --- app/decorators/modele_decorator.rb | 2 +- app/decorators/server_decorator.rb | 2 +- app/views/modeles/index.html.erb | 2 +- app/views/modeles/show.html.erb | 2 +- app/views/servers/index.html.erb | 2 +- app/views/servers/show.html.erb | 2 +- spec/decorators/modele_decorator_spec.rb | 4 ++-- spec/decorators/server_decorator_spec.rb | 4 ++-- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/decorators/modele_decorator.rb b/app/decorators/modele_decorator.rb index 13286171b..beb4cbf77 100644 --- a/app/decorators/modele_decorator.rb +++ b/app/decorators/modele_decorator.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class ModeleDecorator < ApplicationDecorator - def network_types_to_s + def network_types_to_human return Modele.human_attribute_name("network_types.blank") unless (n_t = network_types.presence) n_t.map { |type| Modele.human_attribute_name("network_types.#{type}") }.join(", ") diff --git a/app/decorators/server_decorator.rb b/app/decorators/server_decorator.rb index b6e7940e2..52c7fbabb 100644 --- a/app/decorators/server_decorator.rb +++ b/app/decorators/server_decorator.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class ServerDecorator < ApplicationDecorator - def network_types_to_s + def network_types_to_human return Modele.human_attribute_name("network_types.blank") unless (n_t = network_types.presence) n_t.map { |type| Modele.human_attribute_name("network_types.#{type}") }.join(", ") diff --git a/app/views/modeles/index.html.erb b/app/views/modeles/index.html.erb index cbd387421..b082faef6 100644 --- a/app/views/modeles/index.html.erb +++ b/app/views/modeles/index.html.erb @@ -93,7 +93,7 @@ <% end %> <% table.with_column(Modele.human_attribute_name(:network_types)) do |modele| %> - <%= modele.decorated.network_types_to_s %> + <%= modele.decorated.network_types_to_human %> <% end %> <% table.with_column(style: "min-width: 70px; width: 70px") do |modele| %> diff --git a/app/views/modeles/show.html.erb b/app/views/modeles/show.html.erb index 00063cb03..13f972bae 100644 --- a/app/views/modeles/show.html.erb +++ b/app/views/modeles/show.html.erb @@ -17,7 +17,7 @@ <% end %>
<%= Modele.human_attribute_name(:network_types) %>
-
<%= @modele.decorated.network_types_to_s %>
+
<%= @modele.decorated.network_types_to_human %>
<% end %> diff --git a/app/views/servers/index.html.erb b/app/views/servers/index.html.erb index f0f2d0593..735d6c79b 100644 --- a/app/views/servers/index.html.erb +++ b/app/views/servers/index.html.erb @@ -152,7 +152,7 @@ <% end %> <% table.with_column(Server.human_attribute_name(:network_types)) do |server| %> - <%= server.decorated.network_types_to_s %> + <%= server.decorated.network_types_to_human %> <% end %> <% table.with_column(style: "min-width: 100px; width: 100px") do |server| %> diff --git a/app/views/servers/show.html.erb b/app/views/servers/show.html.erb index fb8645f3d..991e4c1c7 100644 --- a/app/views/servers/show.html.erb +++ b/app/views/servers/show.html.erb @@ -199,7 +199,7 @@
<%= Server.human_attribute_name(:network_types) %>
-
<%= @server.decorated.network_types_to_s %>
+
<%= @server.decorated.network_types_to_human %>
<% end %> diff --git a/spec/decorators/modele_decorator_spec.rb b/spec/decorators/modele_decorator_spec.rb index 3dbd13300..4292a920b 100644 --- a/spec/decorators/modele_decorator_spec.rb +++ b/spec/decorators/modele_decorator_spec.rb @@ -6,8 +6,8 @@ let(:modele) { modeles(:one) } let(:decorated_modele) { modele.decorated } - describe "#network_types_to_s" do - subject(:network_types_sentence) { decorated_modele.network_types_to_s } + describe "#network_types_to_human" do + subject(:network_types_sentence) { decorated_modele.network_types_to_human } context "when modele has no network type" do it { is_expected.to eq("Non (par défaut)") } diff --git a/spec/decorators/server_decorator_spec.rb b/spec/decorators/server_decorator_spec.rb index e0ccce20f..25ff408ac 100644 --- a/spec/decorators/server_decorator_spec.rb +++ b/spec/decorators/server_decorator_spec.rb @@ -6,8 +6,8 @@ let(:server) { servers(:one) } let(:decorated_server) { server.decorated } - describe "#network_types_to_s" do - subject(:network_types_sentence) { decorated_server.network_types_to_s } + describe "#network_types_to_human" do + subject(:network_types_sentence) { decorated_server.network_types_to_human } context "when server has no network type" do it { is_expected.to eq("Non (par défaut)") }