diff --git a/app/controllers/faq_controller.rb b/app/controllers/faq_controller.rb index 7d19499c3..a6b28d7ed 100644 --- a/app/controllers/faq_controller.rb +++ b/app/controllers/faq_controller.rb @@ -3,6 +3,10 @@ class FAQController < ApplicationController before_action :load_faq_data, only: :show + def index + @faqs = loader_service.all + end + def show @renderer = Redcarpet::Markdown.new( Redcarpet::BareRenderer.new(class_names_map: { list: 'fr-ol-content--override' }) diff --git a/app/services/faqs_loader_service.rb b/app/services/faqs_loader_service.rb index 95db7b63d..19acd97fb 100644 --- a/app/services/faqs_loader_service.rb +++ b/app/services/faqs_loader_service.rb @@ -22,6 +22,16 @@ class FAQsLoaderService .group_by { |faq| faq[:subcategory] } end + def all + @faqs_by_path.values + .group_by { |faq| faq.fetch(:category) } + .sort_by { |category, _| ORDER.index(category) || ORDER.size } + .to_h + .transform_values do |faqs| + faqs.group_by { |faq| faq.fetch(:subcategory) } + end + end + private def load_faqs diff --git a/app/views/faq/index.html.haml b/app/views/faq/index.html.haml new file mode 100644 index 000000000..e0c311e18 --- /dev/null +++ b/app/views/faq/index.html.haml @@ -0,0 +1,25 @@ +- content_for(:title, t('.meta_title')) + +.fr-container.fr-my-4w + .fr-grid-row + .fr-col-12.fr-col-md-10 + %h1= t('.title', app_name: Current.application_name) + + - @faqs.each do |category, subcategories| + %h2= t(:name, scope: [:faq, :categories, category], raise: true) + %p= t(:description, scope: [:faq, :categories, category], raise: true) + + .fr-accordions-group.fr-mb-6w + - subcategories.each_with_index do |(subcategory, faqs), index| + %section.fr-accordion + %h3.fr-accordion__title + %button.fr-accordion__btn{ 'aria-expanded': "false", 'aria-controls': "accordion-#{category}-#{index}" } + = t(:name, scope: [:faq, :subcategories, subcategory], raise: true) + + .fr-collapse{ id: "accordion-#{category}-#{index}" } + - description = t(:description, scope: [:faq, :subcategories, subcategory], default: nil) + %p= description if description.present? + + %ul + - faqs.each do |faq| + %li= link_to faq[:title], faq_path(category: faq[:category], slug: faq[:slug]), class: "fr-link" diff --git a/config/locales/faqs.fr.yml b/config/locales/faqs.fr.yml index f57a355c4..bf647efa8 100644 --- a/config/locales/faqs.fr.yml +++ b/config/locales/faqs.fr.yml @@ -1,5 +1,8 @@ fr: faq: + index: + meta_title: "Foire aux Questions" + title: Foire aux Questions (FAQ) de %{app_name} sidebar_button: Dans cette Foire Aux Questions categories: usager: diff --git a/config/routes.rb b/config/routes.rb index b5b8520d2..cb068da33 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -715,6 +715,7 @@ Rails.application.routes.draw do resources :release_notes, only: [:index] + resources :faq, only: [:index] get '/faq/:category/:slug', to: 'faq#show', as: :faq get '/404', to: 'errors#not_found'