2017-06-29 15:30:42 +02:00
|
|
|
module NewGestionnaire
|
|
|
|
class ProceduresController < GestionnaireController
|
2017-07-03 14:05:55 +02:00
|
|
|
before_action :ensure_ownership!, except: [:index]
|
2017-09-07 16:04:53 +02:00
|
|
|
before_action :redirect_to_avis_if_needed, only: [:index]
|
2017-07-03 14:05:55 +02:00
|
|
|
|
|
|
|
def index
|
2017-07-18 15:18:10 +02:00
|
|
|
@procedures = current_gestionnaire.procedures.order(archived_at: :desc, published_at: :desc)
|
2017-07-03 14:05:55 +02:00
|
|
|
|
2017-07-18 15:18:54 +02:00
|
|
|
dossiers = current_gestionnaire.dossiers
|
2017-07-17 11:22:12 +02:00
|
|
|
@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
|
2017-07-03 14:05:55 +02:00
|
|
|
@dossiers_archived_count_per_procedure = dossiers.archived.group(:procedure_id).count
|
2017-07-17 11:22:12 +02:00
|
|
|
@dossiers_termines_count_per_procedure = dossiers.termine.group(:procedure_id).reorder(nil).count
|
2017-07-03 14:05:55 +02:00
|
|
|
|
2017-07-17 11:22:12 +02:00
|
|
|
@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
|
2017-07-03 14:05:55 +02:00
|
|
|
end
|
2017-06-29 15:30:42 +02:00
|
|
|
|
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
|
|
|
|
|
2017-07-31 18:35:34 +02:00
|
|
|
@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
|
2017-07-11 15:40:09 +02:00
|
|
|
|
|
|
|
@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
|
|
|
|
|
2017-06-29 15:30:42 +02:00
|
|
|
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
|
2017-09-07 16:04:53 +02:00
|
|
|
|
|
|
|
def redirect_to_avis_if_needed
|
|
|
|
if current_gestionnaire.procedures.count == 0 && current_gestionnaire.avis.count > 0
|
|
|
|
redirect_to avis_index_path
|
|
|
|
end
|
|
|
|
end
|
2017-06-29 15:30:42 +02:00
|
|
|
end
|
|
|
|
end
|