diff --git a/app/models/column.rb b/app/models/column.rb index 94f9295f8..198aada85 100644 --- a/app/models/column.rb +++ b/app/models/column.rb @@ -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) diff --git a/app/models/columns/linked_drop_down_column.rb b/app/models/columns/linked_drop_down_column.rb index dfa7efe66..396dcb8cd 100644 --- a/app/models/columns/linked_drop_down_column.rb +++ b/app/models/columns/linked_drop_down_column.rb @@ -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 diff --git a/app/models/columns/titre_identite_column.rb b/app/models/columns/titre_identite_column.rb new file mode 100644 index 000000000..3141df1d8 --- /dev/null +++ b/app/models/columns/titre_identite_column.rb @@ -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 diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 9d82f64b5..79bfa7088 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -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 diff --git a/app/models/types_de_champ/linked_drop_down_list_type_de_champ.rb b/app/models/types_de_champ/linked_drop_down_list_type_de_champ.rb index 103922861..44333e0b2 100644 --- a/app/models/types_de_champ/linked_drop_down_list_type_de_champ.rb +++ b/app/models/types_de_champ/linked_drop_down_list_type_de_champ.rb @@ -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 diff --git a/app/models/types_de_champ/repetition_type_de_champ.rb b/app/models/types_de_champ/repetition_type_de_champ.rb index e281c0abf..b1325472f 100644 --- a/app/models/types_de_champ/repetition_type_de_champ.rb +++ b/app/models/types_de_champ/repetition_type_de_champ.rb @@ -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) } diff --git a/app/models/types_de_champ/titre_identite_type_de_champ.rb b/app/models/types_de_champ/titre_identite_type_de_champ.rb index 7a10280c5..617603c10 100644 --- a/app/models/types_de_champ/titre_identite_type_de_champ.rb +++ b/app/models/types_de_champ/titre_identite_type_de_champ.rb @@ -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 diff --git a/spec/models/column_spec.rb b/spec/models/column_spec.rb index c1f1442dd..f91798d7a 100644 --- a/spec/models/column_spec.rb +++ b/spec/models/column_spec.rb @@ -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])