use path instead of value_column in linked_drop_down
This commit is contained in:
parent
de8cad888e
commit
74e6834ce2
3 changed files with 13 additions and 10 deletions
|
@ -1,14 +1,17 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Columns::LinkedDropDownColumn < Columns::ChampColumn
|
class Columns::LinkedDropDownColumn < Columns::ChampColumn
|
||||||
def initialize(procedure_id:, label:, stable_id:, value_column:, displayable:, type: :text)
|
attr_reader :path
|
||||||
|
|
||||||
|
def initialize(procedure_id:, label:, stable_id:, path:, displayable:, type: :text)
|
||||||
|
@path = path
|
||||||
|
|
||||||
super(
|
super(
|
||||||
procedure_id:,
|
procedure_id:,
|
||||||
label:,
|
label:,
|
||||||
stable_id:,
|
stable_id:,
|
||||||
displayable:,
|
displayable:,
|
||||||
type:,
|
type:
|
||||||
value_column:
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -21,7 +24,7 @@ class Columns::LinkedDropDownColumn < Columns::ChampColumn
|
||||||
private
|
private
|
||||||
|
|
||||||
def column_id
|
def column_id
|
||||||
if value_column == :value
|
if path == :value
|
||||||
"type_de_champ/#{stable_id}"
|
"type_de_champ/#{stable_id}"
|
||||||
else
|
else
|
||||||
"type_de_champ/#{stable_id}->#{path}"
|
"type_de_champ/#{stable_id}->#{path}"
|
||||||
|
@ -29,10 +32,10 @@ class Columns::LinkedDropDownColumn < Columns::ChampColumn
|
||||||
end
|
end
|
||||||
|
|
||||||
def typed_value(champ)
|
def typed_value(champ)
|
||||||
return nil if default_column?
|
return nil if path == :value
|
||||||
|
|
||||||
primary_value, secondary_value = unpack_values(champ.value)
|
primary_value, secondary_value = unpack_values(champ.value)
|
||||||
case value_column
|
case path
|
||||||
when :primary
|
when :primary
|
||||||
primary_value
|
primary_value
|
||||||
when :secondary
|
when :secondary
|
||||||
|
|
|
@ -561,7 +561,7 @@ class TypeDeChamp < ApplicationRecord
|
||||||
elsif region?
|
elsif region?
|
||||||
APIGeoService.regions.map { [_1[:name], _1[:code]] }
|
APIGeoService.regions.map { [_1[:name], _1[:code]] }
|
||||||
elsif linked_drop_down_list?
|
elsif linked_drop_down_list?
|
||||||
if column.value_column == :primary
|
if column.path == :primary
|
||||||
primary_options
|
primary_options
|
||||||
else
|
else
|
||||||
secondary_options.values.flatten
|
secondary_options.values.flatten
|
||||||
|
|
|
@ -78,7 +78,7 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas
|
||||||
label: libelle_with_prefix(prefix),
|
label: libelle_with_prefix(prefix),
|
||||||
stable_id: stable_id,
|
stable_id: stable_id,
|
||||||
type: :text,
|
type: :text,
|
||||||
value_column: :value,
|
path: :value,
|
||||||
displayable:
|
displayable:
|
||||||
),
|
),
|
||||||
Columns::LinkedDropDownColumn.new(
|
Columns::LinkedDropDownColumn.new(
|
||||||
|
@ -86,7 +86,7 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas
|
||||||
stable_id:,
|
stable_id:,
|
||||||
label: "#{libelle_with_prefix(prefix)} (Primaire)",
|
label: "#{libelle_with_prefix(prefix)} (Primaire)",
|
||||||
type: :enum,
|
type: :enum,
|
||||||
value_column: :primary,
|
path: :primary,
|
||||||
displayable: false
|
displayable: false
|
||||||
),
|
),
|
||||||
Columns::LinkedDropDownColumn.new(
|
Columns::LinkedDropDownColumn.new(
|
||||||
|
@ -94,7 +94,7 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas
|
||||||
stable_id:,
|
stable_id:,
|
||||||
label: "#{libelle_with_prefix(prefix)} (Secondaire)",
|
label: "#{libelle_with_prefix(prefix)} (Secondaire)",
|
||||||
type: :enum,
|
type: :enum,
|
||||||
value_column: :secondary,
|
path: :secondary,
|
||||||
displayable: false
|
displayable: false
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue