filter all demarches by kind usager
This commit is contained in:
parent
7143c7e8e2
commit
26a86d8003
7 changed files with 67 additions and 1 deletions
|
@ -421,6 +421,7 @@ module Administrateurs
|
||||||
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(service: services) if services
|
||||||
|
procedures_result = procedures_result.where(for_individual: filter.for_individual) if filter.for_individual.present?
|
||||||
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
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ class ProceduresFilter
|
||||||
|
|
||||||
params[:zone_ids] = admin.zones.pluck(:id) if params[:zone_ids] == 'admin_default'
|
params[:zone_ids] = admin.zones.pluck(:id) if params[:zone_ids] == 'admin_default'
|
||||||
|
|
||||||
@params = params.permit(:page, :libelle, :email, :from_publication_date, :service_siret, :service_departement, :template, tags: [], zone_ids: [], statuses: [])
|
@params = params.permit(:page, :libelle, :email, :from_publication_date, :service_siret, :service_departement, :template, tags: [], zone_ids: [], statuses: [], kind_usagers: [])
|
||||||
end
|
end
|
||||||
|
|
||||||
def admin_zones
|
def admin_zones
|
||||||
|
@ -35,6 +35,21 @@ class ProceduresFilter
|
||||||
params[:tags].compact_blank.uniq if params[:tags].present?
|
params[:tags].compact_blank.uniq if params[:tags].present?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def kind_usagers
|
||||||
|
params[:kind_usagers].compact_blank if params[:kind_usagers].present?
|
||||||
|
end
|
||||||
|
|
||||||
|
def kind_usager_filtered?(kind_usager)
|
||||||
|
kind_usagers&.include?(kind_usager)
|
||||||
|
end
|
||||||
|
|
||||||
|
def for_individual
|
||||||
|
kind_usagers = params[:kind_usagers]
|
||||||
|
if kind_usagers.present?
|
||||||
|
kind_usagers.map { |k| k == "individual" }.uniq
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def template?
|
def template?
|
||||||
ActiveRecord::Type::Boolean.new.cast(params[:template])
|
ActiveRecord::Type::Boolean.new.cast(params[:template])
|
||||||
end
|
end
|
||||||
|
|
|
@ -36,6 +36,10 @@
|
||||||
.selected-statuses.fr-mb-2w
|
.selected-statuses.fr-mb-2w
|
||||||
- @filter.statuses.each do |status|
|
- @filter.statuses.each do |status|
|
||||||
= link_to status, all_admin_procedures_path(@filter.without(:statuses, status)), class: 'fr-tag fr-tag--dismiss fr-mb-1w'
|
= link_to status, all_admin_procedures_path(@filter.without(:statuses, status)), class: 'fr-tag fr-tag--dismiss fr-mb-1w'
|
||||||
|
- if @filter.kind_usagers.present?
|
||||||
|
.selected-kind_usagers.fr-mb-2w
|
||||||
|
- @filter.kind_usagers.each do |kind_usager|
|
||||||
|
= link_to t(kind_usager, scope: 'activerecord.attributes.procedure.kind_usager'), all_admin_procedures_path(@filter.without(:kind_usagers, kind_usager)), class: 'fr-tag fr-tag--dismiss fr-mb-1w'
|
||||||
- if @filter.tags.present?
|
- if @filter.tags.present?
|
||||||
.selected-tag.fr-mb-2w
|
.selected-tag.fr-mb-2w
|
||||||
- @filter.tags.each do |tag|
|
- @filter.tags.each do |tag|
|
||||||
|
|
|
@ -86,6 +86,16 @@
|
||||||
= b.check_box(checked: @filter.status_filtered?(b.value))
|
= b.check_box(checked: @filter.status_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' }
|
||||||
|
|
||||||
|
%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' }
|
||||||
|
Type d'usager
|
||||||
|
.fr-ml-1w.hidden{ 'data-expand-target': 'content' }
|
||||||
|
= f.collection_check_boxes :kind_usagers, ['individual', 'personne_morale'], :to_s, :to_s, include_hidden: false do |b|
|
||||||
|
.fr-checkbox-group.fr-ml-2w.fr-py-1w
|
||||||
|
= b.check_box(checked: @filter.kind_usager_filtered?(b.value))
|
||||||
|
= b.label(class: 'fr-label') { t b.text, scope: 'activerecord.attributes.procedure.kind_usager' }
|
||||||
%li.fr-py-2w.fr-pl-2w{ 'data-controller': "expand" }
|
%li.fr-py-2w.fr-pl-2w{ 'data-controller': "expand" }
|
||||||
.fr-mb-1w
|
.fr-mb-1w
|
||||||
%button{ 'data-action': 'expand#toggle' }
|
%button{ 'data-action': 'expand#toggle' }
|
||||||
|
|
|
@ -34,6 +34,9 @@ en:
|
||||||
publiee: Published
|
publiee: Published
|
||||||
close: Closed
|
close: Closed
|
||||||
hidden: Destroyed
|
hidden: Destroyed
|
||||||
|
kind_usager:
|
||||||
|
individual: Individual
|
||||||
|
personne_morale: 'Legal entity'
|
||||||
declarative_with_state/en_instruction: Instruction
|
declarative_with_state/en_instruction: Instruction
|
||||||
declarative_with_state/accepte: Accepted
|
declarative_with_state/accepte: Accepted
|
||||||
api_particulier_token: Token API Particulier
|
api_particulier_token: Token API Particulier
|
||||||
|
|
|
@ -40,6 +40,9 @@ fr:
|
||||||
close: Close
|
close: Close
|
||||||
hidden: Supprimée
|
hidden: Supprimée
|
||||||
depubliee: Dépubliée
|
depubliee: Dépubliée
|
||||||
|
kind_usager:
|
||||||
|
individual: Particulier
|
||||||
|
personne_morale: 'Personne morale'
|
||||||
declarative_with_state/en_instruction: En instruction
|
declarative_with_state/en_instruction: En instruction
|
||||||
declarative_with_state/accepte: Accepté
|
declarative_with_state/accepte: Accepté
|
||||||
api_particulier_token: Jeton API Particulier
|
api_particulier_token: Jeton API Particulier
|
||||||
|
|
|
@ -240,6 +240,36 @@ describe Administrateurs::ProceduresController, type: :controller do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'only for individual' do
|
||||||
|
let!(:procedure) { create(:procedure, :published, for_individual: true) }
|
||||||
|
let!(:procedure2) { create(:procedure, :published, for_individual: false) }
|
||||||
|
it 'returns procedures with specifi type of usager' do
|
||||||
|
get :all, params: { kind_usagers: ['individual'] }
|
||||||
|
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 'only for entreprise' do
|
||||||
|
let!(:procedure) { create(:procedure, :published, for_individual: true) }
|
||||||
|
let!(:procedure2) { create(:procedure, :published, for_individual: false) }
|
||||||
|
it 'returns procedures with specifi type of usager' do
|
||||||
|
get :all, params: { kind_usagers: ['personne_morale'] }
|
||||||
|
expect(assigns(:procedures).any? { |p| p.id == procedure.id }).to be_falsey
|
||||||
|
expect(assigns(:procedures).any? { |p| p.id == procedure2.id }).to be_truthy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'for individual and entreprise' do
|
||||||
|
let!(:procedure) { create(:procedure, :published, for_individual: true) }
|
||||||
|
let!(:procedure2) { create(:procedure, :published, for_individual: false) }
|
||||||
|
it 'returns procedures with specifi type of usager' do
|
||||||
|
get :all, params: { kind_usagers: ['individual', 'personne_morale'] }
|
||||||
|
expect(assigns(:procedures).any? { |p| p.id == procedure.id }).to be_truthy
|
||||||
|
expect(assigns(:procedures).any? { |p| p.id == procedure2.id }).to be_truthy
|
||||||
|
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