demarches-normaliennes/app/controllers/backoffice/dossiers_controller.rb

87 lines
2.7 KiB
Ruby
Raw Normal View History

2015-09-22 15:00:59 +02:00
class Backoffice::DossiersController < ApplicationController
2015-09-22 10:15:12 +02:00
before_action :authenticate_gestionnaire!
2015-08-10 11:05:06 +02:00
def show
2015-11-02 16:36:52 +01:00
initialize_instance_params params[:id]
2015-08-10 11:05:06 +02:00
end
def a_traiter
@dossiers_a_traiter = Dossier.a_traiter(current_gestionnaire)
@dossiers_a_traiter = @dossiers_a_traiter.paginate(:page => params[:page], :per_page => 12).decorate
total_dossiers_per_state
end
def en_attente
@dossiers_en_attente = Dossier.en_attente(current_gestionnaire)
@dossiers_en_attente = @dossiers_en_attente.paginate(:page => params[:page], :per_page => 12).decorate
total_dossiers_per_state
end
def termine
@dossiers_termine = Dossier.termine(current_gestionnaire)
@dossiers_termine = @dossiers_termine.paginate(:page => params[:page], :per_page => 12).decorate
total_dossiers_per_state
end
def search
@search_terms = params[:q]
@dossiers_search, @dossier = Dossier.search(current_gestionnaire, @search_terms)
unless @dossiers_search.empty?
@dossiers_search = @dossiers_search.paginate(:page => params[:page], :per_page => 12).decorate
end
@dossier = @dossier.decorate unless @dossier.nil?
total_dossiers_per_state
rescue RuntimeError
@dossiers_search = []
end
def valid
2015-11-02 16:36:52 +01:00
initialize_instance_params params[:dossier_id]
@dossier.next_step! 'gestionnaire', 'valid'
flash.notice = 'Dossier confirmé avec succès.'
render 'show'
end
def close
2015-11-02 16:36:52 +01:00
initialize_instance_params params[:dossier_id]
@dossier.next_step! 'gestionnaire', 'close'
flash.notice = 'Dossier traité avec succès.'
render 'show'
end
2015-11-02 16:36:52 +01:00
private
def total_dossiers_per_state
@dossiers_a_traiter_total = !@dossiers_a_traiter.nil? ? @dossiers_a_traiter.size : Dossier.a_traiter(current_gestionnaire).size
@dossiers_en_attente_total = !@dossiers_en_attente.nil? ? @dossiers_en_attente.size : Dossier.en_attente(current_gestionnaire).size
@dossiers_termine_total = !@dossiers_termine.nil? ? @dossiers_termine.size : Dossier.termine(current_gestionnaire).size
end
2015-11-02 16:36:52 +01:00
def initialize_instance_params dossier_id
@dossier = Dossier.find(dossier_id)
@entreprise = @dossier.entreprise.decorate
@etablissement = @dossier.etablissement
@pieces_justificatives = @dossier.pieces_justificatives
@commentaires = @dossier.ordered_commentaires
2015-11-02 16:36:52 +01:00
@commentaires = @commentaires.all.decorate
@commentaire_email = current_gestionnaire.email
@procedure = @dossier.procedure
@dossier = @dossier.decorate
@champs = @dossier.ordered_champs
2015-11-02 16:36:52 +01:00
rescue ActiveRecord::RecordNotFound
flash.alert = t('errors.messages.dossier_not_found')
redirect_to url_for(controller: '/backoffice')
end
2015-08-10 11:05:06 +02:00
end