Merge pull request #8887 from demarches-simplifiees/8839-filter-by-siret
Filtrer les démarches par service
This commit is contained in:
commit
4c5e903673
5 changed files with 47 additions and 1 deletions
|
@ -416,11 +416,17 @@ module Administrateurs
|
|||
private
|
||||
|
||||
def filter_procedures(filter)
|
||||
if filter.service_siret.present?
|
||||
service = Service.find_by(siret: filter.service_siret)
|
||||
return Procedure.none if service.nil?
|
||||
end
|
||||
|
||||
procedures_result = Procedure.select(:id).left_joins(:procedures_zones).distinct.publiees_ou_closes
|
||||
procedures_result = procedures_result.where(procedures_zones: { zone_id: filter.zone_ids }) if filter.zone_ids.present?
|
||||
procedures_result = procedures_result.where(aasm_state: filter.statuses) if filter.statuses.present?
|
||||
procedures_result = procedures_result.where("tags @> ARRAY[?]::text[]", filter.tags) if filter.tags.present?
|
||||
procedures_result = procedures_result.where('published_at >= ?', filter.from_publication_date) if filter.from_publication_date.present?
|
||||
procedures_result = procedures_result.where(service: service) if filter.service_siret.present?
|
||||
procedures_result = procedures_result.where('unaccent(libelle) ILIKE unaccent(?)', "%#{filter.libelle}%") if filter.libelle.present?
|
||||
procedures_sql = procedures_result.to_sql
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ class ProceduresFilter
|
|||
|
||||
def initialize(admin, params)
|
||||
@admin = admin
|
||||
@params = params.permit(:page, :libelle, :email, :from_publication_date, tags: [], zone_ids: [], statuses: [])
|
||||
@params = params.permit(:page, :libelle, :email, :from_publication_date, :service_siret, tags: [], zone_ids: [], statuses: [])
|
||||
end
|
||||
|
||||
def admin_zones
|
||||
|
@ -32,6 +32,10 @@ class ProceduresFilter
|
|||
params[:tags].compact_blank.uniq if params[:tags].present?
|
||||
end
|
||||
|
||||
def service_siret
|
||||
params[:service_siret].presence
|
||||
end
|
||||
|
||||
def from_publication_date
|
||||
return if params[:from_publication_date].blank?
|
||||
|
||||
|
|
|
@ -22,6 +22,9 @@
|
|||
- if @filter.libelle
|
||||
.selected-query.fr-mb-2w
|
||||
= link_to @filter.libelle, all_admin_procedures_path(@filter.without(:libelle)), class: 'fr-tag fr-tag--dismiss fr-mb-1w'
|
||||
- if @filter.service_siret
|
||||
.selected-query.fr-mb-2w
|
||||
= link_to @filter.service_siret, all_admin_procedures_path(@filter.without(:service_siret)), class: 'fr-tag fr-tag--dismiss fr-mb-1w'
|
||||
- if @filter.selected_zones.present?
|
||||
.selected-zones.fr-mb-2w
|
||||
- @filter.selected_zones.each do |zone|
|
||||
|
|
|
@ -43,6 +43,14 @@
|
|||
.fr-checkbox-group.fr-ml-2w.fr-py-1w
|
||||
= b.check_box(checked: @filter.zone_filtered?(b.value))
|
||||
= b.label(class: 'fr-label') { b.text }
|
||||
%li.fr-py-2w.fr-pl-2w{ 'data-controller': "expand" }
|
||||
.fr-mb-1w
|
||||
%button{ 'data-action': 'expand#toggle' }
|
||||
%span.fr-icon-add-line.fr-icon--sm.fr-mr-1w.fr-text-action-high--blue-france{ 'aria-hidden': 'true', 'data-expand-target': 'icon' }
|
||||
Service
|
||||
.fr-ml-1w.hidden{ 'data-expand-target': 'content' }
|
||||
%div
|
||||
= f.text_field :service_siret, placeholder: 'Indiquez le SIRET', class: 'fr-input'
|
||||
%li.fr-py-2w{ 'data-controller': "expand" }
|
||||
.fr-mb-1w.fr-pl-2w
|
||||
%button{ 'data-action': 'click->expand#toggle' }
|
||||
|
|
|
@ -172,6 +172,31 @@ describe Administrateurs::ProceduresController, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
context 'with specific service' do
|
||||
let(:requested_siret) { '13001501900024' }
|
||||
let(:another_siret) { '11000004900012' }
|
||||
let(:requested_service) { create(:service, siret: requested_siret) }
|
||||
let(:another_service) { create(:service, siret: another_siret) }
|
||||
let!(:procedure1) { create(:procedure, :published, service: another_service) }
|
||||
let!(:procedure2) { create(:procedure, :published, service: requested_service) }
|
||||
it 'display only procedures with specific service (identified by siret)' do
|
||||
get :all, params: { service_siret: requested_siret }
|
||||
expect(assigns(:procedures).any? { |p| p.id == procedure1.id }).to be_falsey
|
||||
expect(assigns(:procedures).any? { |p| p.id == procedure2.id }).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a siret which does not identify a service' do
|
||||
let(:requested_siret) { '13001501900024' }
|
||||
let(:another_siret) { '11000004900012' }
|
||||
let(:another_service) { create(:service, siret: another_siret) }
|
||||
let!(:procedure1) { create(:procedure, :published, service: another_service) }
|
||||
it 'displays none procedure' do
|
||||
get :all, params: { service_siret: requested_siret }
|
||||
expect(assigns(:procedures)).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context 'with specific tag' do
|
||||
let!(:tags_procedure) { create(:procedure, :published, tags: ['environnement', 'diplomatie']) }
|
||||
|
||||
|
|
Loading…
Reference in a new issue