chore: implement special columns

This commit is contained in:
Paul Chavard 2024-10-30 15:43:47 +01:00
parent e9991573e7
commit 503da1d160
No known key found for this signature in database
8 changed files with 52 additions and 14 deletions

View file

@ -57,8 +57,6 @@ class Column
value = get_raw_value(champ)
if should_cast?
# FIXME: remove this, once displayable is implemented through columns
return nil if champ.last_write_type_champ == TypeDeChamp.type_champs.fetch(:linked_drop_down_list)
from_type = champ.last_write_column_type
to_type = type
parsed_value = parse_value(value, from_type)

View file

@ -2,7 +2,11 @@
class Columns::LinkedDropDownColumn < Column
def column
"#{@column}->#{value_column}" # override column otherwise json path facets will have same id as other
if value_column == :value
super
else
"#{@column}->#{value_column}" # override column otherwise json path facets will have same id as other
end
end
def filtered_ids(dossiers, values)
@ -16,6 +20,8 @@ class Columns::LinkedDropDownColumn < Column
def get_raw_value(champ)
primary_value, secondary_value = unpack_values(champ.value)
case value_column
when :value
nil
when :primary
primary_value
when :secondary

View file

@ -0,0 +1,9 @@
# frozen_string_literal: true
class Columns::TitreIdentiteColumn < Column
private
def get_raw_value(champ)
champ.piece_justificative_file.attached?.to_s
end
end

View file

@ -528,19 +528,19 @@ class TypeDeChamp < ApplicationRecord
def self.column_type(type_champ)
case type_champ
when TypeDeChamp.type_champs.fetch(:datetime)
when type_champs.fetch(:datetime)
:datetime
when TypeDeChamp.type_champs.fetch(:date)
when type_champs.fetch(:date)
:date
when TypeDeChamp.type_champs.fetch(:integer_number)
when type_champs.fetch(:integer_number)
:integer
when TypeDeChamp.type_champs.fetch(:decimal_number)
when type_champs.fetch(:decimal_number)
:decimal
when TypeDeChamp.type_champs.fetch(:multiple_drop_down_list)
when type_champs.fetch(:multiple_drop_down_list)
:enums
when TypeDeChamp.type_champs.fetch(:drop_down_list), TypeDeChamp.type_champs.fetch(:departements), TypeDeChamp.type_champs.fetch(:regions)
when type_champs.fetch(:drop_down_list), type_champs.fetch(:departements), type_champs.fetch(:regions)
:enum
when TypeDeChamp.type_champs.fetch(:checkbox), TypeDeChamp.type_champs.fetch(:yes_no)
when type_champs.fetch(:checkbox), type_champs.fetch(:yes_no), type_champs.fetch(:titre_identite)
:boolean
else
:text
@ -548,7 +548,7 @@ class TypeDeChamp < ApplicationRecord
end
def self.value_column(type_champ)
if type_champ.in?([TypeDeChamp.type_champs.fetch(:departements), TypeDeChamp.type_champs.fetch(:regions)])
if type_champ.in?([type_champs.fetch(:departements), type_champs.fetch(:regions)])
:external_id
else
:value

View file

@ -68,7 +68,16 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas
end
def columns(procedure_id:, displayable: true, prefix: nil)
super.concat([
[
Columns::LinkedDropDownColumn.new(
procedure_id:,
table: Column::TYPE_DE_CHAMP_TABLE,
column: stable_id.to_s,
label: libelle_with_prefix(prefix),
type: :text,
value_column: :value,
displayable:
),
Columns::LinkedDropDownColumn.new(
procedure_id:,
table: Column::TYPE_DE_CHAMP_TABLE,
@ -87,7 +96,7 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas
value_column: :secondary,
displayable: false
)
])
]
end
private

View file

@ -27,7 +27,7 @@ class TypesDeChamp::RepetitionTypeDeChamp < TypesDeChamp::TypeDeChampBase
ActiveStorage::Filename.new(str.delete('[]*?')).sanitized
end
def columns(procedure_id:, displayable: true, prefix: nil)
def columns(procedure_id:, displayable: nil, prefix: nil)
@type_de_champ.procedure
.all_revisions_types_de_champ(parent: @type_de_champ)
.flat_map { _1.columns(procedure_id:, displayable: false, prefix: libelle) }

View file

@ -21,4 +21,19 @@ class TypesDeChamp::TitreIdentiteTypeDeChamp < TypesDeChamp::TypeDeChampBase
def champ_default_export_value(path = :value)
"absent"
end
def columns(procedure_id:, displayable: nil, prefix: nil)
[
Columns::TitreIdentiteColumn.new(
procedure_id:,
table: Column::TYPE_DE_CHAMP_TABLE,
column: stable_id.to_s,
label: libelle_with_prefix(prefix),
type: TypeDeChamp.column_type(type_champ),
value_column: TypeDeChamp.value_column(type_champ),
displayable: false,
filterable: false
)
]
end
end

View file

@ -68,6 +68,7 @@ describe Column do
expect_type_de_champ_values('annuaire_education', [nil])
expect_type_de_champ_values('carte', [])
expect_type_de_champ_values('piece_justificative', [])
expect_type_de_champ_values('titre_identite', [true])
expect_type_de_champ_values('cnaf', [nil])
expect_type_de_champ_values('dgfip', [nil])
expect_type_de_champ_values('pole_emploi', [nil])