Merge pull request #10997 from tchak/only-create-fillable-columns
ETQ dev, je ne veux pas de colonnes sur les champs où ça n'a pas de sens
This commit is contained in:
commit
af33e6a0e9
11 changed files with 77 additions and 26 deletions
|
@ -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)
|
||||
|
|
|
@ -2,8 +2,12 @@
|
|||
|
||||
class Columns::LinkedDropDownColumn < Column
|
||||
def column
|
||||
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)
|
||||
dossiers.with_type_de_champ(@column)
|
||||
|
@ -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
|
||||
|
|
9
app/models/columns/titre_identite_column.rb
Normal file
9
app/models/columns/titre_identite_column.rb
Normal 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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -22,4 +22,8 @@ class TypesDeChamp::PieceJustificativeTypeDeChamp < TypesDeChamp::TypeDeChampBas
|
|||
attachment.url
|
||||
end
|
||||
end
|
||||
|
||||
def columns(procedure_id:, displayable: true, prefix: nil)
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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) }
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -93,6 +93,7 @@ class TypesDeChamp::TypeDeChampBase
|
|||
end
|
||||
|
||||
def columns(procedure_id:, displayable: true, prefix: nil)
|
||||
if fillable?
|
||||
[
|
||||
Column.new(
|
||||
procedure_id:,
|
||||
|
@ -104,6 +105,9 @@ class TypesDeChamp::TypeDeChampBase
|
|||
displayable:
|
||||
)
|
||||
]
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -66,7 +66,9 @@ 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('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])
|
||||
|
|
Loading…
Reference in a new issue