Create and list Avis on Dossier detail page
This commit is contained in:
parent
72494de76f
commit
c3bf15d49f
7 changed files with 102 additions and 1 deletions
21
app/controllers/backoffice/avis_controller.rb
Normal file
21
app/controllers/backoffice/avis_controller.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
class Backoffice::AvisController < ApplicationController
|
||||
|
||||
def create
|
||||
avis = Avis.new(create_params)
|
||||
avis.dossier = dossier
|
||||
avis.save
|
||||
|
||||
redirect_to backoffice_dossier_path(dossier)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def dossier
|
||||
current_gestionnaire.dossiers.find(params[:dossier_id])
|
||||
end
|
||||
|
||||
def create_params
|
||||
params.require(:avis).permit(:email, :introduction)
|
||||
end
|
||||
|
||||
end
|
|
@ -29,6 +29,8 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
|
|||
end
|
||||
|
||||
Notification.where(dossier_id: params[:id].to_i).update_all already_read: true
|
||||
|
||||
@new_avis = Avis.new(introduction: "Bonjour, merci de me donner votre avis sur ce dossier.")
|
||||
end
|
||||
|
||||
def filter
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
class Avis < ApplicationRecord
|
||||
belongs_to :dossier
|
||||
belongs_to :gestionnaire
|
||||
|
||||
def email_to_display
|
||||
gestionnaire.try(:email) || email
|
||||
end
|
||||
end
|
||||
|
|
52
app/views/dossiers/_avis.html.haml
Normal file
52
app/views/dossiers/_avis.html.haml
Normal file
|
@ -0,0 +1,52 @@
|
|||
- if @current_gestionnaire
|
||||
|
||||
.default-data-block.default_visible
|
||||
.row.show-block.infos
|
||||
.header
|
||||
.col-xs-12.title
|
||||
.carret-right
|
||||
.carret-down
|
||||
AVIS EXTERNES
|
||||
.body
|
||||
.display-block-on-print
|
||||
- dossier_facade.dossier.avis.order(updated_at: :desc).each do |avis|
|
||||
- if avis.answer
|
||||
.panel.panel-success
|
||||
.panel-heading
|
||||
%strong= avis.email_to_display
|
||||
a donné son avis le
|
||||
= avis.updated_at.localtime.strftime('%d/%m/%Y à %H:%M')
|
||||
.panel-body
|
||||
%strong Vous :
|
||||
= avis.introduction
|
||||
%hr
|
||||
%strong= "#{avis.email_to_display} :"
|
||||
= avis.answer
|
||||
- else
|
||||
.panel.panel-info
|
||||
.panel-heading
|
||||
Avis demandé à
|
||||
%strong= avis.email_to_display
|
||||
le
|
||||
= avis.created_at.localtime.strftime('%d/%m/%Y à %H:%M')
|
||||
.panel-body
|
||||
%strong Vous :
|
||||
= avis.introduction
|
||||
%hr
|
||||
.center
|
||||
%em Avis en attente
|
||||
.hidden-print
|
||||
.panel.panel-default
|
||||
.panel-heading
|
||||
Demander un avis externe
|
||||
.panel-body
|
||||
.help-block
|
||||
Invitez une personne externe à consulter le dossier et à vous donner un avis sur celui ci.
|
||||
%br
|
||||
Cette personne pourra également contribuer au fil de messagerie, mais ne pourra pas modifier le dossier.
|
||||
= simple_form_for @new_avis, url: backoffice_dossier_avis_index_path(dossier_facade.dossier.object.id) do |f|
|
||||
|
||||
= f.input 'email', label: "Email de la personne qui doit donner un avis"
|
||||
= f.input 'introduction', label: "Message"
|
||||
|
||||
= f.submit "Envoyer la demande d'avis", class: 'btn btn-default'
|
|
@ -51,7 +51,6 @@
|
|||
= render partial: '/users/carte/map', locals: { dossier: @facade.dossier }
|
||||
= render partial: 'users/carte/init_carto', locals: { dossier: @facade.dossier }
|
||||
|
||||
|
||||
- if @current_gestionnaire && gestionnaire_signed_in? && @champs_private.count > 0
|
||||
.default-data-block.default_visible
|
||||
.row.show-block#private-fields
|
||||
|
@ -65,3 +64,5 @@
|
|||
= (private_fields_count == 1) ? "1 champ" : "#{private_fields_count} champs"
|
||||
.body
|
||||
= render partial: '/dossiers/infos_private_fields'
|
||||
|
||||
= render partial: 'dossiers/avis', locals: { dossier_facade: @facade }
|
||||
|
|
|
@ -179,6 +179,7 @@ Rails.application.routes.draw do
|
|||
post 'reopen' => 'dossiers#reopen'
|
||||
put 'follow' => 'dossiers#follow'
|
||||
resources :commentaires, only: [:index]
|
||||
resources :avis, only: [:create]
|
||||
end
|
||||
|
||||
namespace :dossiers do
|
||||
|
|
20
spec/models/avis_spec.rb
Normal file
20
spec/models/avis_spec.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Avis, type: :model do
|
||||
describe '.email_to_display' do
|
||||
let(:invited_email) { 'invited@avis.com' }
|
||||
let!(:avis) { Avis.create(email: invited_email, dossier: create(:dossier)) }
|
||||
|
||||
subject { avis.email_to_display }
|
||||
|
||||
context 'when gestionnaire is not known' do
|
||||
it{ is_expected.to eq(invited_email) }
|
||||
end
|
||||
|
||||
context 'when gestionnaire is known' do
|
||||
let!(:avis) { Avis.create(email: nil, gestionnaire: create(:gestionnaire), dossier: create(:dossier)) }
|
||||
|
||||
it{ is_expected.to eq(avis.gestionnaire.email) }
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue