demarches-normaliennes/app/controllers/new_gestionnaire/procedures_controller.rb
2017-09-06 11:11:14 +02:00

73 lines
2 KiB
Ruby

module NewGestionnaire
class ProceduresController < GestionnaireController
layout "new_application"
before_action :ensure_ownership!, except: [:index]
def index
@procedures = current_gestionnaire.procedures
dossiers = current_gestionnaire.dossiers.state_not_brouillon
@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
def show
@procedure = procedure
@a_suivre_dossiers = procedure
.dossiers
.without_followers
.en_cours
@followed_dossiers = current_gestionnaire
.followed_dossiers
.where(procedure: @procedure)
.en_cours
@termines_dossiers = procedure.dossiers.termine
@all_state_dossiers = procedure.dossiers.all_state
@archived_dossiers = procedure.dossiers.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
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