Possibilité de selectionner plusieurs tags dans la page toutes les demarches

This commit is contained in:
Kara Diaby 2023-03-02 00:04:30 +01:00
parent 2cb1b0c4ab
commit cb0417aad4
4 changed files with 15 additions and 10 deletions

View file

@ -413,7 +413,7 @@ module Administrateurs
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(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("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('unaccent(libelle) ILIKE unaccent(?)', "%#{filter.libelle}%") if filter.libelle.present?
procedures_sql = procedures_result.to_sql

View file

@ -5,7 +5,7 @@ class ProceduresFilter
def initialize(admin, params)
@admin = admin
@params = params.permit(:page, :libelle, :email, :from_publication_date, :tag, zone_ids: [], statuses: [])
@params = params.permit(:page, :libelle, :email, :from_publication_date, tags: [], zone_ids: [], statuses: [])
end
def admin_zones
@ -28,8 +28,8 @@ class ProceduresFilter
params[:statuses].compact_blank if params[:statuses].present?
end
def tag
params[:tag].presence
def tags
params[:tags].compact_blank.uniq if params[:tags].present?
end
def from_publication_date
@ -72,7 +72,7 @@ class ProceduresFilter
filters << email
filters << "from-#{from_publication_date}" if from_publication_date
filters << statuses
filters << tag
filters << tags
filters.compact.join('-')
end
end

View file

@ -5,6 +5,8 @@
= hidden_field_tag 'zone_ids[]', zone_id, id: "zone_#{zone_id}"
- @filter.statuses&.each do |status|
= hidden_field_tag 'statuses[]', status, id: "status_#{status}"
- @filter.tags&.each do|tag|
= hidden_field_tag 'tags[]', tag, id: "tag_#{tag}"
= 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'
@ -28,10 +30,11 @@
.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.tag.present?
- if @filter.tags.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'
- @filter.tags.each do |tag|
= link_to tag, all_admin_procedures_path(@filter.without(:tags, tag)), class: 'fr-tag fr-tag--dismiss fr-mb-1w'
- params[:tags].delete(tag)
- if @filter.from_publication_date.present?
.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'

View file

@ -71,11 +71,13 @@
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', turbo_force: true }
= f.search_field :tags, placeholder: 'Choisissez un tag', list: 'tags_list', class: 'fr-input', data: { no_autosubmit: 'input', turbo_force: true }, multiple: true
%datalist#tags_list
- Procedure.tags.each do |tag|
%option{ value: tag }
- if @filter.tags.present?
- @filter.tags.each do |tag|
= f.hidden_field :tags, value: tag, multiple: true, id: "tag-#{tag.tr(' ', '_')}"
.fr-col-9
= yield(:results)
= render template: 'layouts/application'