Use same counters on procedures index than show
This commit is contained in:
parent
5a0be8918e
commit
5b417889b2
4 changed files with 39 additions and 14 deletions
|
@ -8,11 +8,18 @@ module NewGestionnaire
|
|||
@procedures = current_gestionnaire.procedures
|
||||
|
||||
dossiers = current_gestionnaire.dossiers.state_not_brouillon
|
||||
@dossiers_count_per_procedure = dossiers.group(:procedure_id).count
|
||||
@dossiers_nouveaux_count_per_procedure = dossiers.state_nouveaux.group(:procedure_id).count
|
||||
@dossiers_count_per_procedure = dossiers.all_state.group(:procedure_id).reorder(nil).count
|
||||
@dossiers_a_suivre_count_per_procedure = dossiers.without_followers.en_cours.group(:procedure_id).reorder(nil).count
|
||||
@dossiers_archived_count_per_procedure = dossiers.archived.group(:procedure_id).count
|
||||
@dossiers_termines_count_per_procedure = dossiers.termine.group(:procedure_id).reorder(nil).count
|
||||
|
||||
@followed_dossiers_count_per_procedure = current_gestionnaire.followed_dossiers.where(procedure: @procedures).group(:procedure_id).count
|
||||
@followed_dossiers_count_per_procedure = current_gestionnaire
|
||||
.followed_dossiers
|
||||
.en_cours
|
||||
.where(procedure: @procedures)
|
||||
.group(:procedure_id)
|
||||
.reorder(nil)
|
||||
.count
|
||||
end
|
||||
|
||||
def show
|
||||
|
|
|
@ -13,17 +13,23 @@
|
|||
|
||||
%ul.procedure-stats.flex
|
||||
%li
|
||||
- nouveaux_count = @dossiers_nouveaux_count_per_procedure[p.id] || 0
|
||||
- a_suivre_count = @dossiers_a_suivre_count_per_procedure[p.id] || 0
|
||||
.stats-number
|
||||
= nouveaux_count
|
||||
= a_suivre_count
|
||||
.stats-legend
|
||||
= t('pluralize.new', count: nouveaux_count)
|
||||
à suivre
|
||||
%li
|
||||
- followed_count = @followed_dossiers_count_per_procedure[p.id] || 0
|
||||
.stats-number
|
||||
= followed_count
|
||||
.stats-legend
|
||||
= t('pluralize.followed', count: followed_count)
|
||||
%li
|
||||
- termines_count = @dossiers_termines_count_per_procedure[p.id] || 0
|
||||
.stats-number
|
||||
= termines_count
|
||||
.stats-legend
|
||||
= t('pluralize.processed', count: termines_count)
|
||||
%li
|
||||
- dossier_count = @dossiers_count_per_procedure[p.id] || 0
|
||||
.stats-number
|
||||
|
|
|
@ -85,9 +85,10 @@ describe NewGestionnaire::ProceduresController, type: :controller do
|
|||
before { subject }
|
||||
|
||||
it { expect(assigns(:dossiers_count_per_procedure)[procedure.id]).to eq(nil) }
|
||||
it { expect(assigns(:dossiers_nouveaux_count_per_procedure)[procedure.id]).to eq(nil) }
|
||||
it { expect(assigns(:dossiers_a_suivre_count_per_procedure)[procedure.id]).to eq(nil) }
|
||||
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) }
|
||||
end
|
||||
|
||||
context "with not draft state on multiple procedures" do
|
||||
|
@ -95,25 +96,29 @@ describe NewGestionnaire::ProceduresController, type: :controller do
|
|||
let(:state) { "initiated" }
|
||||
|
||||
before do
|
||||
gestionnaire.procedures << procedure2
|
||||
create(:dossier, procedure: procedure, state: "replied")
|
||||
create(:dossier, procedure: procedure2, state: "updated")
|
||||
create(:dossier, procedure: procedure, state: "received")
|
||||
create(:dossier, procedure: procedure2, state: "closed")
|
||||
create(:dossier, procedure: procedure, state: "without_continuation", archived: true)
|
||||
gestionnaire.followed_dossiers << create(:dossier, procedure: procedure2, state: "refused")
|
||||
|
||||
gestionnaire.procedures << procedure2
|
||||
create(:dossier, :followed, procedure: procedure2, state: "updated")
|
||||
create(:dossier, procedure: procedure2, state: "closed")
|
||||
gestionnaire.followed_dossiers << create(:dossier, procedure: procedure2, state: "received")
|
||||
|
||||
subject
|
||||
end
|
||||
|
||||
it { expect(assigns(:dossiers_count_per_procedure)[procedure.id]).to eq(4) }
|
||||
it { expect(assigns(:dossiers_nouveaux_count_per_procedure)[procedure.id]).to eq(1) }
|
||||
it { expect(assigns(:dossiers_count_per_procedure)[procedure.id]).to eq(3) }
|
||||
it { expect(assigns(:dossiers_a_suivre_count_per_procedure)[procedure.id]).to eq(3) }
|
||||
it { expect(assigns(:followed_dossiers_count_per_procedure)[procedure.id]).to eq(nil) }
|
||||
it { expect(assigns(:dossiers_archived_count_per_procedure)[procedure.id]).to eq(1) }
|
||||
it { expect(assigns(:dossiers_termines_count_per_procedure)[procedure.id]).to eq(nil) }
|
||||
|
||||
it { expect(assigns(:dossiers_count_per_procedure)[procedure2.id]).to eq(3) }
|
||||
it { expect(assigns(:dossiers_nouveaux_count_per_procedure)[procedure2.id]).to eq(nil) }
|
||||
it { expect(assigns(:dossiers_a_suivre_count_per_procedure)[procedure2.id]).to eq(nil) }
|
||||
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) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -65,6 +65,13 @@ FactoryGirl.define do
|
|||
end
|
||||
end
|
||||
|
||||
trait :followed do
|
||||
after(:create) do |dossier, _evaluator|
|
||||
g = create(:gestionnaire)
|
||||
g.followed_dossiers << dossier
|
||||
end
|
||||
end
|
||||
|
||||
trait :replied do
|
||||
state 'replied'
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue