Merge pull request #8089 from demarches-simplifiees/search-libelle

ETQ admin, je peux rechercher des démarches en fonction de leur libellé parmi la liste de toutes les démarches (eventuellement 
filtrées)
This commit is contained in:
krichtof 2022-11-22 17:55:30 +01:00 committed by GitHub
commit e16a33a316
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 4 deletions

View file

@ -350,6 +350,7 @@ module Administrateurs
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('published_at >= ?', filter.from_publication_date) if filter.from_publication_date.present?
procedures_result = procedures_result.where('unaccent(libelle) ILIKE unaccent(?)', "%#{filter.libelle}%") if filter.libelle.present?
procedures_result
end

View file

@ -5,7 +5,7 @@ class ProceduresFilter
def initialize(admin, params)
@admin = admin
@params = params.permit(:page, :from_publication_date, zone_ids: [], statuses: [])
@params = params.permit(:page, :libelle, :from_publication_date, zone_ids: [], statuses: [])
end
def admin_zones
@ -36,6 +36,10 @@ class ProceduresFilter
nil
end
def libelle
ActiveRecord::Base.sanitize_sql_like(params[:libelle]) if params[:libelle].present?
end
def zone_filtered?(zone_id)
zone_ids&.map(&:to_i)&.include?(zone_id)
end

View file

@ -1,12 +1,23 @@
- content_for :results do
.main-filter-header.fr-my-3w
.search
= link_to 'Voir la liste des administrateurs', administrateurs_admin_procedures_path(@filter.params), class: 'fr-btn fr-btn--secondary btn-admins'
= form_with(url: all_admin_procedures_path, method: :get, html: {'data-autosubmit-target': 'form', role: 'search' }) do |f|
- @filter.zone_ids&.each do |zone_id|
= hidden_field_tag 'zone_ids[]', zone_id
- @filter.statuses&.each do |status|
= hidden_field_tag 'statuses[]', status
= hidden_field_tag 'from_publication_date', @filter.from_publication_date if @filter.from_publication_date.present?
= f.label :libelle, 'Rechercher des démarches par libellé', class: 'fr-label'
= f.search_field 'libelle', size: 40, class: 'fr-input'
.switch= link_to 'Voir la liste des administrateurs', administrateurs_admin_procedures_path(@filter.params), class: 'fr-btn fr-btn--secondary'
.fr-table.fr-table--bordered
%table#all-demarches
%caption
= "#{@procedures.total_count} démarches"
%span.hidden.fr-icon-ball-pen-fill{ 'aria-hidden': 'true', 'data-autosubmit-target': 'spinner' }
- 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.selected_zones.present?
.selected-zones.fr-mb-2w
- @filter.selected_zones.each do |zone|

View file

@ -0,0 +1,7 @@
class AddLibelleIndexToProcedures < ActiveRecord::Migration[6.1]
disable_ddl_transaction!
def change
add_index :procedures, :libelle, algorithm: :concurrently
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_11_10_100759) do
ActiveRecord::Schema.define(version: 2022_11_22_123809) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
@ -679,6 +679,7 @@ ActiveRecord::Schema.define(version: 2022_11_10_100759) do
t.index ["declarative_with_state"], name: "index_procedures_on_declarative_with_state"
t.index ["draft_revision_id"], name: "index_procedures_on_draft_revision_id"
t.index ["hidden_at"], name: "index_procedures_on_hidden_at"
t.index ["libelle"], name: "index_procedures_on_libelle"
t.index ["parent_procedure_id"], name: "index_procedures_on_parent_procedure_id"
t.index ["path", "closed_at", "hidden_at", "unpublished_at"], name: "procedure_path_uniqueness", unique: true
t.index ["path", "closed_at", "hidden_at"], name: "index_procedures_on_path_and_closed_at_and_hidden_at", unique: true

View file

@ -151,6 +151,19 @@ describe Administrateurs::ProceduresController, type: :controller do
expect(assigns(:procedures)).not_to include(procedure3)
end
end
context 'with libelle search' do
let!(:procedure1) { create(:procedure, :published, libelle: 'Demande de subvention') }
let!(:procedure2) { create(:procedure, :published, libelle: "Fonds d'aide public « Prime Entrepreneurs des Quartiers »") }
let!(:procedure3) { create(:procedure, :published, libelle: "Hackaton pour entrepreneurs en résidence") }
it 'returns procedures with specific terms in libelle' do
get :all, params: { libelle: 'entrepreneur' }
expect(assigns(:procedures)).to include(procedure2)
expect(assigns(:procedures)).to include(procedure3)
expect(assigns(:procedures)).not_to include(procedure1)
end
end
end
describe 'GET #administrateurs' do