demarches-normaliennes/app/controllers/new_administrateur/groupe_instructeurs_controller.rb
2019-10-23 21:47:20 +02:00

63 lines
1.5 KiB
Ruby
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

module NewAdministrateur
class GroupeInstructeursController < AdministrateurController
ITEMS_PER_PAGE = 25
def index
@procedure = procedure
@groupes_instructeurs = paginated_groupe_instructeurs
end
def show
@procedure = procedure
@groupe_instructeur = groupe_instructeur
@instructeurs = groupe_instructeur
.instructeurs
.page(params[:page])
.per(ITEMS_PER_PAGE)
.order(:email)
end
def create
@groupe_instructeur = procedure
.groupe_instructeurs
.new(label: label, instructeurs: [current_administrateur.instructeur])
if @groupe_instructeur.save
redirect_to procedure_groupe_instructeur_path(procedure, @groupe_instructeur),
notice: "Le groupe dinstructeurs « #{label} » a été créé."
else
@procedure = procedure
@groupes_instructeurs = paginated_groupe_instructeurs
flash[:alert] = "le nom « #{label} » est déjà pris par un autre groupe."
render :index
end
end
private
def procedure
current_administrateur
.procedures
.includes(:groupe_instructeurs)
.find(params[:procedure_id])
end
def groupe_instructeur
procedure.groupe_instructeurs.find(params[:id])
end
def label
params[:groupe_instructeur][:label]
end
def paginated_groupe_instructeurs
procedure
.groupe_instructeurs
.page(params[:page])
.per(ITEMS_PER_PAGE)
.order(:label)
end
end
end