Skip to content

Commit

Permalink
Les admins ont la possibilité de filtrer les démarches par liste préd…
Browse files Browse the repository at this point in the history
…éfinie dans la page toutes les démarches
  • Loading branch information
kara22 committed Oct 1, 2024
1 parent 6ccdc60 commit e55cdfb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
12 changes: 11 additions & 1 deletion app/controllers/administrateurs/procedures_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 481 in app/controllers/administrateurs/procedures_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/administrateurs/procedures_controller.rb#L481

Added line #L481 was not covered by tests

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?
Expand Down
31 changes: 15 additions & 16 deletions app/views/layouts/all.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down Expand Up @@ -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'

0 comments on commit e55cdfb

Please sign in to comment.