diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index acd8d2b669..721296b478 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -6,7 +6,21 @@ def mds def accessibility; end - def contact; end + def contact + territories_with_phone_number = Territory.where.not(phone_number_formatted: nil) + territories_group_by_department = territories_with_phone_number + .where(departement_number: Territory::DEPARTEMENTS_NAMES.keys) + .order(:departement_number).ordered_by_name.group_by(&:departement_number) + + territories_without_department = territories_with_phone_number + .where.not(departement_number: Territory::DEPARTEMENTS_NAMES.keys) + .ordered_by_name + + render locals: { + territories_group_by_department: territories_group_by_department, + territories_without_department: territories_without_department, + } + end def domaines; end diff --git a/app/models/territory.rb b/app/models/territory.rb index 98bf7e036d..051fd07c76 100644 --- a/app/models/territory.rb +++ b/app/models/territory.rb @@ -1,6 +1,9 @@ class Territory < ApplicationRecord has_paper_trail + DEPARTEMENTS_NAMES = CSV.read(Rails.root.join("lib/assets/departements_fr.csv"), headers: :first_row) + .to_h { [_1["number"], _1["name"]] }.freeze + SPECIAL_NAMES = [ MAIRIES_NAME = "Mairies".freeze, CNFS_NAME = "Conseillers Numériques".freeze, @@ -125,10 +128,11 @@ def waiting_room_enabled? end end - private + def department_name + DEPARTEMENTS_NAMES[departement_number] + end - DEPARTEMENTS_NAMES = CSV.read(Rails.root.join("lib/assets/departements_fr.csv"), headers: :first_row) - .to_h { [_1["number"], _1["name"]] }.freeze + private def fill_name_for_departements return if name.present? || departement_number.blank? diff --git a/app/views/static_pages/contact.html.slim b/app/views/static_pages/contact.html.slim index c1aea46f6f..7367ca7dfc 100644 --- a/app/views/static_pages/contact.html.slim +++ b/app/views/static_pages/contact.html.slim @@ -1,14 +1,21 @@ - content_for :title, "Contact" -h2 Votre département +- territories_group_by_department.each do |department_number, territories| + h2 #{department_number} - #{territories.first.department_name} + ul.list-group.mb-2 + - territories.each do |territory| + li + span> #{territory.name} + = link_to territory.phone_number, "tel:#{territory.phone_number_formatted}" + +h2 Autres contacts ul.list-group.mb-2 - - Territory.where.not(phone_number: nil).each do |territory| + - territories_without_department.each do |territory| li - span> #{territory} + span> #{territory.name} = link_to territory.phone_number, "tel:#{territory.phone_number_formatted}" - li - span> Autres départements, voir - = link_to "l'annuaire des services publics", "https://lannuaire.service-public.fr/" +span> Voir += link_to "l'annuaire des services publics", "https://lannuaire.service-public.fr/" .fr-grid-row.mt-4#tech-support .fr-col-md-8