diff --git a/app/decorators/modele_decorator.rb b/app/decorators/modele_decorator.rb new file mode 100644 index 000000000..beb4cbf77 --- /dev/null +++ b/app/decorators/modele_decorator.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class ModeleDecorator < ApplicationDecorator + 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(", ") + end +end diff --git a/app/decorators/server_decorator.rb b/app/decorators/server_decorator.rb new file mode 100644 index 000000000..52c7fbabb --- /dev/null +++ b/app/decorators/server_decorator.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class ServerDecorator < ApplicationDecorator + 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(", ") + end +end 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/index.html.erb b/app/views/modeles/index.html.erb index 618fd1dbf..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.network_types.map { |type| Modele.human_attribute_name("network_types.#{type}") }.join(", ") %> + <%= 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 f138903c2..13f972bae 100644 --- a/app/views/modeles/show.html.erb +++ b/app/views/modeles/show.html.erb @@ -16,10 +16,8 @@
<%= @modele.public_send(attribute_name) %>
<% end %> -
<%= Modele.human_attribute_name(:network_types) %> :
-
- <%= @modele.network_types.map { |type| Modele.human_attribute_name("network_types.#{type}") }.join(", ") %> -
+
<%= Modele.human_attribute_name(:network_types) %>
+
<%= @modele.decorated.network_types_to_human %>
<% 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/index.html.erb b/app/views/servers/index.html.erb index fac78c88f..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.network_types.map { |type| Modele.human_attribute_name("network_types.#{type}") }.join(", ") %> + <%= 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 b3fc50d1d..991e4c1c7 100644 --- a/app/views/servers/show.html.erb +++ b/app/views/servers/show.html.erb @@ -199,9 +199,7 @@
<%= Server.human_attribute_name(:network_types) %>
-
- <%= @server.network_types.map { |type| Modele.human_attribute_name("network_types.#{type}") }.join(", ") %> -
+
<%= @server.decorated.network_types_to_human %>
<% 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 diff --git a/spec/decorators/modele_decorator_spec.rb b/spec/decorators/modele_decorator_spec.rb new file mode 100644 index 000000000..4292a920b --- /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_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)") } + 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..25ff408ac --- /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_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)") } + 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