Merge pull request #8392 from demarches-simplifiees/feat/8065

ETQ Administrateur, je souhaite filtrer mes démarches par tag
This commit is contained in:
Kara Diaby 2023-01-18 18:54:35 +01:00 committed by GitHub
commit d986c998b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 1 deletions

View file

@ -369,6 +369,7 @@ module Administrateurs
procedures_result = Procedure.select(:id).joins(:procedures_zones).distinct.publiees_ou_closes procedures_result = Procedure.select(:id).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(aasm_state: filter.statuses) if filter.statuses.present? procedures_result = procedures_result.where(aasm_state: filter.statuses) if filter.statuses.present?
procedures_result = procedures_result.where("? = ANY(tags)", filter.tag) if filter.tag.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('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

View file

@ -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, zone_ids: [], statuses: []) @params = params.permit(:page, :libelle, :email, :from_publication_date, :tag, zone_ids: [], statuses: [])
end end
def admin_zones def admin_zones
@ -28,6 +28,10 @@ class ProceduresFilter
params[:statuses].compact_blank if params[:statuses].present? params[:statuses].compact_blank if params[:statuses].present?
end end
def tag
params[:tag].presence
end
def from_publication_date def from_publication_date
return if params[:from_publication_date].blank? return if params[:from_publication_date].blank?
@ -68,6 +72,7 @@ class ProceduresFilter
filters << email filters << email
filters << "from-#{from_publication_date}" if from_publication_date filters << "from-#{from_publication_date}" if from_publication_date
filters << statuses filters << statuses
filters << tag
filters.compact.join('-') filters.compact.join('-')
end end
end end

View file

@ -28,6 +28,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.tag.present?
.selected-tag.fr-mb-2w
= link_to @filter.tag, all_admin_procedures_path(@filter.without(:tag)), class: 'fr-tag fr-tag--dismiss fr-mb-1w'
- if @filter.from_publication_date.present? - if @filter.from_publication_date.present?
.selected-from-publication-date.fr-mb-2w .selected-from-publication-date.fr-mb-2w
= link_to "Depuis #{l(@filter.from_publication_date)}", all_admin_procedures_path(@filter.without(:from_publication_date)), class: 'fr-tag fr-tag--dismiss fr-mb-1w' = link_to "Depuis #{l(@filter.from_publication_date)}", all_admin_procedures_path(@filter.without(:from_publication_date)), class: 'fr-tag fr-tag--dismiss fr-mb-1w'

View file

@ -64,6 +64,18 @@
= 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' }
Tags
.fr-ml-1w.hidden{ 'data-expand-target': 'content' }
%div
= f.search_field :tag, placeholder: 'Choisissez un tag', list: 'tags_list', class: 'fr-input', data: { no_autosubmit: 'input' }
%datalist#tags_list
- Procedure.tags.each do |tag|
%option{ value: tag }
%turbo-frame#procedures.fr-col-9{ 'data-turbo-action': 'advance' } %turbo-frame#procedures.fr-col-9{ 'data-turbo-action': 'advance' }
= yield(:results) = yield(:results)
= render template: 'layouts/application' = render template: 'layouts/application'

View file

@ -162,6 +162,15 @@ describe Administrateurs::ProceduresController, type: :controller do
end end
end end
context 'with specific tag' do
let!(:tag_procedure) { create(:procedure, :published, tags: ['environnement']) }
it 'returns procedures with specific tag' do
get :all, params: { tag: 'environnement' }
expect(assigns(:procedures).any? { |p| p.id == tag_procedure.id }).to be_truthy
end
end
context 'with libelle search' do context 'with libelle search' do
let!(:procedure1) { create(:procedure, :published, libelle: 'Demande de subvention') } let!(:procedure1) { create(:procedure, :published, libelle: 'Demande de subvention') }
let!(:procedure2) { create(:procedure, :published, libelle: "Fonds d'aide public « Prime Entrepreneurs des Quartiers »") } let!(:procedure2) { create(:procedure, :published, libelle: "Fonds d'aide public « Prime Entrepreneurs des Quartiers »") }