Skip to content

Commit

Permalink
Modification des routes et du fonctionnement des controlleurs
Browse files Browse the repository at this point in the history
  • Loading branch information
tnicolas1 committed Jan 24, 2025
1 parent 3de91da commit fedce58
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 38 deletions.
29 changes: 27 additions & 2 deletions app/controllers/asp/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ class ApplicationController < ActionController::Base

layout "application"

before_action :authenticate_asp_user!, except: :login
# TODO: Remettre l'authentification !
before_action :log_user,
:set_overrides
:set_overrides,
:infer_page_title

helper_method :current_user, :current_establishment

Expand Down Expand Up @@ -38,5 +39,29 @@ def set_overrides
@inhibit_nav = true
@logout_path = :destroy_asp_user_session
end

def infer_page_title(attrs = {})
key = page_title_key

return unless I18n.exists?(key)

title, breadcrumb = extract_title_data(I18n.t(key, deep_interpolation: true, **attrs))

@page_title = title

add_breadcrumb(breadcrumb)
end

def page_title_key
["pages", "titles", "asp", controller_name, action_name].join(".")
end

def extract_title_data(data)
if data.is_a? Hash
[data[:title], data[:breadcrumb]]
else
[data, data]
end
end
end
end
37 changes: 13 additions & 24 deletions app/controllers/asp/schoolings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,15 @@ module ASP
class SchoolingsController < ApplicationController
layout "application"

before_action :sanitize_search,
:set_schooling_result,
:set_pfmps
before_action :set_pfmps, only: :show
before_action :set_search_result, :infer_page_title, only: :index

def index
@page_title = "Rechercher un dossier"
def index; end

return if @schooling.nil?

@inhibit_title = true

@page_title = "Dossier #{@schooling.asp_dossier_id}"
end
def show; end

private

def set_schooling_result
return if @search.blank?

@schooling = find_schooling_by_attributive_decision_filename
end

def set_pfmps
return if @schooling.nil?

Expand All @@ -35,16 +22,18 @@ def set_pfmps
.distinct
end

def set_search_result
@attributive_decision_number = params[:search]

return if @attributive_decision_number.blank?

@schoolings = find_schooling_by_attributive_decision_filename || []
end

def find_schooling_by_attributive_decision_filename
Schooling
.joins(:attributive_decision_blob)
.find_by("filename LIKE ?", "%_#{@search}.pdf")
end

def sanitize_search
return if params[:search].blank?

@search = params[:search].strip.upcase
.find_by("filename LIKE ?", "%_#{@attributive_decision_number.strip.upcase}.pdf")
end
end
end
31 changes: 20 additions & 11 deletions app/views/asp/schoolings/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
.fr-mb-3w
= form_with method: :get, url: asp_schoolings_path do |form|
.fr-search-bar.fr-search-bar--lg.fr-col-md-8#search
= form.label :search, "Numéro de décision d'attribution", class: "fr-label"
= form.text_field :search, placeholder: "Numéro de décision d'attribution", value: @search, class: "fr-input"
= form.button "Rechercher", type: "submit", class: "fr-btn"
.fr-search-bar.fr-search-bar--lg.fr-col-md-8{id: "search", role: "search"}
= form.label :search, "Numéro de décision d'attribution...", class: "fr-label"
= form.text_field :search, placeholder: "Numéro de décision d'attribution", value: @attributive_decision_number, class: "fr-input"
= form.button "Rechercher", type: "submit", class: "fr-btn", name: nil



- if @search.blank?
- if @attributive_decision_number.blank?
.fr-mb-5w
Entrez un numéro de décision d'attribution pour lancer une recherche

- elsif @schooling.blank?
- elsif @schoolings.none?
.fr-mb-5w
Aucune décision d'attribution trouvée avec le numéro
= @search
Aucune décision d'attribution trouvée avec le numéro : #{@attributive_decision_number}

- else
= render partial: "schooling"
.fr-table
%table
%caption #{@schoolings.count} résultats trouvés pour la recherche : #{@attributive_decision_number}
%thead
%td{scope: "col"} Dossiers
%th{scope: "col"} Élèves
%th{scope: "col"} Dernière classe
%tbody
- @schoolings.each do |schooling|
%tr
%td= dsfr_link_to schooling.attributive_decision_number, asp_schoolings_path(schooling)
%td= schooling.student.full_name
%td= schooling.classe.label

File renamed without changes.
6 changes: 6 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ fr:
faq: F.A.Q.
pages:
titles:
asp:
application:
login: Connexion à APLyPro
schoolings:
index: Recherche d'un dossier
show: Dossier
stats:
index: Statistiques
school_years:
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# rubocop:disable Metrics/BlockLength
Rails.application.routes.draw do
namespace :asp do
resources :schoolings, only: :index
resources :schoolings, only: %i[index show]

devise_for :users, skip: :all, class_name: "ASP::User"
end
Expand Down

0 comments on commit fedce58

Please sign in to comment.