From 26a86d800314d18470a6688cba008dfe4e2dee09 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Fri, 23 Feb 2024 15:52:17 +0100 Subject: [PATCH] filter all demarches by kind usager --- .../administrateurs/procedures_controller.rb | 1 + app/models/procedures_filter.rb | 17 ++++++++++- .../administrateurs/procedures/all.html.haml | 4 +++ app/views/layouts/all.html.haml | 10 +++++++ config/locales/models/procedure/en.yml | 3 ++ config/locales/models/procedure/fr.yml | 3 ++ .../procedures_controller_spec.rb | 30 +++++++++++++++++++ 7 files changed, 67 insertions(+), 1 deletion(-) diff --git a/app/controllers/administrateurs/procedures_controller.rb b/app/controllers/administrateurs/procedures_controller.rb index ae0ab979b..71fd25f56 100644 --- a/app/controllers/administrateurs/procedures_controller.rb +++ b/app/controllers/administrateurs/procedures_controller.rb @@ -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(service: service) if filter.service_siret.present? 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_sql = procedures_result.to_sql diff --git a/app/models/procedures_filter.rb b/app/models/procedures_filter.rb index bc3213da7..c590cd355 100644 --- a/app/models/procedures_filter.rb +++ b/app/models/procedures_filter.rb @@ -8,7 +8,7 @@ class ProceduresFilter 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 def admin_zones @@ -35,6 +35,21 @@ class ProceduresFilter params[:tags].compact_blank.uniq if params[:tags].present? 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? ActiveRecord::Type::Boolean.new.cast(params[:template]) end diff --git a/app/views/administrateurs/procedures/all.html.haml b/app/views/administrateurs/procedures/all.html.haml index 41eea5eb6..43069b757 100644 --- a/app/views/administrateurs/procedures/all.html.haml +++ b/app/views/administrateurs/procedures/all.html.haml @@ -36,6 +36,10 @@ .selected-statuses.fr-mb-2w - @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' + - 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? .selected-tag.fr-mb-2w - @filter.tags.each do |tag| diff --git a/app/views/layouts/all.html.haml b/app/views/layouts/all.html.haml index 9fac8e547..2b785e13f 100644 --- a/app/views/layouts/all.html.haml +++ b/app/views/layouts/all.html.haml @@ -86,6 +86,16 @@ = b.check_box(checked: @filter.status_filtered?(b.value)) = 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" } .fr-mb-1w %button{ 'data-action': 'expand#toggle' } diff --git a/config/locales/models/procedure/en.yml b/config/locales/models/procedure/en.yml index e999c6afa..5ef198442 100644 --- a/config/locales/models/procedure/en.yml +++ b/config/locales/models/procedure/en.yml @@ -34,6 +34,9 @@ en: publiee: Published close: Closed hidden: Destroyed + kind_usager: + individual: Individual + personne_morale: 'Legal entity' declarative_with_state/en_instruction: Instruction declarative_with_state/accepte: Accepted api_particulier_token: Token API Particulier diff --git a/config/locales/models/procedure/fr.yml b/config/locales/models/procedure/fr.yml index 5fa059494..dd356c947 100644 --- a/config/locales/models/procedure/fr.yml +++ b/config/locales/models/procedure/fr.yml @@ -40,6 +40,9 @@ fr: close: Close hidden: Supprimée depubliee: Dépubliée + kind_usager: + individual: Particulier + personne_morale: 'Personne morale' declarative_with_state/en_instruction: En instruction declarative_with_state/accepte: Accepté api_particulier_token: Jeton API Particulier diff --git a/spec/controllers/administrateurs/procedures_controller_spec.rb b/spec/controllers/administrateurs/procedures_controller_spec.rb index 3499c679a..ec6f2a5f5 100644 --- a/spec/controllers/administrateurs/procedures_controller_spec.rb +++ b/spec/controllers/administrateurs/procedures_controller_spec.rb @@ -240,6 +240,36 @@ describe Administrateurs::ProceduresController, type: :controller do 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 let!(:tags_procedure) { create(:procedure, :published, tags: ['environnement', 'diplomatie']) }