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

Page de contacts : tri et groupement par département #4750

Merged
merged 4 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 très cool de génériser ce titre

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
Loading