Avis: index

This commit is contained in:
Simon Lehericey 2017-09-06 11:21:29 +02:00
parent 8c97224fde
commit 3cc09c98f9
4 changed files with 87 additions and 0 deletions

View file

@ -0,0 +1,22 @@
module NewGestionnaire
class AvisController < ApplicationController
layout 'new_application'
A_DONNER_STATUS = 'a-donner'
DONNES_STATUS = 'donnes'
def index
gestionnaire_avis = current_gestionnaire.avis.includes(dossier: [:procedure, :user])
@avis_a_donner, @avis_donnes = gestionnaire_avis.partition { |avis| avis.answer.nil? }
@statut = params[:statut].present? ? params[:statut] : A_DONNER_STATUS
@avis = case @statut
when A_DONNER_STATUS
@avis_a_donner
when DONNES_STATUS
@avis_donnes
end
end
end
end

View file

@ -0,0 +1,35 @@
#avis-index
.backoffice-header
.container.flex
.width-100
%h1 Avis
%ul.tabs
%li{ class: (@statut == NewGestionnaire::AvisController::A_DONNER_STATUS) ? 'active' : nil }>
= link_to(avis_index_path(statut: NewGestionnaire::AvisController::A_DONNER_STATUS)) do
avis à donner
%span.badge= @avis_a_donner.count
%li{ class: (@statut == NewGestionnaire::AvisController::DONNES_STATUS) ? 'active' : nil }>
= link_to(avis_index_path(statut: NewGestionnaire::AvisController::DONNES_STATUS)) do
avis #{'donné'.pluralize(@avis_donnes.count)}
%span.badge= @avis_donnes.count
.container
- if @avis.present?
%table.table.dossiers-table.hoverable
%thead
%tr
%th.number-col Nº dossier
%th Demandeur
%th Procédure
%tbody
- @avis.each do |avis|
%tr
%td.number-col
= link_to(avis_path(avis), class: 'cell-link') do
%i.folder
#{avis.dossier.id}
%td= link_to(avis.dossier.user.email, avis_path(avis), class: 'cell-link')
%td= link_to(avis.dossier.procedure.libelle, avis_path(avis), class: 'cell-link')
- else
%h2 Aucun avis

View file

@ -258,6 +258,7 @@ Rails.application.routes.draw do
end
end
end
resources :avis, only: [:index]
get "recherche" => "recherches#index"
end

View file

@ -0,0 +1,29 @@
require 'spec_helper'
describe NewGestionnaire::AvisController, type: :controller do
render_views
let(:claimant) { create(:gestionnaire) }
let(:gestionnaire) { create(:gestionnaire) }
let(:procedure) { create(:procedure, :published, gestionnaires: [gestionnaire]) }
let(:dossier) { create(:dossier, :replied, procedure: procedure) }
let!(:avis_without_answer) { Avis.create(dossier: dossier, claimant: claimant, gestionnaire: gestionnaire) }
let!(:avis_with_answer) { Avis.create(dossier: dossier, claimant: claimant, gestionnaire: gestionnaire, answer: 'yop') }
before { sign_in(gestionnaire) }
describe '#index' do
before { get :index }
it { expect(response).to have_http_status(:success) }
it { expect(assigns(:avis_a_donner)).to match([avis_without_answer]) }
it { expect(assigns(:avis_donnes)).to match([avis_with_answer]) }
it { expect(assigns(:statut)).to eq('a-donner') }
context 'with a statut equal to donnes' do
before { get :index, statut: 'donnes' }
it { expect(assigns(:statut)).to eq('donnes') }
end
end
end