filter all demarches by departement
This commit is contained in:
parent
97ff31f60f
commit
ef4113f8f9
5 changed files with 36 additions and 1 deletions
|
@ -421,6 +421,8 @@ module Administrateurs
|
||||||
return Procedure.none if service.nil?
|
return Procedure.none if service.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
services = Service.where(departement: filter.service_departement) if filter.service_departement.present?
|
||||||
|
|
||||||
procedures_result = Procedure.select(:id).left_joins(:procedures_zones).distinct.publiees_ou_closes
|
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(procedures_zones: { zone_id: filter.zone_ids }) if filter.zone_ids.present?
|
||||||
procedures_result = procedures_result.where(hidden_at_as_template: nil)
|
procedures_result = procedures_result.where(hidden_at_as_template: nil)
|
||||||
|
@ -428,6 +430,7 @@ module Administrateurs
|
||||||
procedures_result = procedures_result.where("tags @> ARRAY[?]::text[]", filter.tags) if filter.tags.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('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(service: service) if filter.service_siret.present?
|
||||||
|
procedures_result = procedures_result.where(service: services) if services
|
||||||
procedures_result = procedures_result.where('unaccent(libelle) ILIKE unaccent(?)', "%#{filter.libelle}%") if filter.libelle.present?
|
procedures_result = procedures_result.where('unaccent(libelle) ILIKE unaccent(?)', "%#{filter.libelle}%") if filter.libelle.present?
|
||||||
procedures_sql = procedures_result.to_sql
|
procedures_sql = procedures_result.to_sql
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ class ProceduresFilter
|
||||||
|
|
||||||
def initialize(admin, params)
|
def initialize(admin, params)
|
||||||
@admin = admin
|
@admin = admin
|
||||||
@params = params.permit(:page, :libelle, :email, :from_publication_date, :service_siret, tags: [], zone_ids: [], statuses: [])
|
@params = params.permit(:page, :libelle, :email, :from_publication_date, :service_siret, :service_departement, tags: [], zone_ids: [], statuses: [])
|
||||||
end
|
end
|
||||||
|
|
||||||
def admin_zones
|
def admin_zones
|
||||||
|
@ -36,6 +36,10 @@ class ProceduresFilter
|
||||||
params[:service_siret].presence
|
params[:service_siret].presence
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def service_departement
|
||||||
|
params[:service_departement].presence
|
||||||
|
end
|
||||||
|
|
||||||
def from_publication_date
|
def from_publication_date
|
||||||
return if params[:from_publication_date].blank?
|
return if params[:from_publication_date].blank?
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,9 @@
|
||||||
- if @filter.service_siret
|
- if @filter.service_siret
|
||||||
.selected-query.fr-mb-2w
|
.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'
|
= link_to @filter.service_siret, all_admin_procedures_path(@filter.without(:service_siret)), class: 'fr-tag fr-tag--dismiss fr-mb-1w'
|
||||||
|
- if @filter.service_departement
|
||||||
|
.selected-query.fr-mb-2w
|
||||||
|
= link_to @filter.service_departement, all_admin_procedures_path(@filter.without(:service_departement)), class: 'fr-tag fr-tag--dismiss fr-mb-1w'
|
||||||
- if @filter.selected_zones.present?
|
- if @filter.selected_zones.present?
|
||||||
.selected-zones.fr-mb-2w
|
.selected-zones.fr-mb-2w
|
||||||
- @filter.selected_zones.each do |zone|
|
- @filter.selected_zones.each do |zone|
|
||||||
|
|
|
@ -51,6 +51,18 @@
|
||||||
.fr-ml-1w.hidden{ 'data-expand-target': 'content' }
|
.fr-ml-1w.hidden{ 'data-expand-target': 'content' }
|
||||||
%div
|
%div
|
||||||
= f.text_field :service_siret, placeholder: 'Indiquez le SIRET', class: 'fr-input'
|
= f.text_field :service_siret, placeholder: 'Indiquez le SIRET', class: 'fr-input'
|
||||||
|
%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' }
|
||||||
|
Département
|
||||||
|
.fr-ml-1w.hidden{ 'data-expand-target': 'content' }
|
||||||
|
%div
|
||||||
|
= f.select :service_departement,
|
||||||
|
APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] },
|
||||||
|
{ selected: @filter.service_departement, include_blank: ''},
|
||||||
|
id: "service_dep_select",
|
||||||
|
class: 'fr-select'
|
||||||
%li.fr-py-2w{ 'data-controller': "expand" }
|
%li.fr-py-2w{ 'data-controller': "expand" }
|
||||||
.fr-mb-1w.fr-pl-2w
|
.fr-mb-1w.fr-pl-2w
|
||||||
%button{ 'data-action': 'click->expand#toggle' }
|
%button{ 'data-action': 'click->expand#toggle' }
|
||||||
|
|
|
@ -210,6 +210,19 @@ describe Administrateurs::ProceduresController, type: :controller do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with service departement' do
|
||||||
|
let(:service) { create(:service, departement: '63') }
|
||||||
|
let(:service2) { create(:service, departement: '75') }
|
||||||
|
let!(:procedure) { create(:procedure, :published, service: service) }
|
||||||
|
let!(:procedure2) { create(:procedure, :published, service: service2) }
|
||||||
|
|
||||||
|
it 'returns procedures with correct departement' do
|
||||||
|
get :all, params: { service_departement: '63' }
|
||||||
|
expect(assigns(:procedures).any? { |p| p.id == procedure.id }).to be_truthy
|
||||||
|
expect(assigns(:procedures).any? { |p| p.id == procedure2.id }).to be_falsey
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'with specific tag' do
|
context 'with specific tag' do
|
||||||
let!(:tags_procedure) { create(:procedure, :published, tags: ['environnement', 'diplomatie']) }
|
let!(:tags_procedure) { create(:procedure, :published, tags: ['environnement', 'diplomatie']) }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue