First draft repeatable
This commit is contained in:
parent
fc3b7c5ec8
commit
81df033282
4 changed files with 25 additions and 7 deletions
|
@ -72,6 +72,8 @@ class Champ < ApplicationRecord
|
||||||
:refresh_after_update?,
|
:refresh_after_update?,
|
||||||
to: :type_de_champ
|
to: :type_de_champ
|
||||||
|
|
||||||
|
delegate :revision, to: :dossier, prefix: true
|
||||||
|
|
||||||
scope :updated_since?, -> (date) { where('champs.updated_at > ?', date) }
|
scope :updated_since?, -> (date) { where('champs.updated_at > ?', date) }
|
||||||
scope :public_only, -> { where(private: false) }
|
scope :public_only, -> { where(private: false) }
|
||||||
scope :private_only, -> { where(private: true) }
|
scope :private_only, -> { where(private: true) }
|
||||||
|
|
|
@ -7,7 +7,7 @@ module DossierPrefillableConcern
|
||||||
return unless champs_public_attributes.any?
|
return unless champs_public_attributes.any?
|
||||||
|
|
||||||
attr = { prefilled: true }
|
attr = { prefilled: true }
|
||||||
attr[:champs_public_attributes] = champs_public_attributes.map { |h| h.merge(prefilled: true) }
|
attr[:champs_public_all_attributes] = champs_public_attributes.map { |h| h.merge(prefilled: true) }
|
||||||
|
|
||||||
assign_attributes(attr)
|
assign_attributes(attr)
|
||||||
save(validate: false)
|
save(validate: false)
|
||||||
|
|
|
@ -5,7 +5,7 @@ class PrefillParams
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_a
|
def to_a
|
||||||
build_prefill_values.filter(&:prefillable?).map(&:to_h)
|
build_prefill_values.filter(&:prefillable?).map(&:to_h).flatten
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -55,11 +55,15 @@ class PrefillParams
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_h
|
def to_h
|
||||||
|
if champ.type_champ == TypeDeChamp.type_champs.fetch(:repetition)
|
||||||
|
repeatable_hashes
|
||||||
|
else
|
||||||
{
|
{
|
||||||
id: champ.id,
|
id: champ.id,
|
||||||
value: value
|
value: value
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
@ -69,5 +73,16 @@ class PrefillParams
|
||||||
champ.value = value
|
champ.value = value
|
||||||
champ.valid?(:prefill)
|
champ.valid?(:prefill)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def repeatable_hashes
|
||||||
|
value.map.with_index do |repetition, index|
|
||||||
|
row = champ.rows[index] || champ.add_row(champ.dossier_revision)
|
||||||
|
JSON.parse(repetition).map do |key, value|
|
||||||
|
id = row.find { |champ| champ.libelle == key }.id
|
||||||
|
{ id: id, value: value }
|
||||||
|
end
|
||||||
|
rescue JSON::ParserError
|
||||||
|
end.flatten
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -269,7 +269,8 @@ class TypeDeChamp < ApplicationRecord
|
||||||
TypeDeChamp.type_champs.fetch(:yes_no),
|
TypeDeChamp.type_champs.fetch(:yes_no),
|
||||||
TypeDeChamp.type_champs.fetch(:checkbox),
|
TypeDeChamp.type_champs.fetch(:checkbox),
|
||||||
TypeDeChamp.type_champs.fetch(:drop_down_list),
|
TypeDeChamp.type_champs.fetch(:drop_down_list),
|
||||||
TypeDeChamp.type_champs.fetch(:regions)
|
TypeDeChamp.type_champs.fetch(:regions),
|
||||||
|
TypeDeChamp.type_champs.fetch(:repetition),
|
||||||
])
|
])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue