diff --git a/app/assets/stylesheets/new_design/badges.scss b/app/assets/stylesheets/new_design/badges.scss index 6151b9d47..b107e7f49 100644 --- a/app/assets/stylesheets/new_design/badges.scss +++ b/app/assets/stylesheets/new_design/badges.scss @@ -15,4 +15,10 @@ background-color: $orange; color: #FFFFFF; } + + &.procedure-synthese-badge { + color: $white; + background-color: #6C757D; + margin-right: 3px; + } } diff --git a/app/controllers/instructeurs/procedures_controller.rb b/app/controllers/instructeurs/procedures_controller.rb index 68e01c1b0..d53539048 100644 --- a/app/controllers/instructeurs/procedures_controller.rb +++ b/app/controllers/instructeurs/procedures_controller.rb @@ -29,6 +29,18 @@ module Instructeurs .group('groupe_instructeurs.procedure_id') .reorder(nil) .count + + @all_dossiers_counts = {} + @all_dossiers_counts['à suivre'] = dossiers.without_followers.en_cours.count + @all_dossiers_counts['suivis'] = current_instructeur + .followed_dossiers + .joins(:groupe_instructeur) + .en_cours + .where(groupe_instructeur_id: groupe_ids) + .count + @all_dossiers_counts['traités'] = dossiers.termine.count + @all_dossiers_counts['dossiers'] = dossiers.all_state.count + @all_dossiers_counts['archivés'] = dossiers.archived.count end def show diff --git a/app/views/instructeurs/procedures/_synthese.html.haml b/app/views/instructeurs/procedures/_synthese.html.haml new file mode 100644 index 000000000..5724eba3c --- /dev/null +++ b/app/views/instructeurs/procedures/_synthese.html.haml @@ -0,0 +1,6 @@ +- if procedures.length > 1 + .tab-title + %span + Synthèse des dossiers + - all_dossiers_counts.each_with_index do |(label, dossier_count)| + %span.badge.procedure-synthese-badge= number_with_html_delimiter(dossier_count) + ' ' + label diff --git a/app/views/instructeurs/procedures/index.html.haml b/app/views/instructeurs/procedures/index.html.haml index 93efd2ba2..d2275f38b 100644 --- a/app/views/instructeurs/procedures/index.html.haml +++ b/app/views/instructeurs/procedures/index.html.haml @@ -2,6 +2,7 @@ .container %h1.page-title Démarches + = render partial: 'instructeurs/procedures/synthese', locals: { procedures: @procedures, all_dossiers_counts: @all_dossiers_counts } = render partial: 'instructeurs/procedures/list', locals: { procedures: @procedures, dossiers_count_per_procedure: @dossiers_count_per_procedure, diff --git a/spec/controllers/instructeurs/procedures_controller_spec.rb b/spec/controllers/instructeurs/procedures_controller_spec.rb index f48b9df44..d32d7dffa 100644 --- a/spec/controllers/instructeurs/procedures_controller_spec.rb +++ b/spec/controllers/instructeurs/procedures_controller_spec.rb @@ -134,6 +134,12 @@ describe Instructeurs::ProceduresController, type: :controller do it { expect(assigns(:dossiers_archived_count_per_procedure)[procedure.id]).to eq(nil) } it { expect(assigns(:followed_dossiers_count_per_procedure)[procedure.id]).to eq(nil) } it { expect(assigns(:dossiers_termines_count_per_procedure)[procedure.id]).to eq(nil) } + + it { expect(assigns(:all_dossiers_counts)['à suivre']).to eq(0) } + it { expect(assigns(:all_dossiers_counts)['suivis']).to eq(0) } + it { expect(assigns(:all_dossiers_counts)['traités']).to eq(0) } + it { expect(assigns(:all_dossiers_counts)['dossiers']).to eq(0) } + it { expect(assigns(:all_dossiers_counts)['archivés']).to eq(0) } end context "with not draft state on multiple procedures" do @@ -164,6 +170,12 @@ describe Instructeurs::ProceduresController, type: :controller do it { expect(assigns(:followed_dossiers_count_per_procedure)[procedure2.id]).to eq(1) } it { expect(assigns(:dossiers_archived_count_per_procedure)[procedure2.id]).to eq(nil) } it { expect(assigns(:dossiers_termines_count_per_procedure)[procedure2.id]).to eq(1) } + + it { expect(assigns(:all_dossiers_counts)['à suivre']).to eq(3 + 0) } + it { expect(assigns(:all_dossiers_counts)['suivis']).to eq(0 + 1) } + it { expect(assigns(:all_dossiers_counts)['traités']).to eq(0 + 1) } + it { expect(assigns(:all_dossiers_counts)['dossiers']).to eq(3 + 3) } + it { expect(assigns(:all_dossiers_counts)['archivés']).to eq(1 + 0) } end end @@ -198,6 +210,12 @@ describe Instructeurs::ProceduresController, type: :controller do it { expect(assigns(:dossiers_termines_count_per_procedure)[procedure.id]).to eq(10) } it { expect(assigns(:dossiers_count_per_procedure)[procedure.id]).to eq(4 + 6 + 10) } it { expect(assigns(:dossiers_archived_count_per_procedure)[procedure.id]).to eq(14) } + + it { expect(assigns(:all_dossiers_counts)['à suivre']).to eq(4) } + it { expect(assigns(:all_dossiers_counts)['suivis']).to eq(6) } + it { expect(assigns(:all_dossiers_counts)['traités']).to eq(10) } + it { expect(assigns(:all_dossiers_counts)['dossiers']).to eq(4 + 6 + 10) } + it { expect(assigns(:all_dossiers_counts)['archivés']).to eq(14) } end context 'when an instructeur only belongs to one of them gi' do @@ -213,6 +231,12 @@ describe Instructeurs::ProceduresController, type: :controller do it { expect(assigns(:dossiers_termines_count_per_procedure)[procedure.id]).to eq(5) } it { expect(assigns(:dossiers_count_per_procedure)[procedure.id]).to eq(2 + 3 + 5) } it { expect(assigns(:dossiers_archived_count_per_procedure)[procedure.id]).to eq(7) } + + it { expect(assigns(:all_dossiers_counts)['à suivre']).to eq(2) } + it { expect(assigns(:all_dossiers_counts)['suivis']).to eq(3) } + it { expect(assigns(:all_dossiers_counts)['traités']).to eq(5) } + it { expect(assigns(:all_dossiers_counts)['dossiers']).to eq(2 + 3 + 5) } + it { expect(assigns(:all_dossiers_counts)['archivés']).to eq(7) } end end end diff --git a/spec/views/instructeur/procedures/_synthese.html.haml_spec.rb b/spec/views/instructeur/procedures/_synthese.html.haml_spec.rb new file mode 100644 index 000000000..a5b743857 --- /dev/null +++ b/spec/views/instructeur/procedures/_synthese.html.haml_spec.rb @@ -0,0 +1,47 @@ +describe 'instructeurs/procedures/_synthese.html.haml', type: :view do + let(:current_instructeur) { create(:instructeur) } + let(:procedure) { create(:procedure) } + let!(:dossier) { create(:dossier, procedure: procedure) } + + context 'when instructeur has 2 procedures and 1 file, table is shown' do + let(:procedure2) { create(:procedure) } + + subject { + render 'instructeurs/procedures/synthese.html.haml', + all_dossiers_counts: { + 'à suivre': 0, + 'suivis': 0, + 'traités': 1, + 'dossiers': 1, + 'archivés': 0 + }, + procedures: [procedure, procedure2] + } + + it { is_expected.to have_text('Synthèse des dossiers') } + it { is_expected.to have_text('suivis') } + it { is_expected.to have_text('traités') } + it { is_expected.to have_text('dossiers') } + it { is_expected.to have_text('archivés') } + end + + context 'when instructeur has 1 procedure and 1 file, table is not shown' do + subject { + render 'instructeurs/procedures/synthese.html.haml', + all_dossiers_counts: { + 'à suivre': 0, + 'suivis': 0, + 'traités': 1, + 'dossiers': 1, + 'archivés': 0 + }, + procedures: [procedure] + } + + it { is_expected.not_to have_text('Synthèse des dossiers') } + it { is_expected.not_to have_text('suivis') } + it { is_expected.not_to have_text('traités') } + it { is_expected.not_to have_text('dossiers') } + it { is_expected.not_to have_text('archivés') } + end +end