demarches-normaliennes/app/models/columns/linked_drop_down_column.rb

42 lines
778 B
Ruby
Raw Normal View History

2024-10-29 16:38:17 +01:00
# frozen_string_literal: true
class Columns::LinkedDropDownColumn < Column
def column
2024-10-30 15:43:47 +01:00
if value_column == :value
super
else
"#{@column}->#{value_column}" # override column otherwise json path facets will have same id as other
end
2024-10-29 16:38:17 +01:00
end
def filtered_ids(dossiers, values)
dossiers.with_type_de_champ(@column)
.filter_ilike(:champs, :value, values)
.ids
end
private
def get_raw_value(champ)
primary_value, secondary_value = unpack_values(champ.value)
case value_column
2024-10-30 15:43:47 +01:00
when :value
nil
2024-10-29 16:38:17 +01:00
when :primary
primary_value
when :secondary
secondary_value
end
end
def should_cast?
false
end
def unpack_values(value)
JSON.parse(value)
rescue JSON::ParserError
[]
end
end