inject options_for_select for json_column
This commit is contained in:
parent
49d3661441
commit
db2e4cf802
3 changed files with 18 additions and 23 deletions
|
@ -3,7 +3,7 @@
|
||||||
class Columns::JSONPathColumn < Columns::ChampColumn
|
class Columns::JSONPathColumn < Columns::ChampColumn
|
||||||
attr_reader :jsonpath
|
attr_reader :jsonpath
|
||||||
|
|
||||||
def initialize(procedure_id:, label:, stable_id:, tdc_type:, jsonpath:, displayable:, type: :text)
|
def initialize(procedure_id:, label:, stable_id:, tdc_type:, jsonpath:, options_for_select: [], displayable:, type: :text)
|
||||||
@jsonpath = quote_string(jsonpath)
|
@jsonpath = quote_string(jsonpath)
|
||||||
|
|
||||||
super(
|
super(
|
||||||
|
@ -12,7 +12,8 @@ class Columns::JSONPathColumn < Columns::ChampColumn
|
||||||
stable_id:,
|
stable_id:,
|
||||||
tdc_type:,
|
tdc_type:,
|
||||||
displayable:,
|
displayable:,
|
||||||
type:
|
type:,
|
||||||
|
options_for_select:
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -26,17 +27,6 @@ class Columns::JSONPathColumn < Columns::ChampColumn
|
||||||
.ids
|
.ids
|
||||||
end
|
end
|
||||||
|
|
||||||
def options_for_select
|
|
||||||
case jsonpath.split('.').last
|
|
||||||
when 'departement_code'
|
|
||||||
APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
|
||||||
when 'region_name'
|
|
||||||
APIGeoService.regions.map { [_1[:name], _1[:name]] }
|
|
||||||
else
|
|
||||||
[]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def column_id = "type_de_champ/#{stable_id}-#{jsonpath}"
|
def column_id = "type_de_champ/#{stable_id}-#{jsonpath}"
|
||||||
|
|
|
@ -5,12 +5,16 @@ module AddressableColumnConcern
|
||||||
|
|
||||||
included do
|
included do
|
||||||
def columns(procedure:, displayable: true, prefix: nil)
|
def columns(procedure:, displayable: true, prefix: nil)
|
||||||
super.concat([
|
departement_options = APIGeoService.departements
|
||||||
["code postal (5 chiffres)", '$.postal_code', :text],
|
.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
||||||
["commune", '$.city_name', :text],
|
region_options = APIGeoService.regions.map { [_1[:name], _1[:name]] }
|
||||||
["département", '$.departement_code', :enum],
|
|
||||||
["region", '$.region_name', :enum]
|
addressable_columns = [
|
||||||
].map do |(label, jsonpath, type)|
|
["code postal (5 chiffres)", '$.postal_code', :text, []],
|
||||||
|
["commune", '$.city_name', :text, []],
|
||||||
|
["département", '$.departement_code', :enum, departement_options],
|
||||||
|
["region", '$.region_name', :enum, region_options]
|
||||||
|
].map do |(label, jsonpath, type, options_for_select)|
|
||||||
Columns::JSONPathColumn.new(
|
Columns::JSONPathColumn.new(
|
||||||
procedure_id: procedure.id,
|
procedure_id: procedure.id,
|
||||||
stable_id:,
|
stable_id:,
|
||||||
|
@ -18,9 +22,12 @@ module AddressableColumnConcern
|
||||||
label: "#{libelle_with_prefix(prefix)} – #{label}",
|
label: "#{libelle_with_prefix(prefix)} – #{label}",
|
||||||
jsonpath:,
|
jsonpath:,
|
||||||
displayable:,
|
displayable:,
|
||||||
|
options_for_select:,
|
||||||
type:
|
type:
|
||||||
)
|
)
|
||||||
end)
|
end
|
||||||
|
|
||||||
|
super.concat(addressable_columns)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -553,7 +553,7 @@ class TypeDeChamp < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def options_for_select(column)
|
def options_for_select
|
||||||
if departement?
|
if departement?
|
||||||
APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
||||||
elsif region?
|
elsif region?
|
||||||
|
@ -566,8 +566,6 @@ class TypeDeChamp < ApplicationRecord
|
||||||
elsif checkbox?
|
elsif checkbox?
|
||||||
Champs::CheckboxChamp.options
|
Champs::CheckboxChamp.options
|
||||||
end
|
end
|
||||||
elsif siret? || rna? || rnf?
|
|
||||||
column.options_for_select
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue