add bulk action 'follow'
This commit is contained in:
parent
177dec2bdb
commit
25a7fa5a34
10 changed files with 126 additions and 5 deletions
|
@ -26,6 +26,15 @@ en:
|
|||
text_success:
|
||||
one: 1/1 is being accepted
|
||||
other: "%{progress_count}/%{count} files have been accepted"
|
||||
follow:
|
||||
finish:
|
||||
text_success:
|
||||
one: 1/1 file has been followed
|
||||
other: "%{success_count}/%{count} files have been followed"
|
||||
in_progress:
|
||||
text_success:
|
||||
one: 1/1 is being followed
|
||||
other: "%{progress_count}/%{count} files have been followed"
|
||||
title:
|
||||
finish: The bulk action is finished
|
||||
in_progress: A bulk action is processing
|
||||
|
|
|
@ -26,6 +26,15 @@ fr:
|
|||
text_success:
|
||||
one: 1 dossier sera accepté
|
||||
other: "%{progress_count}/%{count} dossiers ont été acceptés"
|
||||
follow:
|
||||
finish:
|
||||
text_success:
|
||||
one: 1 dossier a été suivi
|
||||
other: "%{success_count}/%{count} dossiers ont été suivis"
|
||||
in_progress:
|
||||
text_success:
|
||||
one: 1 dossier sera suivi
|
||||
other: "%{progress_count}/%{count} dossiers ont été suivis"
|
||||
title:
|
||||
finish: L'action de masse est terminée
|
||||
in_progress: Une action de masse est en cours
|
||||
|
|
|
@ -7,11 +7,21 @@ class Dossiers::BatchOperationComponent < ApplicationComponent
|
|||
end
|
||||
|
||||
def render?
|
||||
['traites', 'suivis'].include?(@statut)
|
||||
['a-suivre', 'traites', 'suivis'].include?(@statut)
|
||||
end
|
||||
|
||||
def available_operations
|
||||
case @statut
|
||||
when 'a-suivre' then
|
||||
{
|
||||
options:
|
||||
[
|
||||
{
|
||||
label: t(".operations.follow"),
|
||||
operation: BatchOperation.operations.fetch(:follow)
|
||||
}
|
||||
]
|
||||
}
|
||||
when 'traites' then
|
||||
{
|
||||
options:
|
||||
|
@ -47,9 +57,10 @@ class Dossiers::BatchOperationComponent < ApplicationComponent
|
|||
|
||||
def icons
|
||||
{
|
||||
accepter: 'fr-icon-success-line',
|
||||
archiver: 'fr-icon-folder-2-line',
|
||||
passer_en_instruction: 'fr-icon-edit-line',
|
||||
accepter: 'fr-icon-success-line'
|
||||
follow: 'fr-icon-star-line',
|
||||
passer_en_instruction: 'fr-icon-edit-line'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,3 +3,4 @@ fr:
|
|||
archiver: 'Archive selected files'
|
||||
passer_en_instruction: 'Change selected files to instructing'
|
||||
accepter: 'Accept seleted files'
|
||||
follow: 'Follow seleted files'
|
||||
|
|
|
@ -3,3 +3,4 @@ fr:
|
|||
archiver: 'Archiver les dossiers sélectionnés'
|
||||
passer_en_instruction: 'Passer en instruction les dossiers sélectionnés'
|
||||
accepter: 'Accepter les dossiers sélectionnés'
|
||||
follow: 'Suivre les dossiers sélectionnés'
|
||||
|
|
|
@ -17,9 +17,10 @@
|
|||
|
||||
class BatchOperation < ApplicationRecord
|
||||
enum operation: {
|
||||
accepter: 'accepter',
|
||||
archiver: 'archiver',
|
||||
passer_en_instruction: 'passer_en_instruction',
|
||||
accepter: 'accepter'
|
||||
follow: 'follow',
|
||||
passer_en_instruction: 'passer_en_instruction'
|
||||
}
|
||||
|
||||
has_many :dossiers, dependent: :nullify
|
||||
|
@ -58,6 +59,8 @@ class BatchOperation < ApplicationRecord
|
|||
query.state_en_construction
|
||||
when BatchOperation.operations.fetch(:accepter) then
|
||||
query.state_en_instruction
|
||||
when BatchOperation.operations.fetch(:follow) then
|
||||
query.without_followers
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -74,6 +77,8 @@ class BatchOperation < ApplicationRecord
|
|||
dossier.passer_en_instruction(instructeur: instructeur)
|
||||
when BatchOperation.operations.fetch(:accepter)
|
||||
dossier.accepter(instructeur: instructeur, motivation: motivation, justificatif: justificatif_motivation)
|
||||
when BatchOperation.operations.fetch(:follow)
|
||||
instructeur.follow(dossier)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -110,6 +110,7 @@ RSpec.describe Dossiers::BatchAlertComponent, type: :component do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'accepter' do
|
||||
let(:component) do
|
||||
described_class.new(
|
||||
|
@ -163,4 +164,58 @@ RSpec.describe Dossiers::BatchAlertComponent, type: :component do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'follow' do
|
||||
let(:component) do
|
||||
described_class.new(
|
||||
batch: batch_operation,
|
||||
procedure: procedure
|
||||
)
|
||||
end
|
||||
let!(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
||||
let!(:dossier_2) { create(:dossier, :en_instruction, procedure: procedure) }
|
||||
let!(:batch_operation) { create(:batch_operation, operation: :follow, dossiers: [dossier, dossier_2], instructeur: instructeur) }
|
||||
|
||||
context 'in_progress' do
|
||||
before {
|
||||
batch_operation.track_processed_dossier(true, dossier)
|
||||
batch_operation.reload
|
||||
}
|
||||
|
||||
it { is_expected.to have_selector('.fr-alert--info') }
|
||||
it { is_expected.to have_text("Une action de masse est en cours") }
|
||||
it { is_expected.to have_text("1/2 dossiers ont été suivis") }
|
||||
end
|
||||
|
||||
context 'finished and success' do
|
||||
before {
|
||||
batch_operation.track_processed_dossier(true, dossier)
|
||||
batch_operation.track_processed_dossier(true, dossier_2)
|
||||
batch_operation.reload
|
||||
}
|
||||
|
||||
it { is_expected.to have_selector('.fr-alert--success') }
|
||||
it { is_expected.to have_text("L'action de masse est terminée") }
|
||||
it { is_expected.to have_text("2 dossiers ont été suivis") }
|
||||
it { expect(batch_operation.seen_at).to eq(nil) }
|
||||
end
|
||||
|
||||
context 'finished and fail' do
|
||||
before {
|
||||
batch_operation.track_processed_dossier(false, dossier)
|
||||
batch_operation.track_processed_dossier(true, dossier_2)
|
||||
batch_operation.reload
|
||||
}
|
||||
|
||||
it { is_expected.to have_selector('.fr-alert--warning') }
|
||||
it { is_expected.to have_text("L'action de masse est terminée") }
|
||||
it { is_expected.to have_text("1/2 dossiers ont été suivis") }
|
||||
it { expect(batch_operation.seen_at).to eq(nil) }
|
||||
|
||||
it 'on next render "seen_at" is set to avoid rendering alert' do
|
||||
render_inline(component).to_html
|
||||
expect(batch_operation.seen_at).not_to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,6 +25,11 @@ RSpec.describe Dossiers::BatchOperationComponent, type: :component do
|
|||
it { is_expected.to have_link('Accepter les dossiers sélectionnés') }
|
||||
end
|
||||
|
||||
context 'statut a-suivre' do
|
||||
let(:statut) { 'a-suivre' }
|
||||
it { is_expected.to have_button('Suivre les dossiers sélectionnés', disabled: true) }
|
||||
end
|
||||
|
||||
context 'statut tous' do
|
||||
let(:statut) { 'tous' }
|
||||
it { is_expected.not_to have_selector('button') }
|
||||
|
|
|
@ -39,5 +39,16 @@ FactoryBot.define do
|
|||
]
|
||||
end
|
||||
end
|
||||
|
||||
trait :follow do
|
||||
operation { BatchOperation.operations.fetch(:follow) }
|
||||
after(:build) do |batch_operation, evaluator|
|
||||
procedure = create(:simple_procedure, :published, instructeurs: [evaluator.invalid_instructeur.presence || batch_operation.instructeur], administrateurs: [create(:administrateur)])
|
||||
batch_operation.dossiers = [
|
||||
create(:dossier, :with_individual, :en_instruction, procedure: procedure),
|
||||
create(:dossier, :with_individual, :en_construction, procedure: procedure)
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -46,6 +46,20 @@ describe BatchOperationProcessOneJob, type: :job do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when operation is "follow"' do
|
||||
let(:batch_operation) do
|
||||
create(:batch_operation, :follow,
|
||||
options.merge(instructeur: create(:instructeur)))
|
||||
end
|
||||
|
||||
it 'adds a follower to the dossier' do
|
||||
expect { subject.perform_now }
|
||||
.to change { dossier_job.reload.follows }
|
||||
.from([])
|
||||
.to(anything)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when operation is "accepter"' do
|
||||
let(:batch_operation) do
|
||||
create(:batch_operation, :accepter,
|
||||
|
|
Loading…
Reference in a new issue