refactor(tdc): tdc.columns should take procedure instead of procedure_id

This commit is contained in:
Paul Chavard 2024-11-04 11:39:08 +01:00
parent 3ce36222b4
commit c0da8d1556
No known key found for this signature in database
9 changed files with 18 additions and 18 deletions

View file

@ -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}",

View file

@ -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

View file

@ -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

View file

@ -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)",

View file

@ -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),

View file

@ -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?

View file

@ -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),

View file

@ -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),

View file

@ -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