demarches-normaliennes/app/controllers/new_gestionnaire/procedures_controller.rb

81 lines
2.3 KiB
Ruby
Raw Normal View History

module NewGestionnaire
class ProceduresController < GestionnaireController
layout "new_application"
before_action :ensure_ownership!, except: [:index]
def index
@procedures = current_gestionnaire.procedures.order(archived_at: :desc, published_at: :desc)
dossiers = current_gestionnaire.dossiers
@dossiers_count_per_procedure = dossiers.all_state.group(:procedure_id).reorder(nil).count
@dossiers_a_suivre_count_per_procedure = dossiers.without_followers.en_cours.group(:procedure_id).reorder(nil).count
@dossiers_archived_count_per_procedure = dossiers.archived.group(:procedure_id).count
@dossiers_termines_count_per_procedure = dossiers.termine.group(:procedure_id).reorder(nil).count
@followed_dossiers_count_per_procedure = current_gestionnaire
.followed_dossiers
.en_cours
.where(procedure: @procedures)
.group(:procedure_id)
.reorder(nil)
.count
end
2017-07-11 16:09:03 +02:00
def show
@procedure = procedure
@a_suivre_dossiers = procedure
.dossiers
2017-07-31 18:00:43 +02:00
.includes(:user)
2017-07-11 16:09:03 +02:00
.without_followers
.en_cours
@followed_dossiers = current_gestionnaire
.followed_dossiers
2017-07-31 18:00:43 +02:00
.includes(:user)
2017-07-11 16:09:03 +02:00
.where(procedure: @procedure)
.en_cours
@followed_dossiers_id = current_gestionnaire
.followed_dossiers
.where(procedure: @procedure)
.pluck(:id)
2017-07-31 18:00:43 +02:00
@termines_dossiers = procedure.dossiers.includes(:user).termine
2017-07-11 16:09:03 +02:00
2017-07-31 18:00:43 +02:00
@all_state_dossiers = procedure.dossiers.includes(:user).all_state
2017-07-11 16:09:03 +02:00
2017-07-31 18:00:43 +02:00
@archived_dossiers = procedure.dossiers.includes(:user).archived
@statut = params[:statut].present? ? params[:statut] : 'a-suivre'
@dossiers = case @statut
when 'a-suivre'
@a_suivre_dossiers
when 'suivis'
@followed_dossiers
when 'traites'
@termines_dossiers
when 'tous'
@all_state_dossiers
when 'archives'
@archived_dossiers
end
2017-07-11 16:09:03 +02:00
end
private
def procedure
Procedure.find(params[:procedure_id])
end
def ensure_ownership!
if !procedure.gestionnaires.include?(current_gestionnaire)
flash[:alert] = "Vous n'avez pas accès à cette procédure"
redirect_to root_path
end
end
end
end