From e55cdfb683f1ca6853eeeb6ae0e56ddf469d996c Mon Sep 17 00:00:00 2001 From: Kara Diaby Date: Tue, 1 Oct 2024 11:19:03 +0200 Subject: [PATCH] =?UTF-8?q?Les=20admins=20ont=20la=20possibilit=C3=A9=20de?= =?UTF-8?q?=20filtrer=20les=20d=C3=A9marches=20par=20liste=20pr=C3=A9d?= =?UTF-8?q?=C3=A9finie=20dans=20la=20page=20toutes=20les=20d=C3=A9marches?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../administrateurs/procedures_controller.rb | 12 ++++++- app/views/layouts/all.html.haml | 31 +++++++++---------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/app/controllers/administrateurs/procedures_controller.rb b/app/controllers/administrateurs/procedures_controller.rb index 7ea8aed9b54..b923562c3d2 100644 --- a/app/controllers/administrateurs/procedures_controller.rb +++ b/app/controllers/administrateurs/procedures_controller.rb @@ -476,7 +476,17 @@ def filter_procedures(filter) procedures_result = procedures_result.where(procedures_zones: { zone_id: filter.zone_ids }) if filter.zone_ids.present? procedures_result = procedures_result.where(hidden_at_as_template: nil) procedures_result = procedures_result.where(aasm_state: filter.statuses) if filter.statuses.present? - procedures_result = procedures_result.where("tags @> ARRAY[?]::text[]", filter.tags) if filter.tags.present? + if filter.tags.present? + tag_id_mapping = ProcedureTag.where(name: filter.tags).pluck(:name, :id).to_h + tag_ids = filter.tags.map { |tag_name| tag_id_mapping[tag_name] }.compact + + if tag_ids.any? + procedures_result = procedures_result + .joins(:procedure_tags) + .where(procedure_tags: { id: tag_ids }) + .distinct + end + end procedures_result = procedures_result.where(template: true) if filter.template? 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? diff --git a/app/views/layouts/all.html.haml b/app/views/layouts/all.html.haml index 44d69dacf57..b7809a62bd5 100644 --- a/app/views/layouts/all.html.haml +++ b/app/views/layouts/all.html.haml @@ -25,6 +25,21 @@ %span.fr-icon-arrow-go-back-line Réinitialiser %ul + %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' } + Thématique + .fr-ml-1w.hidden{ 'data-expand-target': 'content' } + %div + = f.search_field :tags, placeholder: 'Choisissez un thème', list: 'tags_list', class: 'fr-input', data: { no_autosubmit: 'input', turbo_force: :server }, multiple: true + %datalist#tags_list + - ProcedureTag.order(:name).each do |tag| + %option{ value: tag.name, data: { id: tag.id } } + - if @filter.tags.present? + - @filter.tags.each do |tag| + = f.hidden_field :tags, value: tag, multiple: true, id: "tag-#{tag.tr(' ', '_')}" + %li.fr-py-2w.fr-pl-2w{ 'data-controller': "expand" } .fr-mb-1w %button{ 'data-action': 'expand#toggle' } @@ -105,22 +120,6 @@ = 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' } - Thématique - .fr-ml-1w.hidden{ 'data-expand-target': 'content' } - %div - = f.search_field :tags, placeholder: 'Choisissez un thème', list: 'tags_list', class: 'fr-input', data: { no_autosubmit: 'input', turbo_force: :server }, 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'