From e2ace4f6bdd550e1972eb365ac0b8e7c50060aac Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 30 Oct 2024 14:28:23 +0100 Subject: [PATCH 1/3] chore: only create columns on fillable champs --- .../types_de_champ/type_de_champ_base.rb | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/app/models/types_de_champ/type_de_champ_base.rb b/app/models/types_de_champ/type_de_champ_base.rb index 8d15205d2..e4babe257 100644 --- a/app/models/types_de_champ/type_de_champ_base.rb +++ b/app/models/types_de_champ/type_de_champ_base.rb @@ -93,17 +93,21 @@ class TypesDeChamp::TypeDeChampBase end def columns(procedure_id:, displayable: true, prefix: nil) - [ - Column.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: - ) - ] + if fillable? + [ + Column.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: + ) + ] + else + [] + end end private From e9991573e722753912d301c83d476d4e9d211f58 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 30 Oct 2024 14:29:13 +0100 Subject: [PATCH 2/3] chore: columns on some champs at this point do not make sense --- app/models/types_de_champ/carte_type_de_champ.rb | 4 ++++ .../types_de_champ/piece_justificative_type_de_champ.rb | 4 ++++ spec/models/column_spec.rb | 3 ++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/models/types_de_champ/carte_type_de_champ.rb b/app/models/types_de_champ/carte_type_de_champ.rb index 9a16c6392..01cbd2a20 100644 --- a/app/models/types_de_champ/carte_type_de_champ.rb +++ b/app/models/types_de_champ/carte_type_de_champ.rb @@ -27,4 +27,8 @@ class TypesDeChamp::CarteTypeDeChamp < TypesDeChamp::TypeDeChampBase def champ_value_for_export(champ, path = :value) champ.geo_areas.map(&:label).join("\n") end + + def columns(procedure_id:, displayable: true, prefix: nil) + [] + end end diff --git a/app/models/types_de_champ/piece_justificative_type_de_champ.rb b/app/models/types_de_champ/piece_justificative_type_de_champ.rb index 6f00eec3a..2c68ef035 100644 --- a/app/models/types_de_champ/piece_justificative_type_de_champ.rb +++ b/app/models/types_de_champ/piece_justificative_type_de_champ.rb @@ -22,4 +22,8 @@ class TypesDeChamp::PieceJustificativeTypeDeChamp < TypesDeChamp::TypeDeChampBas attachment.url end end + + def columns(procedure_id:, displayable: true, prefix: nil) + [] + end end diff --git a/spec/models/column_spec.rb b/spec/models/column_spec.rb index 2d7652822..c1f1442dd 100644 --- a/spec/models/column_spec.rb +++ b/spec/models/column_spec.rb @@ -66,7 +66,8 @@ describe Column do expect_type_de_champ_values('linked_drop_down_list', [nil, "categorie 1", "choix 1"]) expect_type_de_champ_values('yes_no', [true]) expect_type_de_champ_values('annuaire_education', [nil]) - expect_type_de_champ_values('carte', [nil]) + expect_type_de_champ_values('carte', []) + expect_type_de_champ_values('piece_justificative', []) expect_type_de_champ_values('cnaf', [nil]) expect_type_de_champ_values('dgfip', [nil]) expect_type_de_champ_values('pole_emploi', [nil]) From 503da1d160a129e7929e7f5a776d9b4026bd9ef0 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 30 Oct 2024 15:43:47 +0100 Subject: [PATCH 3/3] chore: implement special columns --- app/models/column.rb | 2 -- app/models/columns/linked_drop_down_column.rb | 8 +++++++- app/models/columns/titre_identite_column.rb | 9 +++++++++ app/models/type_de_champ.rb | 16 ++++++++-------- .../linked_drop_down_list_type_de_champ.rb | 13 +++++++++++-- .../types_de_champ/repetition_type_de_champ.rb | 2 +- .../titre_identite_type_de_champ.rb | 15 +++++++++++++++ spec/models/column_spec.rb | 1 + 8 files changed, 52 insertions(+), 14 deletions(-) create mode 100644 app/models/columns/titre_identite_column.rb 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])