Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Network types locales + add help text on form #10

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/decorators/modele_decorator.rb
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions app/decorators/server_decorator.rb
Original file line number Diff line number Diff line change
@@ -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
11 changes: 10 additions & 1 deletion app/views/modeles/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
%>
<div id="networkTypesHelp" class="form-text fst-italic">
<%= Modele.human_attribute_name("network_types.help") %>
</div>
</fieldset>

<fieldset data-controller="nested-form" class="col-12 mt-4">
Expand Down
2 changes: 1 addition & 1 deletion app/views/modeles/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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| %>
Expand Down
6 changes: 2 additions & 4 deletions app/views/modeles/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
<dd class="mb-0 pb-2 ps-3"><%= @modele.public_send(attribute_name) %></dd>
<% end %>

<dt class="pb-2"><%= Modele.human_attribute_name(:network_types) %> :</dt>
<dd class="mb-0 pb-2 ps-3">
<%= @modele.network_types.map { |type| Modele.human_attribute_name("network_types.#{type}") }.join(", ") %>
</dd>
<dt class="pb-2"><%= Modele.human_attribute_name(:network_types) %></dt>
<dd class="mb-0 pb-2 ps-3"><%= @modele.decorated.network_types_to_human %></dd>
</dl>
<% end %>
</div>
Expand Down
11 changes: 10 additions & 1 deletion app/views/servers/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
%>
<div id="networkTypesHelp" class="form-text fst-italic">
<%= Modele.human_attribute_name("network_types.help") %>
</div>
</fieldset>

<fieldset class="col-md-6 col-12 mt-4 align-self-center">
Expand Down
2 changes: 1 addition & 1 deletion app/views/servers/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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| %>
Expand Down
4 changes: 1 addition & 3 deletions app/views/servers/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,7 @@
</dd>

<dt class="pb-2"><%= Server.human_attribute_name(:network_types) %></dt>
<dd class="mb-0 pb-2 ps-3">
<%= @server.network_types.map { |type| Modele.human_attribute_name("network_types.#{type}") }.join(", ") %>
</dd>
<dd class="mb-0 pb-2 ps-3"><%= @server.decorated.network_types_to_human %></dd>
</dl>
<% end %>
</div>
Expand Down
13 changes: 7 additions & 6 deletions config/locales/activerecord.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions spec/decorators/modele_decorator_spec.rb
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions spec/decorators/server_decorator_spec.rb
Original file line number Diff line number Diff line change
@@ -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