refactor(champ): move champ value format methods from TypeDeChamp class to instance
This commit is contained in:
parent
cdaa94d5f6
commit
02934188b4
44 changed files with 468 additions and 523 deletions
|
@ -111,23 +111,11 @@ class Champ < ApplicationRecord
|
|||
end
|
||||
|
||||
def to_s
|
||||
TypeDeChamp.champ_value(type_champ, self)
|
||||
type_de_champ.champ_value(self)
|
||||
end
|
||||
|
||||
def for_api
|
||||
TypeDeChamp.champ_value_for_api(type_champ, self, 1)
|
||||
end
|
||||
|
||||
def for_api_v2
|
||||
TypeDeChamp.champ_value_for_api(type_champ, self, 2)
|
||||
end
|
||||
|
||||
def for_export(path = :value)
|
||||
TypeDeChamp.champ_value_for_export(type_champ, self, path)
|
||||
end
|
||||
|
||||
def for_tag(path = :value)
|
||||
TypeDeChamp.champ_value_for_tag(type_champ, self, path)
|
||||
def last_write_type_champ
|
||||
TypeDeChamp::CHAMP_TYPE_TO_TYPE_CHAMP.fetch(type)
|
||||
end
|
||||
|
||||
def main_value_name
|
||||
|
|
|
@ -696,77 +696,35 @@ class TypeDeChamp < ApplicationRecord
|
|||
options.slice(*kept_keys.map(&:to_s))
|
||||
end
|
||||
|
||||
class << self
|
||||
def champ_value(type_champ, champ)
|
||||
dynamic_type_class = type_champ_to_class_name(type_champ).constantize
|
||||
if use_default_value?(type_champ, champ)
|
||||
dynamic_type_class.champ_default_value
|
||||
else
|
||||
dynamic_type_class.champ_value(champ)
|
||||
end
|
||||
def champ_value(champ)
|
||||
if use_default_value?(champ)
|
||||
dynamic_type.champ_default_value
|
||||
else
|
||||
dynamic_type.champ_value(champ)
|
||||
end
|
||||
end
|
||||
|
||||
def champ_value_for_api(type_champ, champ, version = 2)
|
||||
dynamic_type_class = type_champ_to_class_name(type_champ).constantize
|
||||
if use_default_value?(type_champ, champ)
|
||||
dynamic_type_class.champ_default_api_value(version)
|
||||
else
|
||||
dynamic_type_class.champ_value_for_api(champ, version)
|
||||
end
|
||||
def champ_value_for_api(champ, version: 2)
|
||||
if use_default_value?(champ)
|
||||
dynamic_type.champ_default_api_value(version)
|
||||
else
|
||||
dynamic_type.champ_value_for_api(champ, version:)
|
||||
end
|
||||
end
|
||||
|
||||
def champ_value_for_export(type_champ, champ, path = :value)
|
||||
dynamic_type_class = type_champ_to_class_name(type_champ).constantize
|
||||
if use_default_value?(type_champ, champ)
|
||||
dynamic_type_class.champ_default_export_value(path)
|
||||
else
|
||||
dynamic_type_class.champ_value_for_export(champ, path)
|
||||
end
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
if use_default_value?(champ)
|
||||
dynamic_type.champ_default_export_value(path)
|
||||
else
|
||||
dynamic_type.champ_value_for_export(champ, path)
|
||||
end
|
||||
end
|
||||
|
||||
def champ_value_for_tag(type_champ, champ, path = :value)
|
||||
if use_default_value?(type_champ, champ)
|
||||
''
|
||||
else
|
||||
dynamic_type_class = type_champ_to_class_name(type_champ).constantize
|
||||
dynamic_type_class.champ_value_for_tag(champ, path)
|
||||
end
|
||||
end
|
||||
|
||||
def type_champ_to_champ_class_name(type_champ)
|
||||
"Champs::#{type_champ.classify}Champ"
|
||||
end
|
||||
|
||||
def type_champ_to_class_name(type_champ)
|
||||
"TypesDeChamp::#{type_champ.classify}TypeDeChamp"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def use_default_value?(type_champ, champ)
|
||||
# no champ
|
||||
return true if champ.nil?
|
||||
# type de champ on the revision changed
|
||||
if type_champ != champ.type_champ
|
||||
return !castable_on_change?(type_champ, champ.type_champ)
|
||||
end
|
||||
# special case for linked drop down champ – it's blank implementation is not what you think
|
||||
return champ.value.blank? if type_champ == TypeDeChamp.type_champs.fetch(:linked_drop_down_list)
|
||||
champ.blank?
|
||||
end
|
||||
|
||||
def castable_on_change?(from_type, to_type)
|
||||
case [from_type, to_type]
|
||||
when ['integer_number', 'decimal_number'], # recast numbers automatically
|
||||
['decimal_number', 'integer_number'], # may lose some data, but who cares ?
|
||||
['text', 'textarea'], # allow short text to long text
|
||||
['drop_down_list', 'multiple_drop_down_list'], # single list can become multi
|
||||
['date', 'datetime'], # date <=> datetime
|
||||
['datetime', 'date'] # may lose some data, but who cares ?
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
def champ_value_for_tag(champ, path = :value)
|
||||
if use_default_value?(champ)
|
||||
''
|
||||
else
|
||||
dynamic_type.champ_value_for_tag(champ, path)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -774,8 +732,46 @@ class TypeDeChamp < ApplicationRecord
|
|||
"champ-#{public_id(row_id)}"
|
||||
end
|
||||
|
||||
class << self
|
||||
def type_champ_to_champ_class_name(type_champ)
|
||||
"Champs::#{type_champ.classify}Champ"
|
||||
end
|
||||
|
||||
def type_champ_to_class_name(type_champ)
|
||||
"TypesDeChamp::#{type_champ.classify}TypeDeChamp"
|
||||
end
|
||||
end
|
||||
|
||||
CHAMP_TYPE_TO_TYPE_CHAMP = type_champs.values.map { [type_champ_to_champ_class_name(_1), _1] }.to_h
|
||||
|
||||
private
|
||||
|
||||
def use_default_value?(champ)
|
||||
# no champ
|
||||
return true if champ.nil?
|
||||
# type de champ on the revision changed
|
||||
if champ.last_write_type_champ != type_champ
|
||||
return !castable_on_change?(champ.last_write_type_champ, type_champ)
|
||||
end
|
||||
# special case for linked drop down champ – it's blank implementation is not what you think
|
||||
return champ.value.blank? if type_champ == TypeDeChamp.type_champs.fetch(:linked_drop_down_list)
|
||||
champ.blank?
|
||||
end
|
||||
|
||||
def castable_on_change?(from_type, to_type)
|
||||
case [from_type, to_type]
|
||||
when ['integer_number', 'decimal_number'], # recast numbers automatically
|
||||
['decimal_number', 'integer_number'], # may lose some data, but who cares ?
|
||||
['text', 'textarea'], # allow short text to long text
|
||||
['drop_down_list', 'multiple_drop_down_list'], # single list can become multi
|
||||
['date', 'datetime'], # date <=> datetime
|
||||
['datetime', 'date'] # may lose some data, but who cares ?
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def populate_stable_id
|
||||
if !stable_id
|
||||
update_column(:stable_id, id)
|
||||
|
|
|
@ -6,35 +6,33 @@ class TypesDeChamp::AddressTypeDeChamp < TypesDeChamp::TextTypeDeChamp
|
|||
[[path[:libelle], path[:path]]]
|
||||
end
|
||||
|
||||
class << self
|
||||
def champ_value(champ)
|
||||
champ.address_label.presence || ''
|
||||
end
|
||||
def champ_value(champ)
|
||||
champ.address_label.presence || ''
|
||||
end
|
||||
|
||||
def champ_value_for_api(champ, version = 2)
|
||||
def champ_value_for_api(champ, version: 2)
|
||||
champ_value(champ)
|
||||
end
|
||||
|
||||
def champ_value_for_tag(champ, path = :value)
|
||||
case path
|
||||
when :value
|
||||
champ_value(champ)
|
||||
when :departement
|
||||
champ.departement_code_and_name || ''
|
||||
when :commune
|
||||
champ.commune_name || ''
|
||||
end
|
||||
end
|
||||
|
||||
def champ_value_for_tag(champ, path = :value)
|
||||
case path
|
||||
when :value
|
||||
champ_value(champ)
|
||||
when :departement
|
||||
champ.departement_code_and_name || ''
|
||||
when :commune
|
||||
champ.commune_name || ''
|
||||
end
|
||||
end
|
||||
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
case path
|
||||
when :value
|
||||
champ_value(champ)
|
||||
when :departement
|
||||
champ.departement_code_and_name
|
||||
when :commune
|
||||
champ.commune_name
|
||||
end
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
case path
|
||||
when :value
|
||||
champ_value(champ)
|
||||
when :departement
|
||||
champ.departement_code_and_name
|
||||
when :commune
|
||||
champ.commune_name
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -20,13 +20,11 @@ class TypesDeChamp::CarteTypeDeChamp < TypesDeChamp::TypeDeChampBase
|
|||
|
||||
def tags_for_template = [].freeze
|
||||
|
||||
class << self
|
||||
def champ_value_for_api(champ, version = 2)
|
||||
nil
|
||||
end
|
||||
def champ_value_for_api(champ, version: 2)
|
||||
nil
|
||||
end
|
||||
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
champ.geo_areas.map(&:label).join("\n")
|
||||
end
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
champ.geo_areas.map(&:label).join("\n")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,43 +11,41 @@ class TypesDeChamp::CheckboxTypeDeChamp < TypesDeChamp::TypeDeChampBase
|
|||
end
|
||||
end
|
||||
|
||||
class << self
|
||||
def champ_value(champ)
|
||||
champ.true? ? 'Oui' : 'Non'
|
||||
end
|
||||
def champ_value(champ)
|
||||
champ.true? ? 'Oui' : 'Non'
|
||||
end
|
||||
|
||||
def champ_value_for_tag(champ, path = :value)
|
||||
champ_value(champ)
|
||||
end
|
||||
def champ_value_for_tag(champ, path = :value)
|
||||
champ_value(champ)
|
||||
end
|
||||
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
champ.true? ? 'on' : 'off'
|
||||
end
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
champ.true? ? 'on' : 'off'
|
||||
end
|
||||
|
||||
def champ_value_for_api(champ, version = 2)
|
||||
case version
|
||||
when 2
|
||||
champ.true? ? 'true' : 'false'
|
||||
else
|
||||
super
|
||||
end
|
||||
def champ_value_for_api(champ, version: 2)
|
||||
case version
|
||||
when 2
|
||||
champ.true? ? 'true' : 'false'
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def champ_default_value
|
||||
'Non'
|
||||
end
|
||||
def champ_default_value
|
||||
'Non'
|
||||
end
|
||||
|
||||
def champ_default_export_value(path = :value)
|
||||
'off'
|
||||
end
|
||||
def champ_default_export_value(path = :value)
|
||||
'off'
|
||||
end
|
||||
|
||||
def champ_default_api_value(version = 2)
|
||||
case version
|
||||
when 2
|
||||
'false'
|
||||
else
|
||||
nil
|
||||
end
|
||||
def champ_default_api_value(version = 2)
|
||||
case version
|
||||
when 2
|
||||
'false'
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class TypesDeChamp::COJOTypeDeChamp < TypesDeChamp::TextTypeDeChamp
|
||||
class << self
|
||||
def champ_value(champ)
|
||||
"#{champ.accreditation_number} – #{champ.accreditation_birthdate}"
|
||||
end
|
||||
def champ_value(champ)
|
||||
"#{champ.accreditation_number} – #{champ.accreditation_birthdate}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,32 +1,30 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class TypesDeChamp::CommuneTypeDeChamp < TypesDeChamp::TypeDeChampBase
|
||||
class << self
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
case path
|
||||
when :value
|
||||
champ_value(champ)
|
||||
when :departement
|
||||
champ.departement_code_and_name || ''
|
||||
when :code
|
||||
champ.code || ''
|
||||
end
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
case path
|
||||
when :value
|
||||
champ_value(champ)
|
||||
when :departement
|
||||
champ.departement_code_and_name || ''
|
||||
when :code
|
||||
champ.code || ''
|
||||
end
|
||||
end
|
||||
|
||||
def champ_value_for_tag(champ, path = :value)
|
||||
case path
|
||||
when :value
|
||||
champ_value(champ)
|
||||
when :departement
|
||||
champ.departement_code_and_name || ''
|
||||
when :code
|
||||
champ.code || ''
|
||||
end
|
||||
def champ_value_for_tag(champ, path = :value)
|
||||
case path
|
||||
when :value
|
||||
champ_value(champ)
|
||||
when :departement
|
||||
champ.departement_code_and_name || ''
|
||||
when :code
|
||||
champ.code || ''
|
||||
end
|
||||
end
|
||||
|
||||
def champ_value(champ)
|
||||
champ.code_postal? ? "#{champ.name} (#{champ.code_postal})" : champ.name
|
||||
end
|
||||
def champ_value(champ)
|
||||
champ.code_postal? ? "#{champ.name} (#{champ.code_postal})" : champ.name
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class TypesDeChamp::DateTypeDeChamp < TypesDeChamp::TypeDeChampBase
|
||||
class << self
|
||||
def champ_value(champ)
|
||||
I18n.l(Time.zone.parse(champ.value), format: '%d %B %Y')
|
||||
rescue ArgumentError
|
||||
champ.value.presence || "" # old dossiers can have not parseable dates
|
||||
end
|
||||
def champ_value(champ)
|
||||
I18n.l(Time.zone.parse(champ.value), format: '%d %B %Y')
|
||||
rescue ArgumentError
|
||||
champ.value.presence || "" # old dossiers can have not parseable dates
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class TypesDeChamp::DatetimeTypeDeChamp < TypesDeChamp::TypeDeChampBase
|
||||
class << self
|
||||
def champ_value(champ)
|
||||
I18n.l(Time.zone.parse(champ.value))
|
||||
end
|
||||
def champ_value(champ)
|
||||
I18n.l(Time.zone.parse(champ.value))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,28 +1,26 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class TypesDeChamp::DecimalNumberTypeDeChamp < TypesDeChamp::TypeDeChampBase
|
||||
class << self
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
champ_formatted_value(champ)
|
||||
end
|
||||
|
||||
def champ_value_for_api(champ, version: 2)
|
||||
case version
|
||||
when 1
|
||||
champ_formatted_value(champ)
|
||||
end
|
||||
|
||||
def champ_value_for_api(champ, version = 2)
|
||||
case version
|
||||
when 1
|
||||
champ_formatted_value(champ)
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def champ_default_export_value(path = :value)
|
||||
0
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def champ_formatted_value(champ)
|
||||
champ.value&.to_f
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def champ_default_export_value(path = :value)
|
||||
0
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def champ_formatted_value(champ)
|
||||
champ.value&.to_f
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,36 +5,34 @@ class TypesDeChamp::DepartementTypeDeChamp < TypesDeChamp::TextTypeDeChamp
|
|||
APIGeoService.departement_name(filter_value).presence || filter_value
|
||||
end
|
||||
|
||||
class << self
|
||||
def champ_value(champ)
|
||||
"#{champ.code} – #{champ.name}"
|
||||
end
|
||||
def champ_value(champ)
|
||||
"#{champ.code} – #{champ.name}"
|
||||
end
|
||||
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
case path
|
||||
when :code
|
||||
champ.code
|
||||
when :value
|
||||
champ.name
|
||||
end
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
case path
|
||||
when :code
|
||||
champ.code
|
||||
when :value
|
||||
champ.name
|
||||
end
|
||||
end
|
||||
|
||||
def champ_value_for_tag(champ, path = :value)
|
||||
case path
|
||||
when :code
|
||||
champ.code
|
||||
when :value
|
||||
champ_value(champ)
|
||||
end
|
||||
def champ_value_for_tag(champ, path = :value)
|
||||
case path
|
||||
when :code
|
||||
champ.code
|
||||
when :value
|
||||
champ_value(champ)
|
||||
end
|
||||
end
|
||||
|
||||
def champ_value_for_api(champ, version = 2)
|
||||
case version
|
||||
when 2
|
||||
champ_value(champ).tr('–', '-')
|
||||
else
|
||||
champ_value(champ)
|
||||
end
|
||||
def champ_value_for_api(champ, version: 2)
|
||||
case version
|
||||
when 2
|
||||
champ_value(champ).tr('–', '-')
|
||||
else
|
||||
champ_value(champ)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,27 +1,25 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class TypesDeChamp::EpciTypeDeChamp < TypesDeChamp::TextTypeDeChamp
|
||||
class << self
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
case path
|
||||
when :value
|
||||
champ_value(champ)
|
||||
when :code
|
||||
champ.code
|
||||
when :departement
|
||||
champ.departement_code_and_name
|
||||
end
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
case path
|
||||
when :value
|
||||
champ_value(champ)
|
||||
when :code
|
||||
champ.code
|
||||
when :departement
|
||||
champ.departement_code_and_name
|
||||
end
|
||||
end
|
||||
|
||||
def champ_value_for_tag(champ, path = :value)
|
||||
case path
|
||||
when :value
|
||||
champ_value(champ)
|
||||
when :code
|
||||
champ.code
|
||||
when :departement
|
||||
champ.departement_code_and_name
|
||||
end
|
||||
def champ_value_for_tag(champ, path = :value)
|
||||
case path
|
||||
when :value
|
||||
champ_value(champ)
|
||||
when :code
|
||||
champ.code
|
||||
when :departement
|
||||
champ.departement_code_and_name
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,28 +1,26 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class TypesDeChamp::IntegerNumberTypeDeChamp < TypesDeChamp::TypeDeChampBase
|
||||
class << self
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
champ_formatted_value(champ)
|
||||
end
|
||||
|
||||
def champ_value_for_api(champ, version: 2)
|
||||
case version
|
||||
when 1
|
||||
champ_formatted_value(champ)
|
||||
end
|
||||
|
||||
def champ_value_for_api(champ, version = 2)
|
||||
case version
|
||||
when 1
|
||||
champ_formatted_value(champ)
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def champ_default_export_value(path = :value)
|
||||
0
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def champ_formatted_value(champ)
|
||||
champ.value&.to_i
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def champ_default_export_value(path = :value)
|
||||
0
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def champ_formatted_value(champ)
|
||||
champ.value&.to_i
|
||||
end
|
||||
end
|
||||
|
|
|
@ -32,40 +32,38 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas
|
|||
secondary_options
|
||||
end
|
||||
|
||||
class << self
|
||||
def champ_value(champ)
|
||||
[champ.primary_value, champ.secondary_value].filter(&:present?).join(' / ')
|
||||
end
|
||||
def champ_value(champ)
|
||||
[champ.primary_value, champ.secondary_value].filter(&:present?).join(' / ')
|
||||
end
|
||||
|
||||
def champ_value_for_tag(champ, path = :value)
|
||||
case path
|
||||
when :primary
|
||||
champ.primary_value
|
||||
when :secondary
|
||||
champ.secondary_value
|
||||
when :value
|
||||
champ_value(champ)
|
||||
end
|
||||
def champ_value_for_tag(champ, path = :value)
|
||||
case path
|
||||
when :primary
|
||||
champ.primary_value
|
||||
when :secondary
|
||||
champ.secondary_value
|
||||
when :value
|
||||
champ_value(champ)
|
||||
end
|
||||
end
|
||||
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
case path
|
||||
when :primary
|
||||
champ.primary_value
|
||||
when :secondary
|
||||
champ.secondary_value
|
||||
when :value
|
||||
"#{champ.primary_value || ''};#{champ.secondary_value || ''}"
|
||||
end
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
case path
|
||||
when :primary
|
||||
champ.primary_value
|
||||
when :secondary
|
||||
champ.secondary_value
|
||||
when :value
|
||||
"#{champ.primary_value || ''};#{champ.secondary_value || ''}"
|
||||
end
|
||||
end
|
||||
|
||||
def champ_value_for_api(champ, version = 2)
|
||||
case version
|
||||
when 1
|
||||
{ primary: champ.primary_value, secondary: champ.secondary_value }
|
||||
else
|
||||
super
|
||||
end
|
||||
def champ_value_for_api(champ, version: 2)
|
||||
case version
|
||||
when 1
|
||||
{ primary: champ.primary_value, secondary: champ.secondary_value }
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class TypesDeChamp::MultipleDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBase
|
||||
class << self
|
||||
def champ_value(champ)
|
||||
champ.selected_options.join(', ')
|
||||
end
|
||||
def champ_value(champ)
|
||||
champ.selected_options.join(', ')
|
||||
end
|
||||
|
||||
def champ_value_for_tag(champ, path = :value)
|
||||
ChampPresentations::MultipleDropDownListPresentation.new(champ.selected_options)
|
||||
end
|
||||
def champ_value_for_tag(champ, path = :value)
|
||||
ChampPresentations::MultipleDropDownListPresentation.new(champ.selected_options)
|
||||
end
|
||||
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
champ.selected_options.join(', ')
|
||||
end
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
champ.selected_options.join(', ')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,27 +1,25 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class TypesDeChamp::PaysTypeDeChamp < TypesDeChamp::TextTypeDeChamp
|
||||
class << self
|
||||
def champ_value(champ)
|
||||
champ.name
|
||||
end
|
||||
def champ_value(champ)
|
||||
champ.name
|
||||
end
|
||||
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
case path
|
||||
when :value
|
||||
champ_value(champ)
|
||||
when :code
|
||||
champ.code
|
||||
end
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
case path
|
||||
when :value
|
||||
champ_value(champ)
|
||||
when :code
|
||||
champ.code
|
||||
end
|
||||
end
|
||||
|
||||
def champ_value_for_tag(champ, path = :value)
|
||||
case path
|
||||
when :value
|
||||
champ_value(champ)
|
||||
when :code
|
||||
champ.code
|
||||
end
|
||||
def champ_value_for_tag(champ, path = :value)
|
||||
case path
|
||||
when :value
|
||||
champ_value(champ)
|
||||
when :code
|
||||
champ.code
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -22,15 +22,13 @@ class TypesDeChamp::PhoneTypeDeChamp < TypesDeChamp::TextTypeDeChamp
|
|||
# See issue #6996.
|
||||
DEFAULT_COUNTRY_CODES = [:FR, :GP, :GF, :MQ, :RE, :YT, :NC, :PF].freeze
|
||||
|
||||
class << self
|
||||
def champ_value(champ)
|
||||
if Phonelib.valid_for_countries?(champ.value, DEFAULT_COUNTRY_CODES)
|
||||
Phonelib.parse_for_countries(champ.value, DEFAULT_COUNTRY_CODES).full_national
|
||||
else
|
||||
# When he phone number is possible for the default countries, but not strictly valid,
|
||||
# `full_national` could mess up the formatting. In this case just return the original.
|
||||
champ.value
|
||||
end
|
||||
def champ_value(champ)
|
||||
if Phonelib.valid_for_countries?(champ.value, DEFAULT_COUNTRY_CODES)
|
||||
Phonelib.parse_for_countries(champ.value, DEFAULT_COUNTRY_CODES).full_national
|
||||
else
|
||||
# When he phone number is possible for the default countries, but not strictly valid,
|
||||
# `full_national` could mess up the formatting. In this case just return the original.
|
||||
champ.value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,21 +7,19 @@ class TypesDeChamp::PieceJustificativeTypeDeChamp < TypesDeChamp::TypeDeChampBas
|
|||
|
||||
def tags_for_template = [].freeze
|
||||
|
||||
class << self
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
champ.piece_justificative_file.map { _1.filename.to_s }.join(', ')
|
||||
end
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
champ.piece_justificative_file.map { _1.filename.to_s }.join(', ')
|
||||
end
|
||||
|
||||
def champ_value_for_api(champ, version = 2)
|
||||
return if version == 2
|
||||
def champ_value_for_api(champ, version: 2)
|
||||
return if version == 2
|
||||
|
||||
# API v1 don't support multiple PJ
|
||||
attachment = champ.piece_justificative_file.first
|
||||
return if attachment.nil?
|
||||
# API v1 don't support multiple PJ
|
||||
attachment = champ.piece_justificative_file.first
|
||||
return if attachment.nil?
|
||||
|
||||
if attachment.virus_scanner.safe? || attachment.virus_scanner.pending?
|
||||
attachment.url
|
||||
end
|
||||
if attachment.virus_scanner.safe? || attachment.virus_scanner.pending?
|
||||
attachment.url
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,27 +5,25 @@ class TypesDeChamp::RegionTypeDeChamp < TypesDeChamp::TextTypeDeChamp
|
|||
APIGeoService.region_name(filter_value).presence || filter_value
|
||||
end
|
||||
|
||||
class << self
|
||||
def champ_value(champ)
|
||||
champ.name
|
||||
end
|
||||
def champ_value(champ)
|
||||
champ.name
|
||||
end
|
||||
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
case path
|
||||
when :value
|
||||
champ_value(champ)
|
||||
when :code
|
||||
champ.code
|
||||
end
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
case path
|
||||
when :value
|
||||
champ_value(champ)
|
||||
when :code
|
||||
champ.code
|
||||
end
|
||||
end
|
||||
|
||||
def champ_value_for_tag(champ, path = :value)
|
||||
case path
|
||||
when :value
|
||||
champ_value(champ)
|
||||
when :code
|
||||
champ.code
|
||||
end
|
||||
def champ_value_for_tag(champ, path = :value)
|
||||
case path
|
||||
when :value
|
||||
champ_value(champ)
|
||||
when :code
|
||||
champ.code
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class TypesDeChamp::RepetitionTypeDeChamp < TypesDeChamp::TypeDeChampBase
|
||||
def self.champ_value_for_tag(champ, path = :value)
|
||||
def champ_value_for_tag(champ, path = :value)
|
||||
return nil if path != :value
|
||||
return champ_default_value if champ.rows.blank?
|
||||
|
||||
|
|
|
@ -7,9 +7,7 @@ class TypesDeChamp::RNATypeDeChamp < TypesDeChamp::TypeDeChampBase
|
|||
FILL_DURATION_MEDIUM
|
||||
end
|
||||
|
||||
class << self
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
champ.identifier
|
||||
end
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
champ.identifier
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,35 +3,33 @@
|
|||
class TypesDeChamp::RNFTypeDeChamp < TypesDeChamp::TextTypeDeChamp
|
||||
include AddressableColumnConcern
|
||||
|
||||
class << self
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
case path
|
||||
when :value
|
||||
champ.rnf_id
|
||||
when :departement
|
||||
champ.departement_code_and_name
|
||||
when :code_insee
|
||||
champ.commune&.fetch(:code)
|
||||
when :address
|
||||
champ.full_address
|
||||
when :nom
|
||||
champ.title
|
||||
end
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
case path
|
||||
when :value
|
||||
champ.rnf_id
|
||||
when :departement
|
||||
champ.departement_code_and_name
|
||||
when :code_insee
|
||||
champ.commune&.fetch(:code)
|
||||
when :address
|
||||
champ.full_address
|
||||
when :nom
|
||||
champ.title
|
||||
end
|
||||
end
|
||||
|
||||
def champ_value_for_tag(champ, path = :value)
|
||||
case path
|
||||
when :value
|
||||
champ.rnf_id
|
||||
when :departement
|
||||
champ.departement_code_and_name || ''
|
||||
when :code_insee
|
||||
champ.commune&.fetch(:code) || ''
|
||||
when :address
|
||||
champ.full_address || ''
|
||||
when :nom
|
||||
champ.title || ''
|
||||
end
|
||||
def champ_value_for_tag(champ, path = :value)
|
||||
case path
|
||||
when :value
|
||||
champ.rnf_id
|
||||
when :departement
|
||||
champ.departement_code_and_name || ''
|
||||
when :code_insee
|
||||
champ.commune&.fetch(:code) || ''
|
||||
when :address
|
||||
champ.full_address || ''
|
||||
when :nom
|
||||
champ.title || ''
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -5,9 +5,7 @@ class TypesDeChamp::TextareaTypeDeChamp < TypesDeChamp::TextTypeDeChamp
|
|||
FILL_DURATION_MEDIUM
|
||||
end
|
||||
|
||||
class << self
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
ActionView::Base.full_sanitizer.sanitize(champ.value)
|
||||
end
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
ActionView::Base.full_sanitizer.sanitize(champ.value)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,17 +10,15 @@ class TypesDeChamp::TitreIdentiteTypeDeChamp < TypesDeChamp::TypeDeChampBase
|
|||
|
||||
def tags_for_template = [].freeze
|
||||
|
||||
class << self
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
champ.piece_justificative_file.attached? ? "présent" : "absent"
|
||||
end
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
champ.piece_justificative_file.attached? ? "présent" : "absent"
|
||||
end
|
||||
|
||||
def champ_value_for_api(champ, version = 2)
|
||||
nil
|
||||
end
|
||||
def champ_value_for_api(champ, version: 2)
|
||||
nil
|
||||
end
|
||||
|
||||
def champ_default_export_value(path = :value)
|
||||
"absent"
|
||||
end
|
||||
def champ_default_export_value(path = :value)
|
||||
"absent"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -54,44 +54,42 @@ class TypesDeChamp::TypeDeChampBase
|
|||
filter_value
|
||||
end
|
||||
|
||||
class << self
|
||||
def champ_value(champ)
|
||||
champ.value.present? ? champ.value.to_s : champ_default_value
|
||||
end
|
||||
def champ_value(champ)
|
||||
champ.value.present? ? champ.value.to_s : champ_default_value
|
||||
end
|
||||
|
||||
def champ_value_for_api(champ, version = 2)
|
||||
case version
|
||||
when 2
|
||||
champ_value(champ)
|
||||
else
|
||||
champ.value.presence || champ_default_api_value(version)
|
||||
end
|
||||
def champ_value_for_api(champ, version: 2)
|
||||
case version
|
||||
when 2
|
||||
champ_value(champ)
|
||||
else
|
||||
champ.value.presence || champ_default_api_value(version)
|
||||
end
|
||||
end
|
||||
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
path == :value ? champ.value.presence : champ_default_export_value(path)
|
||||
end
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
path == :value ? champ.value.presence : champ_default_export_value(path)
|
||||
end
|
||||
|
||||
def champ_value_for_tag(champ, path = :value)
|
||||
path == :value ? champ_value(champ) : nil
|
||||
end
|
||||
def champ_value_for_tag(champ, path = :value)
|
||||
path == :value ? champ_value(champ) : nil
|
||||
end
|
||||
|
||||
def champ_default_value
|
||||
def champ_default_value
|
||||
''
|
||||
end
|
||||
|
||||
def champ_default_export_value(path = :value)
|
||||
nil
|
||||
end
|
||||
|
||||
def champ_default_api_value(version = 2)
|
||||
case version
|
||||
when 2
|
||||
''
|
||||
end
|
||||
|
||||
def champ_default_export_value(path = :value)
|
||||
else
|
||||
nil
|
||||
end
|
||||
|
||||
def champ_default_api_value(version = 2)
|
||||
case version
|
||||
when 2
|
||||
''
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def columns(procedure_id:, displayable: true, prefix: nil)
|
||||
|
|
|
@ -11,49 +11,47 @@ class TypesDeChamp::YesNoTypeDeChamp < TypesDeChamp::CheckboxTypeDeChamp
|
|||
end
|
||||
end
|
||||
|
||||
class << self
|
||||
def champ_value(champ)
|
||||
champ_formatted_value(champ)
|
||||
end
|
||||
def champ_value(champ)
|
||||
champ_formatted_value(champ)
|
||||
end
|
||||
|
||||
def champ_value_for_tag(champ, path = :value)
|
||||
champ_formatted_value(champ)
|
||||
end
|
||||
def champ_value_for_tag(champ, path = :value)
|
||||
champ_formatted_value(champ)
|
||||
end
|
||||
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
champ_formatted_value(champ)
|
||||
end
|
||||
def champ_value_for_export(champ, path = :value)
|
||||
champ_formatted_value(champ)
|
||||
end
|
||||
|
||||
def champ_value_for_api(champ, version = 2)
|
||||
case version
|
||||
when 2
|
||||
champ.true? ? 'true' : 'false'
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def champ_default_value
|
||||
'Non'
|
||||
end
|
||||
|
||||
def champ_default_export_value(path = :value)
|
||||
'Non'
|
||||
end
|
||||
|
||||
def champ_default_api_value(version = 2)
|
||||
case version
|
||||
when 2
|
||||
'false'
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def champ_formatted_value(champ)
|
||||
champ.true? ? 'Oui' : 'Non'
|
||||
def champ_value_for_api(champ, version: 2)
|
||||
case version
|
||||
when 2
|
||||
champ.true? ? 'true' : 'false'
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def champ_default_value
|
||||
'Non'
|
||||
end
|
||||
|
||||
def champ_default_export_value(path = :value)
|
||||
'Non'
|
||||
end
|
||||
|
||||
def champ_default_api_value(version = 2)
|
||||
case version
|
||||
when 2
|
||||
'false'
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def champ_formatted_value(champ)
|
||||
champ.true? ? 'Oui' : 'Non'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue