2024-10-29 16:38:17 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-10-31 18:34:30 +01:00
|
|
|
class Columns::LinkedDropDownColumn < Columns::ChampColumn
|
2024-11-03 22:07:38 +01:00
|
|
|
attr_reader :path
|
|
|
|
|
2024-11-04 16:34:00 +01:00
|
|
|
def initialize(procedure_id:, label:, stable_id:, tdc_type:, path:, displayable:, type: :text)
|
2024-11-03 22:07:38 +01:00
|
|
|
@path = path
|
|
|
|
|
2024-10-31 18:34:30 +01:00
|
|
|
super(
|
|
|
|
procedure_id:,
|
|
|
|
label:,
|
|
|
|
stable_id:,
|
2024-11-04 16:34:00 +01:00
|
|
|
tdc_type:,
|
2024-10-31 18:34:30 +01:00
|
|
|
displayable:,
|
2024-11-03 22:07:38 +01:00
|
|
|
type:
|
2024-10-31 18:34:30 +01:00
|
|
|
)
|
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
|
|
|
|
|
2024-11-04 08:26:57 +01:00
|
|
|
def column_id = "type_de_champ/#{stable_id}->#{path}"
|
2024-10-31 18:34:30 +01:00
|
|
|
|
2024-10-31 21:36:13 +01:00
|
|
|
def typed_value(champ)
|
2024-11-03 22:07:38 +01:00
|
|
|
return nil if path == :value
|
2024-10-31 21:36:13 +01:00
|
|
|
|
2024-10-29 16:38:17 +01:00
|
|
|
primary_value, secondary_value = unpack_values(champ.value)
|
2024-11-03 22:07:38 +01:00
|
|
|
case path
|
2024-10-29 16:38:17 +01:00
|
|
|
when :primary
|
|
|
|
primary_value
|
|
|
|
when :secondary
|
|
|
|
secondary_value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def unpack_values(value)
|
|
|
|
JSON.parse(value)
|
|
|
|
rescue JSON::ParserError
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
end
|