diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb index f3d98b610..a286704b9 100644 --- a/app/controllers/backoffice/dossiers_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -5,6 +5,21 @@ class Backoffice::DossiersController < ApplicationController initialize_instance_params params[:id] end + def a_traiter + @dossiers_a_traiter = Dossier.a_traiter(current_gestionnaire).decorate + total_dossiers_per_state + end + + def en_attente + @dossiers_en_attente = Dossier.en_attente(current_gestionnaire).decorate + total_dossiers_per_state + end + + def termine + @dossiers_termine = Dossier.termine(current_gestionnaire).decorate + total_dossiers_per_state + end + def valid initialize_instance_params params[:dossier_id] @@ -25,6 +40,12 @@ class Backoffice::DossiersController < ApplicationController private + def total_dossiers_per_state + @dossiers_a_traiter_total = !@dossiers_a_traiter.nil? ? @dossiers_a_traiter.size : Dossier.a_traiter(current_gestionnaire).size + @dossiers_en_attente_total = !@dossiers_en_attente.nil? ? @dossiers_en_attente.size : Dossier.en_attente(current_gestionnaire).size + @dossiers_termine_total = !@dossiers_termine.nil? ? @dossiers_termine.size : Dossier.termine(current_gestionnaire).size + end + def initialize_instance_params dossier_id @dossier = Dossier.find(dossier_id) @entreprise = @dossier.entreprise.decorate diff --git a/app/controllers/backoffice_controller.rb b/app/controllers/backoffice_controller.rb index 5096033d4..3a4702095 100644 --- a/app/controllers/backoffice_controller.rb +++ b/app/controllers/backoffice_controller.rb @@ -4,9 +4,7 @@ class BackofficeController < ApplicationController if !gestionnaire_signed_in? redirect_to(controller: '/gestionnaires/sessions', action: :new) else - @dossiers_a_traiter = Dossier.a_traiter(current_gestionnaire).decorate - @dossiers_en_attente = Dossier.en_attente(current_gestionnaire).decorate - @dossiers_termine = Dossier.termine(current_gestionnaire).decorate + redirect_to(:backoffice_dossiers_a_traiter) end end end \ No newline at end of file diff --git a/app/views/backoffice/dossiers/_onglets.html.haml b/app/views/backoffice/dossiers/_onglets.html.haml new file mode 100644 index 000000000..c31d8190e --- /dev/null +++ b/app/views/backoffice/dossiers/_onglets.html.haml @@ -0,0 +1,18 @@ +%h1 Gestion des dossiers +%br + +%ul.nav.nav-tabs + %li{class: "#{'active' unless @dossiers_a_traiter.nil? }"} + %a{:href => "#{url_for :backoffice_dossiers_a_traiter}"} + %strong.text-danger + = "À traiter (#{@dossiers_a_traiter_total})" + %li{class: "#{'active' unless @dossiers_en_attente.nil? }"} + %a{:href => "#{url_for :backoffice_dossiers_en_attente}"} + %strong.text-info + ="En attente (#{@dossiers_en_attente_total})" + %li{class: "#{'active' unless @dossiers_termine.nil? }"} + %a{:href => "#{url_for :backoffice_dossiers_termine}"} + %strong.text-success + = "Terminé (#{@dossiers_termine_total})" + +%br \ No newline at end of file diff --git a/app/views/backoffice/dossiers/a_traiter.html.haml b/app/views/backoffice/dossiers/a_traiter.html.haml new file mode 100644 index 000000000..3b65f1b90 --- /dev/null +++ b/app/views/backoffice/dossiers/a_traiter.html.haml @@ -0,0 +1,17 @@ +#backoffice_a_traiter + = render partial: 'onglets' + + -#%h3.text-danger À traiter + %table.table + %thead.row + %th.col-md-4.col-lg-4 Procédure + %th.col-md-4.col-lg-4 Dossier + %th.col-md-2.col-lg-2 État + %th.col-md-2.col-lg-2 Date de mise à jour + - @dossiers_a_traiter.each do |dossier| + %tr + %td= dossier.procedure.libelle + %td + = link_to(dossier.nom_projet, "/backoffice/dossiers/#{dossier.id}") + %td= dossier.state_fr + %td= dossier.last_update diff --git a/app/views/backoffice/dossiers/en_attente.html.haml b/app/views/backoffice/dossiers/en_attente.html.haml new file mode 100644 index 000000000..bedebc034 --- /dev/null +++ b/app/views/backoffice/dossiers/en_attente.html.haml @@ -0,0 +1,17 @@ +#backoffice_en_attente + = render partial: 'onglets' + + -#%h3.text-info En attente + %table.table + %thead + %th.col-md-4.col-lg-4 Procédure + %th.col-md-4.col-lg-4 Dossier + %th.col-md-2.col-lg-2 État + %th.col-md-2.col-lg-2 Date de mise à jour + - @dossiers_en_attente.each do |dossier| + %tr + %td= dossier.procedure.libelle + %td + = link_to(dossier.nom_projet, "/backoffice/dossiers/#{dossier.id}") + %td= dossier.state_fr + %td= dossier.last_update diff --git a/app/views/backoffice/dossiers/termine.html.haml b/app/views/backoffice/dossiers/termine.html.haml new file mode 100644 index 000000000..6e8609da5 --- /dev/null +++ b/app/views/backoffice/dossiers/termine.html.haml @@ -0,0 +1,17 @@ +#backoffice_termine + = render partial: 'onglets' + + -#%h3.text-success Terminé + %table.table + %thead + %th.col-md-4.col-lg-4 Procédure + %th.col-md-4.col-lg-4 Dossier + %th.col-md-2.col-lg-2 État + %th.col-md-2.col-lg-2 Date de mise à jour + - @dossiers_termine.each do |dossier| + %tr + %td= dossier.procedure.libelle + %td + = link_to(dossier.nom_projet, "/backoffice/dossiers/#{dossier.id}") + %td= dossier.state_fr + %td= dossier.last_update diff --git a/app/views/backoffice/index.html.haml b/app/views/backoffice/index.html.haml deleted file mode 100644 index e4b6b343e..000000000 --- a/app/views/backoffice/index.html.haml +++ /dev/null @@ -1,49 +0,0 @@ -#backoffice - %h1 Gestion des dossiers - %br - %h3.text-danger À traiter - %table.table - %thead.row - %th.col-md-4.col-lg-4 Procédure - %th.col-md-4.col-lg-4 Dossier - %th.col-md-2.col-lg-2 État - %th.col-md-2.col-lg-2 Date de mise à jour - - @dossiers_a_traiter.each do |dossier| - %tr - %td= dossier.procedure.libelle - %td - = link_to(dossier.nom_projet, "/backoffice/dossiers/#{dossier.id}") - %td= dossier.state_fr - %td= dossier.last_update - - %br - %h3.text-info En attente - %table.table - %thead - %th.col-md-4.col-lg-4 Procédure - %th.col-md-4.col-lg-4 Dossier - %th.col-md-2.col-lg-2 État - %th.col-md-2.col-lg-2 Date de mise à jour - - @dossiers_en_attente.each do |dossier| - %tr - %td= dossier.procedure.libelle - %td - = link_to(dossier.nom_projet, "/backoffice/dossiers/#{dossier.id}") - %td= dossier.state_fr - %td= dossier.last_update - - %br - %h3.text-success Terminé - %table.table - %thead - %th.col-md-4.col-lg-4 Procédure - %th.col-md-4.col-lg-4 Dossier - %th.col-md-2.col-lg-2 État - %th.col-md-2.col-lg-2 Date de mise à jour - - @dossiers_termine.each do |dossier| - %tr - %td= dossier.procedure.libelle - %td - = link_to(dossier.nom_projet, "/backoffice/dossiers/#{dossier.id}") - %td= dossier.state_fr - %td= dossier.last_update diff --git a/config/routes.rb b/config/routes.rb index 3606b8baf..90272b2f1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,7 +11,7 @@ Rails.application.routes.draw do devise_for :users, controllers: { sessions: 'users/sessions' } - + root 'root#index' get 'france_connect' => 'france_connect#login' @@ -51,6 +51,10 @@ Rails.application.routes.draw do namespace :backoffice do get 'sign_in' => '/gestionnaires/sessions#new' + get 'dossiers/a_traiter' => 'dossiers#a_traiter' + get 'dossiers/en_attente' => 'dossiers#en_attente' + get 'dossiers/termine' => 'dossiers#termine' + resources :dossiers do post 'valid' => 'dossiers#valid' post 'close' => 'dossiers#close' diff --git a/spec/controllers/backoffice/dossiers_controller_spec.rb b/spec/controllers/backoffice/dossiers_controller_spec.rb index 13a11da66..3639a4a4d 100644 --- a/spec/controllers/backoffice/dossiers_controller_spec.rb +++ b/spec/controllers/backoffice/dossiers_controller_spec.rb @@ -4,7 +4,7 @@ describe Backoffice::DossiersController, type: :controller do let(:dossier) { create(:dossier, :with_entreprise, :with_user) } let(:dossier_id) { dossier.id } let(:bad_dossier_id) { Dossier.count + 10 } - let(:gestionnaire) { create(:gestionnaire) } + let(:gestionnaire) { create(:gestionnaire, administrateur: create(:administrateur)) } describe 'GET #show' do context 'gestionnaire is connected' do @@ -29,6 +29,45 @@ describe Backoffice::DossiersController, type: :controller do end end + describe 'GET #a_traiter' do + context 'when gestionnaire is connected' do + before do + sign_in gestionnaire + end + + it 'returns http success' do + get :a_traiter + expect(response).to have_http_status(200) + end + end + end + + describe 'GET #en_attente' do + context 'when gestionnaire is connected' do + before do + sign_in gestionnaire + end + + it 'returns http success' do + get :en_attente + expect(response).to have_http_status(200) + end + end + end + + describe 'GET #termine' do + context 'when gestionnaire is connected' do + before do + sign_in gestionnaire + end + + it 'returns http success' do + get :termine + expect(response).to have_http_status(200) + end + end + end + describe 'POST #valid' do before do dossier.initiated! diff --git a/spec/controllers/backoffice_controller_spec.rb b/spec/controllers/backoffice_controller_spec.rb new file mode 100644 index 000000000..5f621a035 --- /dev/null +++ b/spec/controllers/backoffice_controller_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' + +describe BackofficeController, type: :controller do + describe 'GET #index' do + context 'when gestionnaire is not connected'do + before do + get :index + end + + it { expect(response).to redirect_to :new_gestionnaire_session } + end + + context 'when gestionnaire is connected'do + before do + sign_in create(:gestionnaire) + get :index + end + + it { expect(response).to redirect_to :backoffice_dossiers_a_traiter } + end + end +end \ No newline at end of file diff --git a/spec/features/backoffice/onglets_link_spec.rb b/spec/features/backoffice/onglets_link_spec.rb new file mode 100644 index 000000000..ab6e7e70c --- /dev/null +++ b/spec/features/backoffice/onglets_link_spec.rb @@ -0,0 +1,45 @@ +require 'spec_helper' + +feature 'on click on tabs button' do + let(:administrateur) { create(:administrateur) } + let(:gestionnaire) { create(:gestionnaire, administrateur: administrateur) } + + before do + login_as gestionnaire, scope: :gestionnaire + end + + context 'when gestionnaire is logged in' do + context 'when he click on tabs a traitee' do + before do + visit backoffice_dossiers_en_attente_url + page.click_on 'À traiter (0)' + end + + scenario 'it redirect to backoffice dossier termine' do + expect(page).to have_css('#backoffice_a_traiter') + end + end + + context 'when he click on tabs en attente' do + before do + visit backoffice_dossiers_termine_url + page.click_on 'En attente (0)' + end + + scenario 'it redirect to backoffice dossier en attente' do + expect(page).to have_css('#backoffice_en_attente') + end + end + + context 'when he click on tabs termine' do + before do + visit backoffice_dossiers_a_traiter_url + page.click_on 'Terminé (0)' + end + + scenario 'it redirect to backoffice dossier termine' do + expect(page).to have_css('#backoffice_termine') + end + end + end +end \ No newline at end of file diff --git a/spec/views/backoffice/dossiers/a_traiter_html.haml_spec.rb b/spec/views/backoffice/dossiers/a_traiter_html.haml_spec.rb new file mode 100644 index 000000000..7ad155b24 --- /dev/null +++ b/spec/views/backoffice/dossiers/a_traiter_html.haml_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe 'backoffice/dossiers/a_traiter.html.haml', type: :view do + let(:administrateur) { create(:administrateur) } + let(:gestionnaire) { create(:gestionnaire, administrateur: administrateur) } + + let!(:procedure) { create(:procedure, administrateur: administrateur) } + let!(:decorate_dossier) { create(:dossier, :with_user, state: 'initiated', procedure: procedure).decorate } + + before do + assign(:dossiers_a_traiter, Dossier.a_traiter(gestionnaire).decorate) + render + end + + subject { rendered } + it { is_expected.to have_css('#backoffice_a_traiter') } + it { is_expected.to have_content(procedure.libelle) } + it { is_expected.to have_content(decorate_dossier.nom_projet) } + it { is_expected.to have_content(decorate_dossier.state_fr) } + it { is_expected.to have_content(decorate_dossier.last_update) } +end \ No newline at end of file diff --git a/spec/views/backoffice/index.html.haml_spec.rb b/spec/views/backoffice/dossiers/en_attente_html.haml_spec.rb similarity index 68% rename from spec/views/backoffice/index.html.haml_spec.rb rename to spec/views/backoffice/dossiers/en_attente_html.haml_spec.rb index 01512ee4a..0e1529fe8 100644 --- a/spec/views/backoffice/index.html.haml_spec.rb +++ b/spec/views/backoffice/dossiers/en_attente_html.haml_spec.rb @@ -1,23 +1,19 @@ require 'spec_helper' -describe 'backoffice/index.html.haml', type: :view do +describe 'backoffice/dossiers/en_attente.html.haml', type: :view do let(:administrateur) { create(:administrateur) } let(:gestionnaire) { create(:gestionnaire, administrateur: administrateur) } let!(:procedure) { create(:procedure, administrateur: administrateur) } - let!(:decorate_dossier) { create(:dossier, :with_user, procedure: procedure).decorate } + let!(:decorate_dossier) { create(:dossier, :with_user, procedure: procedure, state: 'replied').decorate } before do - assign(:dossiers_a_traiter, Dossier.a_traiter(gestionnaire).decorate) assign(:dossiers_en_attente, Dossier.en_attente(gestionnaire).decorate) - assign(:dossiers_termine, Dossier.termine(gestionnaire).decorate) - - decorate_dossier.initiated! render end subject { rendered } - it { is_expected.to have_css('#backoffice') } + it { is_expected.to have_css('#backoffice_en_attente') } it { is_expected.to have_content(procedure.libelle) } it { is_expected.to have_content(decorate_dossier.nom_projet) } it { is_expected.to have_content(decorate_dossier.state_fr) } diff --git a/spec/views/backoffice/dossiers/termine_html.haml_spec.rb b/spec/views/backoffice/dossiers/termine_html.haml_spec.rb new file mode 100644 index 000000000..60e35151c --- /dev/null +++ b/spec/views/backoffice/dossiers/termine_html.haml_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe 'backoffice/dossiers/termine.html.haml', type: :view do + let(:administrateur) { create(:administrateur) } + let(:gestionnaire) { create(:gestionnaire, administrateur: administrateur) } + + let!(:procedure) { create(:procedure, administrateur: administrateur) } + let!(:decorate_dossier) { create(:dossier, :with_user, procedure: procedure, state: 'closed').decorate } + + before do + assign(:dossiers_termine, Dossier.termine(gestionnaire).decorate) + render + end + + subject { rendered } + it { is_expected.to have_css('#backoffice_termine') } + it { is_expected.to have_content(procedure.libelle) } + it { is_expected.to have_content(decorate_dossier.nom_projet) } + it { is_expected.to have_content(decorate_dossier.state_fr) } + it { is_expected.to have_content(decorate_dossier.last_update) } +end \ No newline at end of file