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

213 lines
6.7 KiB
Ruby
Raw Normal View History

module NewGestionnaire
class DossiersController < ProceduresController
2017-12-01 12:57:01 +01:00
include ActionView::Helpers::NumberHelper
include ActionView::Helpers::TextHelper
after_action :mark_demande_as_read, only: :show
after_action :mark_messagerie_as_read, only: [:messagerie, :create_commentaire]
after_action :mark_avis_as_read, only: [:avis, :create_avis]
after_action :mark_annotations_privees_as_read, only: [:annotations_privees, :update_annotations]
def attestation
send_data(dossier.attestation.pdf.read, filename: 'attestation.pdf', type: 'application/pdf')
end
def show
@demande_seen_at = current_gestionnaire.follows.find_by(dossier: dossier)&.demande_seen_at
end
2017-07-19 11:08:53 +02:00
def messagerie
@commentaire = Commentaire.new
@messagerie_seen_at = current_gestionnaire.follows.find_by(dossier: dossier)&.messagerie_seen_at
2017-07-19 11:08:53 +02:00
end
def annotations_privees
@annotations_privees_seen_at = current_gestionnaire.follows.find_by(dossier: dossier)&.annotations_privees_seen_at
end
2017-09-26 14:38:16 +02:00
def avis
@avis_seen_at = current_gestionnaire.follows.find_by(dossier: dossier)&.avis_seen_at
@avis = Avis.new
2017-09-26 14:38:16 +02:00
end
def personnes_impliquees
2018-08-29 22:11:38 +02:00
@following_instructeurs_emails = dossier.followers_gestionnaires.pluck(:email)
@avis_emails = dossier.avis.includes(:gestionnaire).map(&:email_to_display)
@invites_emails = dossier.invites.map(&:email)
@potential_recipients = procedure.gestionnaires.reject { |g| g == current_gestionnaire }
end
def send_to_instructeurs
recipients = Gestionnaire.find(params[:recipients])
recipients.each do |recipient|
GestionnaireMailer.send_dossier(current_gestionnaire, dossier, recipient).deliver_later
end
flash.notice = "Dossier envoyé"
redirect_to(personnes_impliquees_gestionnaire_dossier_path(procedure, dossier))
end
def follow
current_gestionnaire.follow(dossier)
flash.notice = 'Dossier suivi'
redirect_back(fallback_location: gestionnaire_procedures_url)
end
def unfollow
2017-10-05 14:10:49 +02:00
current_gestionnaire.unfollow(dossier)
flash.notice = "Vous ne suivez plus le dossier nº #{dossier.id}"
redirect_back(fallback_location: gestionnaire_procedures_url)
end
def archive
dossier.update(archived: true)
current_gestionnaire.unfollow(dossier)
redirect_back(fallback_location: gestionnaire_procedures_url)
end
def unarchive
dossier.update(archived: false)
redirect_back(fallback_location: gestionnaire_procedures_url)
end
def passer_en_instruction
dossier.en_instruction!
current_gestionnaire.follow(dossier)
flash.notice = 'Dossier passé en instruction.'
render partial: 'state_button_refresh', locals: { dossier: dossier }
end
def repasser_en_construction
dossier.en_construction!
flash.notice = 'Dossier repassé en construction.'
render partial: 'state_button_refresh', locals: { dossier: dossier }
end
2017-12-01 12:57:01 +01:00
def terminer
if params[:dossier] && params[:dossier][:motivation].present?
dossier.motivation = params[:dossier][:motivation]
2017-12-01 12:57:01 +01:00
end
case params[:process_action]
when "refuser"
2017-12-05 17:43:32 +01:00
dossier.refuse!
dossier.save
flash.notice = "Dossier considéré comme refusé."
NotificationMailer.send_refused_notification(dossier).deliver_later
when "classer_sans_suite"
2017-12-05 17:43:32 +01:00
dossier.sans_suite!
dossier.save
flash.notice = "Dossier considéré comme sans suite."
NotificationMailer.send_without_continuation_notification(dossier).deliver_later
when "accepter"
2017-12-05 17:43:32 +01:00
dossier.accepte!
2018-07-25 17:16:24 +02:00
if dossier.attestation.nil?
dossier.attestation = dossier.build_attestation
dossier.save
end
flash.notice = "Dossier traité avec succès."
NotificationMailer.send_closed_notification(dossier).deliver_later
2017-12-01 12:57:01 +01:00
end
render partial: 'state_button_refresh', locals: { dossier: dossier }
2017-12-01 12:57:01 +01:00
end
def create_commentaire
@commentaire = CommentaireService.create(current_gestionnaire, dossier, commentaire_params)
if @commentaire.save
current_gestionnaire.follow(dossier)
flash.notice = "Message envoyé"
redirect_to messagerie_gestionnaire_dossier_path(procedure, dossier)
else
flash.alert = @commentaire.errors.full_messages
render :messagerie
end
end
2017-07-24 20:04:41 +02:00
def position
etablissement = dossier.etablissement
2018-10-01 13:24:37 +02:00
if etablissement.present?
point = Carto::Geocodeur.convert_adresse_to_point(etablissement.geo_adresse)
end
2017-07-24 20:04:41 +02:00
lon = "2.428462"
lat = "46.538192"
zoom = "13"
2018-01-11 19:04:39 +01:00
if point.present?
2017-07-24 20:04:41 +02:00
lon = point.x.to_s
lat = point.y.to_s
end
render json: { lon: lon, lat: lat, zoom: zoom, dossier_id: params[:dossier_id] }
end
2017-08-28 14:16:13 +02:00
def create_avis
@avis = Avis.new(avis_params.merge(claimant: current_gestionnaire, dossier: dossier))
if @avis.save
flash.notice = "Une demande d'avis a été envoyée à #{@avis.email_to_display}"
redirect_to avis_gestionnaire_dossier_path(procedure, dossier)
else
flash.now.alert = @avis.errors.full_messages
@avis_seen_at = current_gestionnaire.follows.find_by(dossier: dossier)&.avis_seen_at
render :avis
end
2017-08-28 14:16:13 +02:00
end
2017-08-02 15:33:23 +02:00
def update_annotations
dossier = current_gestionnaire.dossiers.includes(champs_private: :type_de_champ).find(params[:dossier_id])
# FIXME: add attachements validation, cf. Champ#piece_justificative_file_errors
dossier.update(champs_private_params)
redirect_to annotations_privees_gestionnaire_dossier_path(procedure, dossier)
2017-08-02 15:33:23 +02:00
end
def print
@dossier = dossier
render layout: "print"
end
private
def dossier
@dossier ||= current_gestionnaire.dossiers.find(params[:dossier_id])
end
def commentaire_params
params.require(:commentaire).permit(:body, :file)
end
2017-08-28 14:16:13 +02:00
def avis_params
params.require(:avis).permit(:email, :introduction, :confidentiel)
2017-08-28 14:16:13 +02:00
end
2017-08-02 15:33:23 +02:00
def champs_private_params
2018-04-03 17:53:14 +02:00
params.require(:dossier).permit(champs_private_attributes: [
:id, :primary_value, :secondary_value, :piece_justificative_file, :value, value: [],
2018-04-03 17:53:14 +02:00
etablissement_attributes: Champs::SiretChamp::ETABLISSEMENT_ATTRIBUTES
])
2017-08-02 15:33:23 +02:00
end
2017-12-01 12:57:01 +01:00
def mark_demande_as_read
current_gestionnaire.mark_tab_as_seen(dossier, :demande)
end
def mark_messagerie_as_read
current_gestionnaire.mark_tab_as_seen(dossier, :messagerie)
end
def mark_avis_as_read
current_gestionnaire.mark_tab_as_seen(dossier, :avis)
end
def mark_annotations_privees_as_read
current_gestionnaire.mark_tab_as_seen(dossier, :annotations_privees)
end
end
end