add limit of 500 dossiers
This commit is contained in:
parent
5802f3f7cf
commit
93a85ca4b0
4 changed files with 90 additions and 7 deletions
|
@ -4,6 +4,7 @@ module Instructeurs
|
||||||
before_action :ensure_not_super_admin!, only: [:download_export]
|
before_action :ensure_not_super_admin!, only: [:download_export]
|
||||||
|
|
||||||
ITEMS_PER_PAGE = 25
|
ITEMS_PER_PAGE = 25
|
||||||
|
BATCH_SELECTION_LIMIT = 500
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@procedures = current_instructeur
|
@procedures = current_instructeur
|
||||||
|
|
|
@ -20,7 +20,10 @@ export class BatchOperationController extends ApplicationController {
|
||||||
this.inputTargets.forEach((e) => (e.checked = target.checked));
|
this.inputTargets.forEach((e) => (e.checked = target.checked));
|
||||||
this.toggleSubmitButtonWhenNeeded();
|
this.toggleSubmitButtonWhenNeeded();
|
||||||
|
|
||||||
displayNotice(this.inputTargets);
|
const pagination = document.querySelector('.pagination')
|
||||||
|
if (pagination) {
|
||||||
|
displayNotice(this.inputTargets);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onSelectMore(event) {
|
onSelectMore(event) {
|
||||||
|
@ -38,6 +41,7 @@ export class BatchOperationController extends ApplicationController {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
emptyCheckboxes();
|
emptyCheckboxes();
|
||||||
deleteSelection();
|
deleteSelection();
|
||||||
|
this.toggleSubmitButtonWhenNeeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleSubmitButtonWhenNeeded() {
|
toggleSubmitButtonWhenNeeded() {
|
||||||
|
|
|
@ -5,13 +5,19 @@
|
||||||
%p.fr-notice__title
|
%p.fr-notice__title
|
||||||
Les
|
Les
|
||||||
%span#dynamic_number n
|
%span#dynamic_number n
|
||||||
dossiers de cette pages sont sélectionnés.
|
dossiers de cette page sont sélectionnés.
|
||||||
%a{ :href => "#", data: { action: "batch-operation#onSelectMore", dossiers: @filtered_sorted_ids.join(',') } }
|
%a{ :href => "#", data: { action: "batch-operation#onSelectMore", dossiers: @filtered_sorted_ids.first(Instructeurs::ProceduresController::BATCH_SELECTION_LIMIT).join(',') } }
|
||||||
= "Sélectionner les #{@dossiers_count} dossiers."
|
- if @dossiers_count <= Instructeurs::ProceduresController::BATCH_SELECTION_LIMIT
|
||||||
|
= "Sélectionner les #{@dossiers_count} dossiers."
|
||||||
|
- else
|
||||||
|
= "Sélectionner les #{Instructeurs::ProceduresController::BATCH_SELECTION_LIMIT} premiers dossiers sur les #{@dossiers_count}"
|
||||||
#selected.hidden
|
#selected.hidden
|
||||||
%p.fr-notice__title
|
%p.fr-notice__title
|
||||||
= "#{@dossiers_count} dossiers sont sélectionnés"
|
- if @dossiers_count <= Instructeurs::ProceduresController::BATCH_SELECTION_LIMIT
|
||||||
|
= "#{@dossiers_count} dossiers sont sélectionnés."
|
||||||
|
- else
|
||||||
|
= "#{Instructeurs::ProceduresController::BATCH_SELECTION_LIMIT} dossiers sont sélectionnés."
|
||||||
%a{ :href => "#", data: { action: "batch-operation#onDeleteSelection" } }
|
%a{ :href => "#", data: { action: "batch-operation#onDeleteSelection" } }
|
||||||
= "Effacer la sélection"
|
= "Effacer la sélection"
|
||||||
|
|
||||||
= check_box_tag :"batch_operation[dossier_ids][]", [], false, class: 'hidden', data: { batch_operation_target: "input", action: "batch-operation#onCheckOne", operations: "accepter,repasser_en_construction,follow,unfollow" }, form: dom_id(BatchOperation.new), id: dom_id(BatchOperation.new, "checkbox_multiple"), aria: { label: t('views.instructeurs.dossiers.batch_operation.enabled') }
|
= check_box_tag :"batch_operation[dossier_ids][]", [], false, class: 'hidden', data: { batch_operation_target: "input", action: "batch-operation#onCheckOne", operations: BatchOperation.operations.values.join(',') }, form: dom_id(BatchOperation.new), id: dom_id(BatchOperation.new, "checkbox_multiple"), aria: { label: t('views.instructeurs.dossiers.batch_operation.enabled') }
|
||||||
|
|
|
@ -61,18 +61,90 @@ describe 'BatchOperation a dossier:', js: true do
|
||||||
|
|
||||||
# try checkall
|
# try checkall
|
||||||
find("##{dom_id(BatchOperation.new, :checkbox_all)}").check
|
find("##{dom_id(BatchOperation.new, :checkbox_all)}").check
|
||||||
|
|
||||||
|
# multiple select notice don't appear if all the dossiers are on the same page
|
||||||
|
expect(page).to have_selector('.fr-notice', visible: false)
|
||||||
|
|
||||||
[dossier_2, dossier_3].map do |dossier|
|
[dossier_2, dossier_3].map do |dossier|
|
||||||
dossier_checkbox_id = dom_id(BatchOperation.new, "checkbox_#{dossier.id}")
|
dossier_checkbox_id = dom_id(BatchOperation.new, "checkbox_#{dossier.id}")
|
||||||
expect(page).to have_selector("##{dossier_checkbox_id}:checked")
|
expect(page).to have_selector("##{dossier_checkbox_id}:checked")
|
||||||
end
|
end
|
||||||
|
|
||||||
# submnit checkall
|
# submit checkall
|
||||||
expect { click_on "Archiver les dossiers" }
|
expect { click_on "Archiver les dossiers" }
|
||||||
.to change { BatchOperation.count }
|
.to change { BatchOperation.count }
|
||||||
.from(1).to(2)
|
.from(1).to(2)
|
||||||
|
|
||||||
expect(BatchOperation.last.dossiers).to match_array([dossier_2, dossier_3])
|
expect(BatchOperation.last.dossiers).to match_array([dossier_2, dossier_3])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario 'create a BatchOperation with more dossiers than pagination' do
|
||||||
|
stub_const "Instructeurs::ProceduresController::ITEMS_PER_PAGE", 2
|
||||||
|
dossier_1 = create(:dossier, :en_instruction, procedure: procedure)
|
||||||
|
dossier_2 = create(:dossier, :en_instruction, procedure: procedure)
|
||||||
|
dossier_3 = create(:dossier, :en_instruction, procedure: procedure)
|
||||||
|
log_in(instructeur.email, password)
|
||||||
|
|
||||||
|
visit instructeur_procedure_path(procedure, statut: 'a-suivre')
|
||||||
|
|
||||||
|
expect(page).to have_content("1 - 2 sur 3 dossiers")
|
||||||
|
|
||||||
|
# click on check_all make the notice appear
|
||||||
|
find("##{dom_id(BatchOperation.new, :checkbox_all)}").check
|
||||||
|
expect(page).to have_selector('.fr-notice')
|
||||||
|
expect(page).to have_content('Les 2 dossiers de cette pages sont sélectionnés. Sélectionner les 3 dossiers.')
|
||||||
|
|
||||||
|
# click on selection link fill checkbox value with dossier_ids
|
||||||
|
click_on("Sélectionner les 3 dossiers")
|
||||||
|
expect(page).to have_content('3 dossiers sont sélectionnés. Effacer la sélection ')
|
||||||
|
expect(page).to have_selector('#checkbox_multiple_batch_operation', visible: false)
|
||||||
|
expect(find_field("batch_operation[dossier_ids][]", match: :first).value).to eq "#{dossier_3.id},#{dossier_2.id},#{dossier_1.id}"
|
||||||
|
|
||||||
|
# click on delete link empty checkbox value and hide notice
|
||||||
|
click_on("Effacer la sélection")
|
||||||
|
expect(page).to have_selector('.fr-notice', visible: false)
|
||||||
|
expect(page).to have_button("Suivre les dossiers", disabled: true)
|
||||||
|
expect(find_field("batch_operation[dossier_ids][]", match: :first).value).to eq ""
|
||||||
|
|
||||||
|
# click on check_all + notice link and submit
|
||||||
|
find("##{dom_id(BatchOperation.new, :checkbox_all)}").check
|
||||||
|
click_on("Sélectionner les 3 dossiers")
|
||||||
|
|
||||||
|
expect { click_on "Suivre les dossiers" }
|
||||||
|
.to change { BatchOperation.count }
|
||||||
|
.from(0).to(1)
|
||||||
|
|
||||||
|
expect(BatchOperation.last.dossiers).to match_array([dossier_1, dossier_2, dossier_3])
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'create a BatchOperation within the limit of selection' do
|
||||||
|
stub_const "Instructeurs::ProceduresController::ITEMS_PER_PAGE", 2
|
||||||
|
stub_const "Instructeurs::ProceduresController::BATCH_SELECTION_LIMIT", 3
|
||||||
|
dossier_1 = create(:dossier, :en_instruction, procedure: procedure)
|
||||||
|
dossier_2 = create(:dossier, :en_instruction, procedure: procedure)
|
||||||
|
dossier_3 = create(:dossier, :en_instruction, procedure: procedure)
|
||||||
|
dossier_4 = create(:dossier, :en_instruction, procedure: procedure)
|
||||||
|
log_in(instructeur.email, password)
|
||||||
|
|
||||||
|
visit instructeur_procedure_path(procedure, statut: 'a-suivre')
|
||||||
|
|
||||||
|
# click on check_all make the notice appear
|
||||||
|
find("##{dom_id(BatchOperation.new, :checkbox_all)}").check
|
||||||
|
expect(page).to have_selector('.fr-notice')
|
||||||
|
expect(page).to have_content('Les 2 dossiers de cette page sont sélectionnés. Sélectionner les 3 premiers dossiers sur les 4')
|
||||||
|
|
||||||
|
# click on selection link fill checkbox value with dossier_ids
|
||||||
|
click_on("Sélectionner les 3 premiers dossiers sur les 4")
|
||||||
|
expect(page).to have_content('3 dossiers sont sélectionnés. Effacer la sélection')
|
||||||
|
expect(find_field("batch_operation[dossier_ids][]", match: :first).value).to eq "#{dossier_4.id},#{dossier_3.id},#{dossier_2.id}"
|
||||||
|
|
||||||
|
# create batch
|
||||||
|
expect { click_on "Suivre les dossiers" }
|
||||||
|
.to change { BatchOperation.count }
|
||||||
|
.from(0).to(1)
|
||||||
|
|
||||||
|
expect(BatchOperation.last.dossiers).to match_array([dossier_2, dossier_3, dossier_4])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def log_in(email, password, check_email: true)
|
def log_in(email, password, check_email: true)
|
||||||
|
|
Loading…
Add table
Reference in a new issue