From c0da8d1556e95943d06df5573528202540d1771b Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Mon, 4 Nov 2024 11:39:08 +0100 Subject: [PATCH] refactor(tdc): tdc.columns should take procedure instead of procedure_id --- app/models/concerns/addressable_column_concern.rb | 4 ++-- app/models/concerns/columns_concern.rb | 2 +- app/models/types_de_champ/carte_type_de_champ.rb | 2 +- .../types_de_champ/linked_drop_down_list_type_de_champ.rb | 8 ++++---- .../types_de_champ/piece_justificative_type_de_champ.rb | 4 ++-- app/models/types_de_champ/repetition_type_de_champ.rb | 6 +++--- app/models/types_de_champ/titre_identite_type_de_champ.rb | 4 ++-- app/models/types_de_champ/type_de_champ_base.rb | 4 ++-- spec/models/columns/champ_column_spec.rb | 2 +- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/app/models/concerns/addressable_column_concern.rb b/app/models/concerns/addressable_column_concern.rb index 4f10b62b5..e7ba4d11e 100644 --- a/app/models/concerns/addressable_column_concern.rb +++ b/app/models/concerns/addressable_column_concern.rb @@ -4,7 +4,7 @@ module AddressableColumnConcern extend ActiveSupport::Concern included do - def columns(procedure_id:, displayable: true, prefix: nil) + def columns(procedure:, displayable: true, prefix: nil) super.concat([ ["code postal (5 chiffres)", '$.postal_code', :text], ["commune", '$.city_name', :text], @@ -12,7 +12,7 @@ module AddressableColumnConcern ["region", '$.region_name', :enum] ].map do |(label, jsonpath, type)| Columns::JSONPathColumn.new( - procedure_id:, + procedure_id: procedure.id, stable_id:, tdc_type: type_champ, label: "#{libelle_with_prefix(prefix)} – #{label}", diff --git a/app/models/concerns/columns_concern.rb b/app/models/concerns/columns_concern.rb index c30074c68..e01173412 100644 --- a/app/models/concerns/columns_concern.rb +++ b/app/models/concerns/columns_concern.rb @@ -154,7 +154,7 @@ module ColumnsConcern end def types_de_champ_columns - all_revisions_types_de_champ.flat_map { _1.columns(procedure_id: id) } + all_revisions_types_de_champ.flat_map { _1.columns(procedure: self) } end end end 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 5903c5a2c..fb7822353 100644 --- a/app/models/types_de_champ/carte_type_de_champ.rb +++ b/app/models/types_de_champ/carte_type_de_champ.rb @@ -30,7 +30,7 @@ class TypesDeChamp::CarteTypeDeChamp < TypesDeChamp::TypeDeChampBase def champ_blank?(champ) = champ.geo_areas.blank? - def columns(procedure_id:, displayable: true, prefix: nil) + def columns(procedure:, displayable: true, prefix: nil) [] end end 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 cee354c02..c6396be6b 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 @@ -71,10 +71,10 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas (has_secondary_options_for_primary?(champ) && secondary_value(champ).blank?) end - def columns(procedure_id:, displayable: true, prefix: nil) + def columns(procedure:, displayable: true, prefix: nil) [ Columns::LinkedDropDownColumn.new( - procedure_id:, + procedure_id: procedure.id, label: libelle_with_prefix(prefix), stable_id:, tdc_type: type_champ, @@ -83,7 +83,7 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas displayable: ), Columns::LinkedDropDownColumn.new( - procedure_id:, + procedure_id: procedure.id, stable_id:, tdc_type: type_champ, label: "#{libelle_with_prefix(prefix)} (Primaire)", @@ -92,7 +92,7 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas displayable: false ), Columns::LinkedDropDownColumn.new( - procedure_id:, + procedure_id: procedure.id, stable_id:, tdc_type: type_champ, label: "#{libelle_with_prefix(prefix)} (Secondaire)", 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 cb65fb132..dbebe11f9 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 @@ -25,10 +25,10 @@ class TypesDeChamp::PieceJustificativeTypeDeChamp < TypesDeChamp::TypeDeChampBas def champ_blank?(champ) = champ.piece_justificative_file.blank? - def columns(procedure_id:, displayable: true, prefix: nil) + def columns(procedure:, displayable: true, prefix: nil) [ Columns::AttachedManyColumn.new( - procedure_id:, + procedure_id: procedure.id, stable_id:, tdc_type: type_champ, label: libelle_with_prefix(prefix), 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 28db1512d..043294933 100644 --- a/app/models/types_de_champ/repetition_type_de_champ.rb +++ b/app/models/types_de_champ/repetition_type_de_champ.rb @@ -25,10 +25,10 @@ class TypesDeChamp::RepetitionTypeDeChamp < TypesDeChamp::TypeDeChampBase ActiveStorage::Filename.new(str.delete('[]*?')).sanitized end - def columns(procedure_id:, displayable: nil, prefix: nil) - @type_de_champ.procedure + def columns(procedure:, displayable: nil, prefix: nil) + procedure .all_revisions_types_de_champ(parent: @type_de_champ) - .flat_map { _1.columns(procedure_id:, displayable: false, prefix: libelle) } + .flat_map { _1.columns(procedure:, displayable: false, prefix: libelle) } end def champ_blank?(champ) = champ.dossier.repetition_row_ids(@type_de_champ).blank? 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 9938808de..e72944c15 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 @@ -24,10 +24,10 @@ class TypesDeChamp::TitreIdentiteTypeDeChamp < TypesDeChamp::TypeDeChampBase def champ_blank?(champ) = champ.piece_justificative_file.blank? - def columns(procedure_id:, displayable: nil, prefix: nil) + def columns(procedure:, displayable: nil, prefix: nil) [ Columns::AttachedManyColumn.new( - procedure_id:, + procedure_id: procedure.id, stable_id:, tdc_type: type_champ, label: libelle_with_prefix(prefix), 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 2c81fc430..fb3549f94 100644 --- a/app/models/types_de_champ/type_de_champ_base.rb +++ b/app/models/types_de_champ/type_de_champ_base.rb @@ -95,11 +95,11 @@ class TypesDeChamp::TypeDeChampBase def champ_blank?(champ) = champ.value.blank? def champ_blank_or_invalid?(champ) = champ_blank?(champ) - def columns(procedure_id:, displayable: true, prefix: nil) + def columns(procedure:, displayable: true, prefix: nil) if fillable? [ Columns::ChampColumn.new( - procedure_id:, + procedure_id: procedure.id, stable_id:, tdc_type: type_champ, label: libelle_with_prefix(prefix), diff --git a/spec/models/columns/champ_column_spec.rb b/spec/models/columns/champ_column_spec.rb index 0cbf1da91..f197af3cd 100644 --- a/spec/models/columns/champ_column_spec.rb +++ b/spec/models/columns/champ_column_spec.rb @@ -122,7 +122,7 @@ describe Columns::ChampColumn do def expect_type_de_champ_values(type, assertion) type_de_champ = types_de_champ.find { _1.type_champ == type } champ = dossier.send(:filled_champ, type_de_champ, nil) - columns = type_de_champ.columns(procedure_id: procedure.id) + columns = type_de_champ.columns(procedure:) expect(columns.map { _1.value(champ) }).to assertion end