From 9d976b8d95ebe5a1f94325f0aa854ad38cd3ce14 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Wed, 6 Nov 2024 21:53:47 +0100 Subject: [PATCH] move filtering logic inside champ_column --- app/models/columns/champ_column.rb | 13 +++++++++++++ app/services/dossier_filter_service.rb | 12 ------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/models/columns/champ_column.rb b/app/models/columns/champ_column.rb index 4db5e298c..6ff99ff13 100644 --- a/app/models/columns/champ_column.rb +++ b/app/models/columns/champ_column.rb @@ -31,6 +31,19 @@ class Columns::ChampColumn < Column end end + def filtered_ids(dossiers, search_terms) + if type == :enum + dossiers.with_type_de_champ(stable_id) + .filter_enum(:champs, value_column, search_terms).ids + elsif type == :enums + dossiers.with_type_de_champ(stable_id) + .filter_array_enum(:champs, value_column, search_terms).ids + else + dossiers.with_type_de_champ(stable_id) + .filter_ilike(:champs, value_column, search_terms).ids + end + end + private def column_id = "type_de_champ/#{stable_id}" diff --git a/app/services/dossier_filter_service.rb b/app/services/dossier_filter_service.rb index 982675ade..88922bea9 100644 --- a/app/services/dossier_filter_service.rb +++ b/app/services/dossier_filter_service.rb @@ -74,7 +74,6 @@ class DossierFilterService .map do |(table, column), filters_for_column| values = filters_for_column.map(&:filter) filtered_column = filters_for_column.first.column - value_column = filtered_column.value_column if filtered_column.respond_to?(:filtered_ids) filtered_column.filtered_ids(dossiers, values) @@ -93,17 +92,6 @@ class DossierFilterService else dossiers.where("dossiers.#{column} IN (?)", values) end - when TYPE_DE_CHAMP - if filtered_column.type == :enum - dossiers.with_type_de_champ(column) - .filter_enum(:champs, value_column, values) - elsif filtered_column.type == :enums - dossiers.with_type_de_champ(column) - .filter_array_enum(:champs, value_column, values) - else - dossiers.with_type_de_champ(column) - .filter_ilike(:champs, value_column, values) - end when 'etablissement' if column == 'entreprise_date_creation' dates = values