diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index acd8d2b669..c2cccc7658 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -6,7 +6,19 @@ 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, :name).group_by(&:departement_number) + + territories_without_department = territories_with_phone_number.where.not(departement_number: Territory::DEPARTEMENTS_NAMES.keys) + .order(: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 6257b2159f..e9030ded30 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, @@ -65,9 +68,6 @@ class Territory < ApplicationRecord where(id: Organisation.with_upcoming_rdvs.distinct.select(:territory_id)) } scope :ordered_by_name, -> { order(Arel.sql("unaccent(LOWER(territories.name))")) } - scope :with_phone_number_formatted, -> { where.not(phone_number_formatted: nil) } - scope :with_valid_department, -> { where(departement_number: DEPARTEMENTS_NAMES.keys) } - scope :with_invalid_department, -> { where.not(departement_number: DEPARTEMENTS_NAMES.keys) } ## - @@ -134,9 +134,6 @@ def department_name private - DEPARTEMENTS_NAMES = CSV.read(Rails.root.join("lib/assets/departements_fr.csv"), headers: :first_row) - .to_h { [_1["number"], _1["name"]] }.freeze - 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 1e39426a14..3ab05e0a7a 100644 --- a/app/views/static_pages/contact.html.slim +++ b/app/views/static_pages/contact.html.slim @@ -1,6 +1,6 @@ - content_for :title, "Contact" -- Territory.with_phone_number_formatted.with_valid_department.order(:departement_number, :name).group_by(&:departement_number).each do |department_number, territories| +- 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| @@ -10,7 +10,7 @@ h2 Autres contacts ul.list-group.mb-2 - - Territory.with_phone_number_formatted.with_invalid_department.order(:name).each do |territory| + - territories_without_department.each do |territory| li span> #{territory.name} = link_to territory.phone_number, "tel:#{territory.phone_number_formatted}"