add from_created_at filter
This commit is contained in:
parent
39f534b3d7
commit
21ed6abcad
4 changed files with 49 additions and 6 deletions
|
@ -11,6 +11,11 @@
|
||||||
= b.check_box(checked: filter.states_filtered?(b.value))
|
= b.check_box(checked: filter.states_filtered?(b.value))
|
||||||
= b.label(class: 'fr-label') { t b.text, scope: 'activerecord.attributes.procedure.aasm_state' }
|
= b.label(class: 'fr-label') { t b.text, scope: 'activerecord.attributes.procedure.aasm_state' }
|
||||||
|
|
||||||
|
.fr-col-12.fr-col-md-3
|
||||||
|
.fr-input-group
|
||||||
|
= f.label 'from_created_at_date', 'Dossier créé depuis le', class: 'fr-label'
|
||||||
|
= f.date_field 'from_created_at_date', value: @filter.from_created_at_date, class: 'fr-input'
|
||||||
|
|
||||||
.fr-mb-2w
|
.fr-mb-2w
|
||||||
= f.submit 'Appliquer les filtres', class: 'fr-btn fr-btn--sm'
|
= f.submit 'Appliquer les filtres', class: 'fr-btn fr-btn--sm'
|
||||||
= link_to 'Réinitialiser les filtres', dossiers_path(statut: @statut), class: 'fr-btn fr-btn--sm fr-btn--tertiary-no-outline'
|
= link_to 'Réinitialiser les filtres', dossiers_path(statut: @statut), class: 'fr-btn fr-btn--sm fr-btn--tertiary-no-outline'
|
||||||
|
|
|
@ -51,14 +51,17 @@ module Users
|
||||||
@first_brouillon_recently_updated = current_user.dossiers.visible_by_user.brouillons_recently_updated.first
|
@first_brouillon_recently_updated = current_user.dossiers.visible_by_user.brouillons_recently_updated.first
|
||||||
|
|
||||||
@filter = DossiersFilter.new(current_user, params)
|
@filter = DossiersFilter.new(current_user, params)
|
||||||
if params[:states]
|
if @filter.filter_params.present?
|
||||||
@dossiers_result = filter_procedures(@filter, current_user.dossiers.visible_by_user)
|
@dossiers_result = filter_procedures(@filter, @dossiers)
|
||||||
@dossiers = @dossiers_result.page(page)
|
@dossiers = @dossiers_result.page(page)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def filter_procedures(filter, dossiers)
|
def filter_procedures(filter, dossiers)
|
||||||
dossiers.where(state: filter.states) if filter.states.present?
|
dossiers_result = dossiers
|
||||||
|
dossiers_result = dossiers_result.where(state: filter.states) if filter.states.present?
|
||||||
|
dossiers_result = dossiers_result.where('created_at >= ?', filter.from_created_at_date) if filter.from_created_at_date.present?
|
||||||
|
dossiers_result
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
|
|
@ -5,7 +5,11 @@ class DossiersFilter
|
||||||
|
|
||||||
def initialize(user, params)
|
def initialize(user, params)
|
||||||
@user = user
|
@user = user
|
||||||
@params = params.permit(:page, :from_publication_date, states: [])
|
@params = params.permit(:page, :from_created_at_date, states: [])
|
||||||
|
end
|
||||||
|
|
||||||
|
def filter_params
|
||||||
|
params[:from_created_at_date].presence || params[:states].presence
|
||||||
end
|
end
|
||||||
|
|
||||||
def states
|
def states
|
||||||
|
@ -15,4 +19,12 @@ class DossiersFilter
|
||||||
def states_filtered?(state)
|
def states_filtered?(state)
|
||||||
states&.include?(state)
|
states&.include?(state)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def from_created_at_date
|
||||||
|
return if params[:from_created_at_date].blank?
|
||||||
|
|
||||||
|
Date.parse(params[:from_created_at_date])
|
||||||
|
rescue Date::Error
|
||||||
|
nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -57,7 +57,7 @@ describe 'user access to the list of their dossiers', js: true do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when user uses filter' do
|
context 'when user uses filter' do
|
||||||
scenario 'user filter by brouillon state on tab "en-cours"' do
|
scenario 'user filters by brouillon state on tab "en-cours"' do
|
||||||
expect(page).to have_text('4 en cours')
|
expect(page).to have_text('4 en cours')
|
||||||
expect(page).to have_text('2 traités')
|
expect(page).to have_text('2 traités')
|
||||||
expect(page).to have_text('4 sur 4 dossiers')
|
expect(page).to have_text('4 sur 4 dossiers')
|
||||||
|
@ -67,7 +67,7 @@ describe 'user access to the list of their dossiers', js: true do
|
||||||
expect(page).to have_checked_field('Brouillon')
|
expect(page).to have_checked_field('Brouillon')
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'user filter by brouillon state on tab "traité"' do
|
scenario 'user filters by brouillon state on tab "traité"' do
|
||||||
visit dossiers_path(statut: 'traites')
|
visit dossiers_path(statut: 'traites')
|
||||||
expect(page).to have_text('4 en cours')
|
expect(page).to have_text('4 en cours')
|
||||||
expect(page).to have_text('2 traités')
|
expect(page).to have_text('2 traités')
|
||||||
|
@ -80,6 +80,29 @@ describe 'user access to the list of their dossiers', js: true do
|
||||||
expect(page).to have_text('2 sur 2 dossiers')
|
expect(page).to have_text('2 sur 2 dossiers')
|
||||||
expect(page).to have_unchecked_field('Refuse')
|
expect(page).to have_unchecked_field('Refuse')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario 'user filters by created_at' do
|
||||||
|
dossier_en_construction.update!(created_at: Date.yesterday)
|
||||||
|
|
||||||
|
expect(page).to have_text('4 sur 4 dossiers')
|
||||||
|
fill_in 'from_created_at_date', with: Date.today
|
||||||
|
click_on('Appliquer les filtres')
|
||||||
|
expect(page).to have_text('3 sur 3 dossiers')
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'user filters by states and created at' do
|
||||||
|
dossier_en_construction.update!(created_at: Date.yesterday)
|
||||||
|
|
||||||
|
expect(page).to have_text('4 sur 4 dossiers')
|
||||||
|
fill_in 'from_created_at_date', with: Date.today
|
||||||
|
click_on('Appliquer les filtres')
|
||||||
|
expect(page).to have_text('3 sur 3 dossiers')
|
||||||
|
|
||||||
|
find("label", text: "En Construction").click
|
||||||
|
find("label", text: "En Instruction").click
|
||||||
|
click_on('Appliquer les filtres')
|
||||||
|
expect(page).to have_text('2 sur 2 dossiers')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when user clicks on a projet in list' do
|
context 'when user clicks on a projet in list' do
|
||||||
|
|
Loading…
Reference in a new issue