Avis: instruction

This commit is contained in:
Simon Lehericey 2017-09-06 16:14:03 +02:00
parent a1f9f7aa75
commit 88c27479ee
6 changed files with 102 additions and 1 deletions

View file

@ -2,6 +2,20 @@
@import "common";
@import "constants";
.give-avis {
h1 {
font-size: 18px;
font-weight: bold;
margin-bottom: $default-padding;
}
.avis-notice {
font-size: 12px;
color: $grey;
margin-bottom: 2 * $default-padding;
}
}
.ask-avis {
h1 {
font-size: 18px;

View file

@ -24,10 +24,25 @@ module NewGestionnaire
@dossier = avis.dossier
end
def instruction
@avis = avis
@dossier = avis.dossier
end
def update
avis.update_attributes(avis_params)
flash.notice = 'Votre réponse est enregistrée.'
redirect_to instruction_avis_path(avis)
end
private
def avis
current_gestionnaire.avis.includes(dossier: [:avis]).find(params[:id])
end
def avis_params
params.require(:avis).permit(:answer)
end
end
end

View file

@ -7,3 +7,5 @@
%ul.tabs
%li{ class: current_page?(avis_path(avis)) ? 'active' : nil }
= link_to 'Demande', avis_path(avis)
%li{ class: current_page?(instruction_avis_path(avis)) ? 'active' : nil }
= link_to 'Instruction', instruction_avis_path(avis)

View file

@ -0,0 +1,47 @@
#avis-show
= render partial: 'header', locals: { avis: @avis, dossier: @dossier }
.container
%section.give-avis
%h1 Donner votre avis
%p.avis-notice= "#{@avis.claimant.email}: #{@avis.introduction}"
= form_for @avis, url: avis_path(@avis), html: { class: 'form' } do |f|
= f.text_area :answer, rows: 3, placeholder: 'Votre avis', required: true
.send-wrapper
= f.submit 'Envoyer votre avis', class: 'button send'
%section.ask-avis
%h1 Inviter une personne à donner son avis
%p.avis-notice L'invité pourra consulter, donner un avis sur le dossier et contribuer au fil de messagerie, mais il ne pourra le modifier.
= form_for Avis.new, url: avis_dossier_path(@dossier.procedure, @dossier), html: { class: 'form' } do |f|
= f.email_field :email, placeholder: 'Adresse email', required: true
= f.text_area :introduction, rows: 3, value: 'Bonjour, merci de me donner votre avis sur ce dossier.', required: true
.send-wrapper
= f.submit 'Demander un avis', class: 'button send'
- if @dossier.avis.present?
%section.list-avis
%h1.title
Avis des invités
%span.count= @dossier.avis.count
%ul
- @dossier.avis.each do |avis|
%li.one-avis
%h2.claimant
= (avis.claimant.email == current_gestionnaire.email) ? 'Vous' : avis.claimant.email
%span.date Demande d'avis envoyée le #{I18n.l(avis.created_at.localtime, format: '%d/%m/%y')}
%p= avis.introduction
.answer.flex.align-start
%i.bubble.avis-icon
.width-100
%h2.gestionnaire
= avis.gestionnaire.email
- if avis.answer.present?
%span.date Réponse donnée le #{I18n.l(avis.updated_at.localtime, format: '%d/%m/%y')}
- else
%span.waiting En attente de réponse
%p= avis.answer

View file

@ -258,7 +258,11 @@ Rails.application.routes.draw do
end
end
end
resources :avis, only: [:index, :show]
resources :avis, only: [:index, :show, :update] do
member do
get 'instruction'
end
end
get "recherche" => "recherches#index"
end

View file

@ -34,4 +34,23 @@ describe NewGestionnaire::AvisController, type: :controller do
it { expect(assigns(:avis)).to eq(avis_without_answer) }
it { expect(assigns(:dossier)).to eq(dossier) }
end
describe '#instruction' do
before { get :instruction, { 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
before do
patch :update, { id: avis_without_answer.id, avis: { answer: 'answer' } }
avis_without_answer.reload
end
it { expect(response).to redirect_to(instruction_avis_path(avis_without_answer)) }
it { expect(avis_without_answer.answer).to eq('answer') }
it { expect(flash.notice).to eq('Votre réponse est enregistrée.') }
end
end