you know what ? value_column is a column

This commit is contained in:
simon lehericey 2024-11-06 22:26:24 +01:00
parent 8599dd829a
commit aa8ce15c2a
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
2 changed files with 8 additions and 8 deletions

View file

@ -6,11 +6,12 @@ class Columns::ChampColumn < Column
def initialize(procedure_id:, label:, stable_id:, tdc_type:, displayable: true, filterable: true, type: :text, options_for_select: []) def initialize(procedure_id:, label:, stable_id:, tdc_type:, displayable: true, filterable: true, type: :text, options_for_select: [])
@stable_id = stable_id @stable_id = stable_id
@tdc_type = tdc_type @tdc_type = tdc_type
column = tdc_type.in?(['departements', 'regions']) ? :external_id : :value
super( super(
procedure_id:, procedure_id:,
table: 'type_de_champ', table: 'type_de_champ',
column: stable_id.to_s, column:,
label:, label:,
type:, type:,
displayable:, displayable:,
@ -33,13 +34,13 @@ class Columns::ChampColumn < Column
def filtered_ids(dossiers, search_terms) def filtered_ids(dossiers, search_terms)
if type == :enum if type == :enum
dossiers.with_type_de_champ(stable_id) dossiers.with_type_de_champ(stable_id)
.filter_enum(:champs, value_column, search_terms).ids .filter_enum(:champs, column, search_terms).ids
elsif type == :enums elsif type == :enums
dossiers.with_type_de_champ(stable_id) dossiers.with_type_de_champ(stable_id)
.filter_array_enum(:champs, value_column, search_terms).ids .filter_array_enum(:champs, column, search_terms).ids
else else
dossiers.with_type_de_champ(stable_id) dossiers.with_type_de_champ(stable_id)
.filter_ilike(:champs, value_column, search_terms).ids .filter_ilike(:champs, column, search_terms).ids
end end
end end
@ -47,9 +48,7 @@ class Columns::ChampColumn < Column
def column_id = "type_de_champ/#{stable_id}" def column_id = "type_de_champ/#{stable_id}"
def value_column = @tdc_type.in?(['departements', 'regions']) ? :external_id : :value def string_value(champ) = champ.public_send(column)
def string_value(champ) = champ.public_send(value_column)
def typed_value(champ) def typed_value(champ)
value = string_value(champ) value = string_value(champ)

View file

@ -32,8 +32,9 @@ class DossierFilterService
dossiers_id_with_notification dossiers_id_with_notification
end end
when TYPE_DE_CHAMP when TYPE_DE_CHAMP
stable_id = sorted_column.column.stable_id
ids = dossiers ids = dossiers
.with_type_de_champ(column) .with_type_de_champ(stable_id)
.order("champs.value #{order}") .order("champs.value #{order}")
.pluck(:id) .pluck(:id)
if ids.size != count if ids.size != count