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

Rationalisation des contacts et réseaux sociaux #2459

Merged
merged 34 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
18816e9
DRY
arnaudlevy Nov 28, 2024
cad5649
better
arnaudlevy Nov 28, 2024
2bd0a4c
Merge branch 'main' into dry-socials
arnaudlevy Nov 28, 2024
2c0afba
Merge branch 'main' into dry-socials
arnaudlevy Nov 29, 2024
18d151c
clean
arnaudlevy Nov 29, 2024
6da1cbf
Merge branch 'dry-socials' of github.com:osunyorg/admin into dry-socials
arnaudlevy Nov 29, 2024
e0debe8
phone numbers and email groups
arnaudlevy Nov 29, 2024
211a700
Fix
arnaudlevy Nov 29, 2024
cf5b3b9
code climate
arnaudlevy Nov 29, 2024
07660af
dry show
arnaudlevy Nov 29, 2024
c3dcc71
climate
arnaudlevy Nov 29, 2024
17288a6
edit done
arnaudlevy Dec 2, 2024
12570db
Merge branch 'main' into dry-socials
arnaudlevy Dec 4, 2024
e5ddcbb
Merge branch 'main' into dry-socials
arnaudlevy Dec 5, 2024
5414084
Merge branch 'main' into dry-socials
arnaudlevy Dec 5, 2024
7f99ce7
fix
arnaudlevy Dec 5, 2024
cb0f051
Merge branch 'dry-socials' of github.com:osunyorg/admin into dry-socials
arnaudlevy Dec 5, 2024
fee9746
Fix
arnaudlevy Dec 5, 2024
d587767
Update app/views/admin/application/contact_details/_show.html.erb
arnaudlevy Dec 5, 2024
e8039d2
fixes
arnaudlevy Dec 5, 2024
b190bf1
Merge branch 'dry-socials' of github.com:osunyorg/admin into dry-socials
arnaudlevy Dec 5, 2024
f8876c5
public_send
SebouChu Dec 5, 2024
e437afc
fix
arnaudlevy Dec 5, 2024
7dc1e7d
rename variable to attribute
SebouChu Dec 5, 2024
78e1287
Fix
arnaudlevy Dec 5, 2024
0dd66e4
fix website social_email
SebouChu Dec 5, 2024
be49edb
check form builder and attribute name for emails
SebouChu Dec 5, 2024
e9949c0
Merge branch 'main' into dry-socials
arnaudlevy Dec 5, 2024
4e4cadd
fix
SebouChu Dec 5, 2024
2fcf012
Merge branch 'main' into dry-socials
arnaudlevy Dec 6, 2024
2b54dbf
Fix
arnaudlevy Dec 6, 2024
2663100
Merge branch 'main' into dry-socials
arnaudlevy Dec 6, 2024
68a21d8
conditional details
arnaudlevy Dec 6, 2024
6eba729
Merge branch 'main' into dry-socials
arnaudlevy Dec 9, 2024
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
8 changes: 8 additions & 0 deletions app/assets/stylesheets/commons/_address.sass
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
2 changes: 2 additions & 0 deletions app/controllers/admin/education/schools_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def index
def show
@programs = @school.programs.ordered(current_language)
@roles = @school.university_roles.ordered(current_language)
@websites = @school.websites.ordered(current_language)
@locations = @school.locations.ordered(current_language)
breadcrumb
end

Expand Down
2 changes: 1 addition & 1 deletion app/helpers/university/people_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def personal_attribute_visibility_tag(visibility_value)
hint_text = t("simple_form.hints.university_person.personal_data_visibility")
color_class_name = case visibility_value
when 'public'
'bg-primary'
'bg-success'
when 'restricted'
'bg-warning'
else
Expand Down
50 changes: 50 additions & 0 deletions app/services/contact_details.rb
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
9 changes: 6 additions & 3 deletions app/services/contact_details/phone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ class ContactDetails::Phone < ContactDetails::Base

def prepare_value
super
@value.remove! ' '
@value.remove! '.'
[' ', '.', '-'].each do |string|
arnaudlevy marked this conversation as resolved.
Show resolved Hide resolved
@value.remove! string
end
@value = "tel:#{@value}"
end

def prepare_label
super
@label.gsub! '.', ' '
['.', '-'].each do |string|
arnaudlevy marked this conversation as resolved.
Show resolved Hide resolved
@label.gsub! string, ' '
end
end
end
30 changes: 25 additions & 5 deletions app/services/osuny/address_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@ def initialize(about:, l10n: nil, language:)
@language = language
end

def present?
to_s.present?
end

def address
about.try(:address)
end

def address_name
l10n.try(:address_name)
end

def address_additional
l10n.try(:address_additional)
end
Expand Down Expand Up @@ -41,24 +49,36 @@ def to_s
end

# <address itemprop="address" itemscope itemtype="https://schema.org/PostalAddress">
# <span itemprop="name">noesya</span>
# <span itemprop="streetAddress">15 rue des Bouviers</span>
# <span itemprop="description">Quartier Saint-Michel</span>
# <span itemprop="postalCode">33000</span> <span itemprop="addressLocality">Bordeaux</span>
# <span itemprop="addressCountry">FRANCE</span>
# </address>
def to_html
html = '<address itemprop="address" itemscope itemtype="https://schema.org/PostalAddress">'
html += " <span itemprop=\"streetAddress\">#{address}</span>" if address.present?
html += " <span itemprop=\"description\">#{address_additional}</span>" if address_additional.present?
html += " <span itemprop=\"postalCode\">#{zipcode}</span>" if zipcode.present?
html += " <span itemprop=\"addressLocality\">#{city}</span>" if city.present?
html += " <span itemprop=\"addressCountry\">#{country.upcase}</span>" if country.present?
html += add_if address_name.present?,
" <span itemprop=\"name\">#{address_name}</span>"
html += add_if address.present?,
" <span itemprop=\"streetAddress\">#{address}</span>"
html += add_if address_additional.present?,
" <span itemprop=\"description\">#{address_additional}</span>"
html += add_if zipcode.present?,
" <span itemprop=\"postalCode\">#{zipcode}</span>"
html += add_if city.present?,
" <span itemprop=\"addressLocality\">#{city}</span>"
html += add_if country.present?,
" <span itemprop=\"addressCountry\">#{country&.upcase}</span>"
html += '</address>'
html
end

protected

def add_if(condition, text)
condition ? text : ''
end

def country_string
about.try(:country)
end
Expand Down
23 changes: 5 additions & 18 deletions app/views/admin/administration/locations/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,16 @@
<%= lf.hidden_field :language_id, value: current_language.id %>

<div class="row mb-5">
<div class="col-lg-4">
<%= render 'admin/application/featured_image/edit', f: lf, about: l10n %>
<div class="col-lg-3">
<%= lf.input :name %>
<%= render "admin/application/slug/form",
f: lf,
source: '#administration_location_localizations_attributes_0_name' %>
<%= render 'admin/application/featured_image/edit', f: lf, about: l10n %>
</div>
<div class="col-lg-8">
<%= lf.input :name %>
<div class="offset-lg-1 col-lg-8">
<%= render 'admin/application/summary/form', f: lf, about: l10n %>
<%= lf.input :address_name %>
<%= f.input :address %>
<%= lf.input :address_additional %>
<div class="row">
<div class="col-lg-4">
<%= f.input :zipcode %>
</div>
<div class="col-lg-8">
<%= f.input :city %>
</div>
</div>
<%= f.input :country, input_html: { class: 'form-select' } %>
<%= f.input :phone %>
<%= lf.input :url %>
<%= render 'admin/application/contact_details/edit', f: f, lf: lf, about: location, l10n: l10n %>
<%= f.association :programs,
as: :check_boxes,
collection: osuny_collection_tree(
Expand Down
29 changes: 1 addition & 28 deletions app/views/admin/administration/locations/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,40 +1,13 @@
<% content_for :title, @l10n %>


<div class="row">
<div class="col-lg-3">
<%= render 'admin/application/featured_image/show', about: @l10n, small: true %>
</div>
<div class="offset-lg-1 col-lg-8">
<%= render 'admin/application/summary/show', about: @l10n, small: true %>
<div class="mb-5">
<div class="row">
<div class="col-lg-6">
<%= osuny_label Administration::Location.human_attribute_name('address') %>
<p>
<% if @l10n.address_name.present? %>
<%= @l10n.address_name %><br>
<% end %>
<% if @location.address.present? %>
<%= @location.address %><br>
<% end %>
<% if @l10n.address_additional.present? %>
<%= @l10n.address_additional %><br>
<% end %>
<%= @location.zipcode %> <%= @location.city %> <%= @location.country %>
</p>
</div>
<div class="col-lg-6">
<% if @location.phone.present? %>
<%= osuny_label Administration::Location.human_attribute_name('phone') %>
<p><%= @location.phone %></p>
<% end %>
<% if @l10n.url.present? %>
<%= osuny_label Administration::Location::Localization.human_attribute_name('url') %>
<p><%= link_to @l10n.url, @l10n.url, target: :_blank %></p>
<% end %>
</div>
</div>
<%= render 'admin/application/contact_details/show', about: @location, l10n: @l10n %>
</div>
<% if @schools.any? %>
<%= osuny_panel Administration::Location.human_attribute_name('schools'), small: true do %>
Expand Down
17 changes: 4 additions & 13 deletions app/views/admin/administration/locations/static.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,10 @@ language = @l10n.language
<%= render 'admin/application/l10n/static', about: @l10n %>
<%= render 'admin/application/featured_image/static', about: @l10n %>
<%= render 'admin/application/summary/static', about: @l10n %>
contact_details:
<%= render 'admin/application/static/postal_address', about: location, l10n: @l10n, language: language %>
<%= render 'admin/application/static/contact_detail', variable: :address, data: location.address, kind: ContactDetails::Base %>
<%= render 'admin/application/static/contact_detail', variable: :address_name, data: @l10n.address_name, kind: ContactDetails::Base %>
<%= render 'admin/application/static/contact_detail', variable: :address_additional, data: @l10n.address_additional, kind: ContactDetails::Base %>
<%= render 'admin/application/static/contact_detail', variable: :zipcode, data: location.zipcode, kind: ContactDetails::Base %>
<%= render 'admin/application/static/contact_detail', variable: :city, data: location.city, kind: ContactDetails::Base %>
<%= render 'admin/application/static/contact_detail', variable: :country, data: location.country, kind: ContactDetails::Country %>
<%= render 'admin/application/static/contact_detail', variable: :website, data: @l10n.url, kind: ContactDetails::Website %>
<%= render 'admin/application/static/contact_detail', variable: :phone, data: location.phone, kind: ContactDetails::Phone %>
geolocation:
latitude: <%= location.latitude %>
longitude: <%= location.longitude %>
<%= render 'admin/application/contact_details/static',
about: location,
l10n: @l10n,
language: language %>
programs:
<%
location.programs.each do |program|
Expand Down
10 changes: 10 additions & 0 deletions app/views/admin/application/contact_details/_edit.html.erb
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 %>
9 changes: 9 additions & 0 deletions app/views/admin/application/contact_details/_show.html.erb
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 app/views/admin/application/contact_details/_static.html.erb
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
%>
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 %>
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 %>
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 %>
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 %>
Loading
Loading