internalize value_column inside champ_column
This commit is contained in:
parent
9d976b8d95
commit
17531b73b7
7 changed files with 49 additions and 60 deletions
|
@ -8,15 +8,14 @@ class Column
|
|||
|
||||
TYPE_DE_CHAMP_TABLE = 'type_de_champ'
|
||||
|
||||
attr_reader :table, :column, :label, :type, :value_column, :filterable, :displayable, :options_for_select
|
||||
attr_reader :table, :column, :label, :type, :filterable, :displayable, :options_for_select
|
||||
|
||||
def initialize(procedure_id:, table:, column:, label: nil, type: :text, value_column: :value, filterable: true, displayable: true, options_for_select: [])
|
||||
def initialize(procedure_id:, table:, column:, label: nil, type: :text, filterable: true, displayable: true, options_for_select: [])
|
||||
@procedure_id = procedure_id
|
||||
@table = table
|
||||
@column = column
|
||||
@label = label || I18n.t(column, scope: [:activerecord, :attributes, :procedure_presentation, :fields, table])
|
||||
@type = type
|
||||
@value_column = value_column
|
||||
@filterable = filterable
|
||||
@displayable = displayable
|
||||
@options_for_select = options_for_select
|
||||
|
@ -33,7 +32,7 @@ class Column
|
|||
|
||||
def to_json
|
||||
{
|
||||
table:, column:, label:, type:, value_column:, filterable:, displayable:
|
||||
table:, column:, label:, type:, filterable:, displayable:
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
class Columns::ChampColumn < Column
|
||||
attr_reader :stable_id
|
||||
|
||||
def initialize(procedure_id:, label:, stable_id:, tdc_type:, displayable: true, filterable: true, type: :text, value_column: :value, options_for_select: [])
|
||||
def initialize(procedure_id:, label:, stable_id:, tdc_type:, displayable: true, filterable: true, type: :text, options_for_select: [])
|
||||
@stable_id = stable_id
|
||||
@tdc_type = tdc_type
|
||||
|
||||
|
@ -13,7 +13,6 @@ class Columns::ChampColumn < Column
|
|||
column: stable_id.to_s,
|
||||
label:,
|
||||
type:,
|
||||
value_column:,
|
||||
displayable:,
|
||||
filterable:,
|
||||
options_for_select:
|
||||
|
@ -48,6 +47,8 @@ class Columns::ChampColumn < Column
|
|||
|
||||
def column_id = "type_de_champ/#{stable_id}"
|
||||
|
||||
def value_column = @tdc_type.in?(['departements', 'regions']) ? :external_id : :value
|
||||
|
||||
def string_value(champ) = champ.public_send(value_column)
|
||||
|
||||
def typed_value(champ)
|
||||
|
|
|
@ -545,14 +545,6 @@ class TypeDeChamp < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def self.value_column(type_champ)
|
||||
if type_champ.in?([type_champs.fetch(:departements), type_champs.fetch(:regions)])
|
||||
:external_id
|
||||
else
|
||||
:value
|
||||
end
|
||||
end
|
||||
|
||||
def options_for_select
|
||||
if departement?
|
||||
APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }.sort
|
||||
|
|
|
@ -33,7 +33,6 @@ class TypesDeChamp::PieceJustificativeTypeDeChamp < TypesDeChamp::TypeDeChampBas
|
|||
tdc_type: type_champ,
|
||||
label: libelle_with_prefix(prefix),
|
||||
type: TypeDeChamp.column_type(type_champ),
|
||||
value_column: TypeDeChamp.value_column(type_champ),
|
||||
displayable: false,
|
||||
filterable: false
|
||||
)
|
||||
|
|
|
@ -32,7 +32,6 @@ class TypesDeChamp::TitreIdentiteTypeDeChamp < TypesDeChamp::TypeDeChampBase
|
|||
tdc_type: type_champ,
|
||||
label: libelle_with_prefix(prefix),
|
||||
type: TypeDeChamp.column_type(type_champ),
|
||||
value_column: TypeDeChamp.value_column(type_champ),
|
||||
displayable: false,
|
||||
filterable: false
|
||||
)
|
||||
|
|
|
@ -104,7 +104,6 @@ class TypesDeChamp::TypeDeChampBase
|
|||
tdc_type: type_champ,
|
||||
label: libelle_with_prefix(prefix),
|
||||
type: TypeDeChamp.column_type(type_champ),
|
||||
value_column: TypeDeChamp.value_column(type_champ),
|
||||
displayable:,
|
||||
options_for_select:
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue