Skip to content

Commit

Permalink
Page de contacts : tri et groupement par département (#4750)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineGirard authored Oct 31, 2024
1 parent 5c3b163 commit 7df5fdc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
16 changes: 15 additions & 1 deletion app/controllers/static_pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 7 additions & 3 deletions app/models/territory.rb
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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?
Expand Down
19 changes: 13 additions & 6 deletions app/views/static_pages/contact.html.slim
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 7df5fdc

Please sign in to comment.