-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rationalisation des contacts et réseaux sociaux (#2459)
* DRY * better * clean * phone numbers and email groups * Fix * code climate * dry show * climate * edit done * fix * Fix * Update app/views/admin/application/contact_details/_show.html.erb Co-authored-by: Sébastien Gaya <sebastien.gaya@gmail.com> * fixes * public_send * fix * rename variable to attribute * Fix * fix website social_email * check form builder and attribute name for emails * fix * Fix * conditional details --------- Co-authored-by: Sébastien Gaya <sebastien.gaya@gmail.com>
- Loading branch information
1 parent
ca267ef
commit 189cc95
Showing
57 changed files
with
838 additions
and
768 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
address | ||
margin-bottom: 0 | ||
[itemprop="name"], | ||
[itemprop="streetAddress"], | ||
[itemprop="description"] | ||
display: block | ||
[itemprop="name"] | ||
font-weight: bold |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,59 @@ | ||
class ContactDetails | ||
|
||
PARTS = [ | ||
:postal_address, | ||
:phone_numbers, | ||
:emails, | ||
:websites, | ||
:social_networks | ||
] | ||
|
||
SOCIAL_NETWORKS = [ | ||
:facebook, | ||
:github, | ||
:instagram, | ||
:linkedin, | ||
:mastodon, | ||
:peertube, | ||
:tiktok, | ||
:twitter, | ||
:vimeo, | ||
:x, | ||
:youtube | ||
] | ||
|
||
PHONES = [ | ||
:phone, | ||
:phone_mobile, | ||
:phone_professional, | ||
:phone_personal | ||
] | ||
|
||
def self.with_kind(kind) | ||
"ContactDetails::#{kind.to_s.camelize}".constantize | ||
end | ||
|
||
def self.for(kind, string) | ||
with_kind(kind).new(string) | ||
end | ||
|
||
def self.find_data(attribute, about, l10n, possible_prefix: nil) | ||
data = find_data_in_about_or_l10n(attribute, about, l10n) | ||
if data.nil? | ||
prefixed_method = "#{possible_prefix}#{attribute}" | ||
data = find_data_in_about_or_l10n(prefixed_method, about, l10n) | ||
end | ||
data | ||
end | ||
|
||
def self.find_social(attribute, about, l10n) | ||
find_data(attribute, about, l10n, possible_prefix: 'social_') | ||
end | ||
|
||
protected | ||
|
||
def self.find_data_in_about_or_l10n(method, about, l10n) | ||
return about.public_send(method) if about.respond_to?(method) | ||
return l10n.public_send(method) if l10n.present? && l10n.respond_to?(method) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
app/views/admin/application/contact_details/_edit.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<%= osuny_separator %> | ||
<%= render "admin/application/contact_details/edit/postal_address", f: f, lf: lf, about: about, l10n: l10n %> | ||
<%= osuny_separator %> | ||
<div class="row"> | ||
<%= render "admin/application/contact_details/edit/phone_numbers", f: f, lf: lf, about: about, l10n: l10n %> | ||
<%= render "admin/application/contact_details/edit/emails", f: f, lf: lf, about: about, l10n: l10n %> | ||
<%= render "admin/application/contact_details/edit/websites", f: f, lf: lf, about: about, l10n: l10n %> | ||
<%= render "admin/application/contact_details/edit/social_networks", f: f, lf: lf, about: about, l10n: l10n %> | ||
</div> | ||
<%= osuny_separator %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<% | ||
# Fallback l10n to the about if not present | ||
l10n ||= about | ||
%> | ||
<div class="row"> | ||
<% ContactDetails::PARTS.each do |part| %> | ||
<%= render "admin/application/contact_details/show/#{part}", about: about, l10n: l10n %> | ||
<% end %> | ||
</div> |
15 changes: 15 additions & 0 deletions
15
app/views/admin/application/contact_details/_static.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<% | ||
depth ||= 0 | ||
indentation = ' ' * depth | ||
l10n ||= nil | ||
language ||= l10n&.language | ||
%> | ||
<%= indentation %>contact_details: | ||
<% ContactDetails::PARTS.each do |part| %><%= | ||
render "admin/application/contact_details/static/#{part}", | ||
about: about, | ||
l10n: l10n, | ||
language: language, | ||
depth: depth+1 %><% | ||
end | ||
%> |
22 changes: 22 additions & 0 deletions
22
app/views/admin/application/contact_details/edit/_emails.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<% | ||
if about.respond_to?(:email) | ||
fb = f | ||
attribute_name = :email | ||
elsif about.respond_to?(:social_email) | ||
fb = f | ||
attribute_name = :social_email | ||
elsif l10n.respond_to?(:email) | ||
fb = lf | ||
attribute_name = :email | ||
elsif l10n.respond_to?(:social_email) | ||
fb = lf | ||
attribute_name = :social_email | ||
end | ||
if attribute_name.present? | ||
%> | ||
<div class="col-md-6"> | ||
<%= fb.input attribute_name, | ||
label: t('contact_details.emails.email.label'), | ||
hint: t('contact_details.emails.email.hint') %> | ||
</div> | ||
<% end %> |
11 changes: 11 additions & 0 deletions
11
app/views/admin/application/contact_details/edit/_phone_numbers.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<% | ||
ContactDetails::PHONES.each do |attribute| | ||
if about.respond_to?(attribute) | ||
%> | ||
<div class="col-md-6"> | ||
<%= f.input attribute, | ||
label: t("contact_details.phone_numbers.#{attribute}.label"), | ||
hint: t("contact_details.phone_numbers.#{attribute}.hint") %> | ||
</div> | ||
<% end %> | ||
<% end %> |
30 changes: 30 additions & 0 deletions
30
app/views/admin/application/contact_details/edit/_postal_address.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<% if about.respond_to?(:address) %> | ||
<%= lf.input :address_name, | ||
label: t('contact_details.postal_address.address_name.label'), | ||
hint: t('contact_details.postal_address.address_name.hint') if l10n.respond_to?(:address_name) %> | ||
<%= f.input :address, | ||
label: t('contact_details.postal_address.address.label'), | ||
hint: t('contact_details.postal_address.address.hint') %> | ||
<%= lf.input :address_additional, | ||
label: t('contact_details.postal_address.address_additional.label'), | ||
hint: t('contact_details.postal_address.address_additional.hint') if l10n.respond_to?(:address_name) %> | ||
<div class="row"> | ||
<div class="col-lg-2"> | ||
<%= f.input :zipcode, | ||
label: t('contact_details.postal_address.zipcode.label'), | ||
hint: t('contact_details.postal_address.zipcode.hint') %> | ||
</div> | ||
<div class="col-lg-5"> | ||
<%= f.input :city, | ||
label: t('contact_details.postal_address.city.label'), | ||
hint: t('contact_details.postal_address.city.hint') %> | ||
</div> | ||
<div class="col-lg-5"> | ||
<%= f.input :country, | ||
label: t('contact_details.postal_address.country.label'), | ||
hint: t('contact_details.postal_address.country.hint'), | ||
input_html: { class: 'form-select' } %> | ||
|
||
</div> | ||
</div> | ||
<% end %> |
18 changes: 18 additions & 0 deletions
18
app/views/admin/application/contact_details/edit/_social_networks.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<% | ||
ContactDetails::SOCIAL_NETWORKS.each do |attribute| | ||
method_raw = attribute | ||
method_prefixed = "social_#{attribute}" | ||
if l10n.respond_to?(method_raw) | ||
method = method_raw | ||
elsif l10n.respond_to?(method_prefixed) | ||
method = method_prefixed | ||
else | ||
next | ||
end | ||
%> | ||
<div class="col-md-6"> | ||
<%= lf.input method, | ||
label: t("contact_details.social_networks.#{attribute}.label"), | ||
hint: t("contact_details.social_networks.#{attribute}.hint") %> | ||
</div> | ||
<% end %> |
Oops, something went wrong.