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

88 lines
2.6 KiB
Ruby
Raw Normal View History

module NewGestionnaire
class ProceduresController < GestionnaireController
before_action :ensure_ownership!, except: [:index]
before_action :redirect_to_avis_if_needed, only: [: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
2017-08-30 11:12:58 +02:00
@notifications_count_per_procedure = current_gestionnaire.notifications_count_per_procedure
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-08-30 15:31:17 +02:00
.includes(:user, :notifications)
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
def redirect_to_avis_if_needed
if current_gestionnaire.procedures.count == 0 && current_gestionnaire.avis.count > 0
redirect_to avis_index_path
end
end
end
end