diff --git a/app/controllers/new_gestionnaire/avis_controller.rb b/app/controllers/new_gestionnaire/avis_controller.rb new file mode 100644 index 000000000..0c003c17a --- /dev/null +++ b/app/controllers/new_gestionnaire/avis_controller.rb @@ -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 diff --git a/app/views/new_gestionnaire/avis/index.html.haml b/app/views/new_gestionnaire/avis/index.html.haml new file mode 100644 index 000000000..ee71f4d09 --- /dev/null +++ b/app/views/new_gestionnaire/avis/index.html.haml @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 83adc5228..54694cee2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -258,6 +258,7 @@ Rails.application.routes.draw do end end end + resources :avis, only: [:index] get "recherche" => "recherches#index" end diff --git a/spec/controllers/new_gestionnaire/avis_controller_spec.rb b/spec/controllers/new_gestionnaire/avis_controller_spec.rb new file mode 100644 index 000000000..13f4e4925 --- /dev/null +++ b/spec/controllers/new_gestionnaire/avis_controller_spec.rb @@ -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