Gestionnaire can list dossiers where he is invited for avis
This commit is contained in:
parent
e831442cbd
commit
43f481b7ff
14 changed files with 141 additions and 3 deletions
|
@ -22,4 +22,5 @@ class Backoffice::Dossiers::ProcedureController < Backoffice::DossiersListContro
|
|||
def retrieve_procedure
|
||||
current_gestionnaire.procedures.find params[:id]
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -4,10 +4,13 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
|
|||
before_action :ensure_gestionnaire_is_authorized, only: :show
|
||||
|
||||
def index
|
||||
return redirect_to backoffice_invitations_path if current_gestionnaire.avis.any?
|
||||
|
||||
procedure = current_gestionnaire.procedure_filter
|
||||
|
||||
if procedure.nil?
|
||||
procedure_list = dossiers_list_facade.gestionnaire_procedures_name_and_id_list
|
||||
|
||||
if procedure_list.count == 0
|
||||
flash.alert = "Vous n'avez aucune procédure d'affectée."
|
||||
return redirect_to root_path
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
class BackofficeController < ApplicationController
|
||||
include SmartListing::Helper::ControllerExtensions
|
||||
helper SmartListing::Helper
|
||||
|
||||
before_action :authenticate_gestionnaire!, only: [:invitations]
|
||||
|
||||
def index
|
||||
if !gestionnaire_signed_in?
|
||||
|
@ -7,4 +11,19 @@ class BackofficeController < ApplicationController
|
|||
redirect_to(:backoffice_dossiers)
|
||||
end
|
||||
end
|
||||
|
||||
def invitations
|
||||
pending_avis = current_gestionnaire.avis.without_answer.includes(dossier: [:procedure]).by_latest
|
||||
@pending_avis = smart_listing_create :pending_avis,
|
||||
pending_avis,
|
||||
partial: 'backoffice/dossiers/list_invitations',
|
||||
array: true
|
||||
|
||||
avis_with_answer = current_gestionnaire.avis.with_answer.includes(dossier: [:procedure]).by_latest
|
||||
@avis_with_answer = smart_listing_create :avis_with_answer,
|
||||
avis_with_answer,
|
||||
partial: 'backoffice/dossiers/list_invitations',
|
||||
array: true
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -2,6 +2,9 @@ class Avis < ApplicationRecord
|
|||
belongs_to :dossier
|
||||
belongs_to :gestionnaire
|
||||
|
||||
scope :with_answer, -> { where.not(answer: nil) }
|
||||
scope :without_answer, -> { where(answer: nil) }
|
||||
|
||||
def email_to_display
|
||||
gestionnaire.try(:email) || email
|
||||
end
|
||||
|
|
|
@ -3,7 +3,6 @@ class Procedure < ActiveRecord::Base
|
|||
has_many :types_de_champ, class_name: 'TypeDeChampPublic', dependent: :destroy
|
||||
has_many :types_de_champ_private, dependent: :destroy
|
||||
has_many :dossiers
|
||||
has_many :notifications, through: :dossiers
|
||||
|
||||
has_one :procedure_path, dependent: :destroy
|
||||
|
||||
|
|
20
app/views/backoffice/dossiers/_list_invitations.html.haml
Normal file
20
app/views/backoffice/dossiers/_list_invitations.html.haml
Normal file
|
@ -0,0 +1,20 @@
|
|||
- if smart_listing.collection.any?
|
||||
%table#dossiers-list.table
|
||||
%thead
|
||||
%th
|
||||
Nº
|
||||
%th
|
||||
Procédure
|
||||
%th
|
||||
Invité le
|
||||
%tbody
|
||||
- smart_listing.collection.each do |avis|
|
||||
%tr.dossier-row{ id: "tr_dossier_#{avis.dossier.id}", 'data-dossier_url' => backoffice_dossier_url(id: avis.dossier.id) }
|
||||
%td= avis.dossier.id
|
||||
%td= avis.dossier.procedure.libelle
|
||||
%td= avis.created_at.strftime('%d/%m/%Y %H:%M')
|
||||
= smart_listing.paginate
|
||||
|
||||
- else
|
||||
.center{ colspan: 2 }
|
||||
%em Aucun dossier
|
22
app/views/backoffice/invitations.html.haml
Normal file
22
app/views/backoffice/invitations.html.haml
Normal file
|
@ -0,0 +1,22 @@
|
|||
.col-md-12
|
||||
.default-data-block.default_visible
|
||||
.row.show-block
|
||||
.header
|
||||
.title
|
||||
.carret-right
|
||||
.carret-down
|
||||
= "#{@pending_avis.count} avis à rendre"
|
||||
.body
|
||||
= smart_listing_render :pending_avis
|
||||
|
||||
%br
|
||||
|
||||
.default-data-block
|
||||
.row.show-block
|
||||
.header
|
||||
.title
|
||||
.carret-right
|
||||
.carret-down
|
||||
= "#{@avis_with_answer.count} avis #{"rendu".pluralize(@avis_with_answer.count)}"
|
||||
.body
|
||||
= smart_listing_render :avis_with_answer
|
4
app/views/backoffice/invitations.js.erb
Normal file
4
app/views/backoffice/invitations.js.erb
Normal file
|
@ -0,0 +1,4 @@
|
|||
<%= smart_listing_update :pending_avis %>
|
||||
<%= smart_listing_update :avis_with_answer %>
|
||||
|
||||
link_init();
|
|
@ -20,6 +20,10 @@
|
|||
#infos-block
|
||||
.split-hr-left
|
||||
#procedure-list
|
||||
- if current_gestionnaire.avis.any?
|
||||
= link_to backoffice_invitations_path do
|
||||
.procedure-list-element{ class: ('active' if request.path == backoffice_invitations_path) }
|
||||
Invitations
|
||||
- current_gestionnaire.procedures.by_libelle.each do |procedure|
|
||||
= link_to backoffice_dossiers_procedure_path(procedure.id), { title: procedure.libelle } do
|
||||
.procedure-list-element{ class: ('active' if procedure.id.to_s == params[:id]) }
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
= render partial: 'layouts/left_panels/left_panel_backoffice_dossierscontroller_index'
|
|
@ -0,0 +1,2 @@
|
|||
.col-xs-10.main-info
|
||||
INVITATIONS
|
|
@ -167,6 +167,8 @@ Rails.application.routes.draw do
|
|||
|
||||
resource :private_formulaire
|
||||
|
||||
get 'invitations'
|
||||
|
||||
resources :dossiers do
|
||||
post 'receive' => 'dossiers#receive'
|
||||
post 'refuse' => 'dossiers#refuse'
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
|
||||
describe BackofficeController, type: :controller do
|
||||
describe 'GET #index' do
|
||||
context 'when gestionnaire is not connected'do
|
||||
context 'when gestionnaire is not connected' do
|
||||
before do
|
||||
get :index
|
||||
end
|
||||
|
@ -10,7 +10,7 @@ describe BackofficeController, type: :controller do
|
|||
it { expect(response).to redirect_to :new_gestionnaire_session }
|
||||
end
|
||||
|
||||
context 'when gestionnaire is connected'do
|
||||
context 'when gestionnaire is connected' do
|
||||
before do
|
||||
sign_in create(:gestionnaire)
|
||||
get :index
|
||||
|
@ -19,4 +19,45 @@ describe BackofficeController, type: :controller do
|
|||
it { expect(response).to redirect_to :backoffice_dossiers }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #invitations' do
|
||||
context 'when gestionnaire is not invited on any dossiers' do
|
||||
render_views
|
||||
|
||||
before do
|
||||
sign_in create(:gestionnaire)
|
||||
get :invitations
|
||||
end
|
||||
|
||||
it { expect(response.status).to eq(200) }
|
||||
it { expect(response.body).to include("INVITATIONS") }
|
||||
it { expect(response.body).to include("0 avis à rendre") }
|
||||
it { expect(response.body).to include("0 avis rendus") }
|
||||
end
|
||||
|
||||
context 'when gestionnaire is invited on a dossier' do
|
||||
let(:dossier){ create(:dossier) }
|
||||
let(:gestionnaire){ create(:gestionnaire) }
|
||||
let!(:avis){ create(:avis, dossier: dossier, gestionnaire: gestionnaire) }
|
||||
render_views
|
||||
|
||||
before do
|
||||
sign_in gestionnaire
|
||||
get :invitations
|
||||
end
|
||||
|
||||
it { expect(response.status).to eq(200) }
|
||||
it { expect(response.body).to include("1 avis à rendre") }
|
||||
it { expect(response.body).to include("0 avis rendus") }
|
||||
it { expect(response.body).to include(dossier.procedure.libelle) }
|
||||
|
||||
context 'when avis is already sent' do
|
||||
let!(:avis){ create(:avis, dossier: dossier, gestionnaire: gestionnaire, answer: "Voici mon avis.") }
|
||||
|
||||
it { expect(response.body).to include("0 avis à rendre") }
|
||||
it { expect(response.body).to include("1 avis rendu") }
|
||||
it { expect(response.body).to include(dossier.procedure.libelle) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
17
spec/factories/avis.rb
Normal file
17
spec/factories/avis.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
FactoryGirl.define do
|
||||
factory :avis do
|
||||
introduction 'Bonjour, merci de me donner votre avis sur ce dossier'
|
||||
|
||||
before(:create) do |avis, _evaluator|
|
||||
unless avis.gestionnaire
|
||||
avis.gestionnaire = create :gestionnaire
|
||||
end
|
||||
end
|
||||
|
||||
before(:create) do |avis, _evaluator|
|
||||
unless avis.dossier
|
||||
avis.dossier = create :dossier
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue