Avis: add messagerie
This commit is contained in:
parent
d1540c4a68
commit
3dfd77e914
5 changed files with 57 additions and 1 deletions
|
@ -35,14 +35,28 @@ module NewGestionnaire
|
||||||
redirect_to instruction_avis_path(avis)
|
redirect_to instruction_avis_path(avis)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def messagerie
|
||||||
|
@avis = avis
|
||||||
|
@dossier = avis.dossier
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_commentaire
|
||||||
|
Commentaire.create(commentaire_params.merge(email: current_gestionnaire.email, dossier: avis.dossier))
|
||||||
|
redirect_to messagerie_avis_path(avis)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def avis
|
def avis
|
||||||
current_gestionnaire.avis.includes(dossier: [:avis]).find(params[:id])
|
current_gestionnaire.avis.includes(dossier: [:avis, :commentaires]).find(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def avis_params
|
def avis_params
|
||||||
params.require(:avis).permit(:answer)
|
params.require(:avis).permit(:answer)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def commentaire_params
|
||||||
|
params.require(:commentaire).permit(:body)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,3 +9,5 @@
|
||||||
= link_to 'Demande', avis_path(avis)
|
= link_to 'Demande', avis_path(avis)
|
||||||
%li{ class: current_page?(instruction_avis_path(avis)) ? 'active' : nil }
|
%li{ class: current_page?(instruction_avis_path(avis)) ? 'active' : nil }
|
||||||
= link_to 'Instruction', instruction_avis_path(avis)
|
= link_to 'Instruction', instruction_avis_path(avis)
|
||||||
|
%li{ class: current_page?(messagerie_avis_path(avis)) ? 'active' : nil }
|
||||||
|
= link_to 'Messagerie', messagerie_avis_path(avis)
|
||||||
|
|
21
app/views/new_gestionnaire/avis/messagerie.html.haml
Normal file
21
app/views/new_gestionnaire/avis/messagerie.html.haml
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
= render partial: 'header', locals: { avis: @avis, dossier: @dossier }
|
||||||
|
|
||||||
|
.messagerie.container
|
||||||
|
%ul
|
||||||
|
- @dossier.commentaires.ordered.each do |commentaire|
|
||||||
|
%li
|
||||||
|
= render partial: 'new_gestionnaire/dossiers/commentaire_icon', locals: { commentaire: commentaire, current_gestionnaire: current_gestionnaire }
|
||||||
|
|
||||||
|
.width-100
|
||||||
|
%h2
|
||||||
|
%span.mail
|
||||||
|
= render partial: 'new_gestionnaire/dossiers/commentaire_issuer', locals: { commentaire: commentaire, current_gestionnaire: current_gestionnaire }
|
||||||
|
- if ![current_gestionnaire.email, @dossier.user.email, 'contact@tps.apientreprise.fr'].include?(commentaire.email)
|
||||||
|
%span.guest Invité
|
||||||
|
%span.date= I18n.l(commentaire.created_at.localtime, format: '%H:%M le %d/%m/%Y')
|
||||||
|
%p= sanitize(commentaire.body)
|
||||||
|
|
||||||
|
= form_for(Commentaire.new, url: commentaire_avis_path(@avis), html: { class: 'form' }) do |f|
|
||||||
|
= f.text_area :body, rows: 5, placeholder: 'Répondre ici', required: true
|
||||||
|
.send-wrapper
|
||||||
|
= f.submit 'Envoyer', class: 'button send'
|
|
@ -261,6 +261,8 @@ Rails.application.routes.draw do
|
||||||
resources :avis, only: [:index, :show, :update] do
|
resources :avis, only: [:index, :show, :update] do
|
||||||
member do
|
member do
|
||||||
get 'instruction'
|
get 'instruction'
|
||||||
|
get 'messagerie'
|
||||||
|
post 'commentaire' => 'avis#create_commentaire'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
get "recherche" => "recherches#index"
|
get "recherche" => "recherches#index"
|
||||||
|
|
|
@ -43,6 +43,14 @@ describe NewGestionnaire::AvisController, type: :controller do
|
||||||
it { expect(assigns(:dossier)).to eq(dossier) }
|
it { expect(assigns(:dossier)).to eq(dossier) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#messagerie' do
|
||||||
|
before { get :messagerie, { id: avis_without_answer.id } }
|
||||||
|
|
||||||
|
it { expect(response).to have_http_status(:success) }
|
||||||
|
it { expect(assigns(:avis)).to eq(avis_without_answer) }
|
||||||
|
it { expect(assigns(:dossier)).to eq(dossier) }
|
||||||
|
end
|
||||||
|
|
||||||
describe '#update' do
|
describe '#update' do
|
||||||
before do
|
before do
|
||||||
patch :update, { id: avis_without_answer.id, avis: { answer: 'answer' } }
|
patch :update, { id: avis_without_answer.id, avis: { answer: 'answer' } }
|
||||||
|
@ -53,4 +61,13 @@ describe NewGestionnaire::AvisController, type: :controller do
|
||||||
it { expect(avis_without_answer.answer).to eq('answer') }
|
it { expect(avis_without_answer.answer).to eq('answer') }
|
||||||
it { expect(flash.notice).to eq('Votre réponse est enregistrée.') }
|
it { expect(flash.notice).to eq('Votre réponse est enregistrée.') }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#create_commentaire' do
|
||||||
|
before do
|
||||||
|
post :create_commentaire, { id: avis_without_answer.id, commentaire: { body: 'commentaire body' } }
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(response).to redirect_to(messagerie_avis_path(avis_without_answer)) }
|
||||||
|
it { expect(dossier.commentaires.map(&:body)).to match(['commentaire body']) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue