2020-08-06 16:35:45 +02:00
|
|
|
|
# == Schema Information
|
|
|
|
|
#
|
|
|
|
|
# Table name: champs
|
|
|
|
|
#
|
2021-02-04 19:23:40 +01:00
|
|
|
|
# id :integer not null, primary key
|
|
|
|
|
# data :jsonb
|
|
|
|
|
# fetch_external_data_exceptions :string is an Array
|
2022-12-01 12:00:21 +01:00
|
|
|
|
# prefilled :boolean default(FALSE)
|
2021-02-04 19:23:40 +01:00
|
|
|
|
# private :boolean default(FALSE), not null
|
2021-10-20 17:26:09 +02:00
|
|
|
|
# rebased_at :datetime
|
2021-02-04 19:23:40 +01:00
|
|
|
|
# type :string
|
|
|
|
|
# value :string
|
2021-10-05 15:37:13 +02:00
|
|
|
|
# value_json :jsonb
|
2021-02-04 19:23:40 +01:00
|
|
|
|
# created_at :datetime
|
|
|
|
|
# updated_at :datetime
|
2022-09-21 15:20:42 +02:00
|
|
|
|
# dossier_id :integer
|
2021-02-04 19:23:40 +01:00
|
|
|
|
# etablissement_id :integer
|
|
|
|
|
# external_id :string
|
|
|
|
|
# parent_id :bigint
|
2022-12-16 12:39:51 +01:00
|
|
|
|
# row_id :string
|
2022-09-21 15:20:42 +02:00
|
|
|
|
# type_de_champ_id :integer
|
2020-08-06 16:35:45 +02:00
|
|
|
|
#
|
2018-12-18 11:17:52 +01:00
|
|
|
|
class Champs::RepetitionChamp < Champ
|
2022-11-15 14:31:29 +01:00
|
|
|
|
accepts_nested_attributes_for :champs
|
2021-10-22 12:18:43 +02:00
|
|
|
|
delegate :libelle_for_export, to: :type_de_champ
|
2018-12-18 11:17:52 +01:00
|
|
|
|
|
|
|
|
|
def rows
|
2022-12-16 15:07:26 +01:00
|
|
|
|
champs.group_by(&:row_id).values
|
2018-12-18 11:17:52 +01:00
|
|
|
|
end
|
|
|
|
|
|
2022-05-18 14:49:49 +02:00
|
|
|
|
def add_row(revision)
|
2022-04-28 15:06:40 +02:00
|
|
|
|
added_champs = []
|
2021-10-27 16:27:17 +02:00
|
|
|
|
transaction do
|
2022-12-16 12:39:51 +01:00
|
|
|
|
row_id = ULID.generate
|
2022-05-18 14:49:49 +02:00
|
|
|
|
revision.children_of(type_de_champ).each do |type_de_champ|
|
2023-02-02 09:59:03 +01:00
|
|
|
|
added_champs << type_de_champ.build_champ(row_id:)
|
2021-10-27 16:27:17 +02:00
|
|
|
|
end
|
2022-04-28 15:06:40 +02:00
|
|
|
|
self.champs << added_champs
|
2019-01-30 16:14:15 +01:00
|
|
|
|
end
|
2022-04-28 15:06:40 +02:00
|
|
|
|
added_champs
|
2019-01-30 16:14:15 +01:00
|
|
|
|
end
|
|
|
|
|
|
2021-07-21 10:45:59 +02:00
|
|
|
|
def blank?
|
|
|
|
|
champs.empty?
|
2019-01-30 16:14:15 +01:00
|
|
|
|
end
|
|
|
|
|
|
2018-12-18 11:17:52 +01:00
|
|
|
|
def search_terms
|
|
|
|
|
# The user cannot enter any information here so it doesn’t make much sense to search
|
|
|
|
|
end
|
2019-04-03 14:29:30 +02:00
|
|
|
|
|
2019-09-11 16:04:42 +02:00
|
|
|
|
def for_tag
|
|
|
|
|
([libelle] + rows.map do |champs|
|
|
|
|
|
champs.map do |champ|
|
|
|
|
|
"#{champ.libelle} : #{champ}"
|
|
|
|
|
end.join("\n")
|
|
|
|
|
end).join("\n\n")
|
|
|
|
|
end
|
|
|
|
|
|
2019-07-11 10:28:44 +02:00
|
|
|
|
def rows_for_export
|
|
|
|
|
rows.each.with_index(1).map do |champs, index|
|
|
|
|
|
Champs::RepetitionChamp::Row.new(index: index, dossier_id: dossier_id.to_s, champs: champs)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-04-03 14:29:30 +02:00
|
|
|
|
class Row < Hashie::Dash
|
|
|
|
|
property :index
|
|
|
|
|
property :dossier_id
|
|
|
|
|
property :champs
|
|
|
|
|
|
2019-07-11 10:28:44 +02:00
|
|
|
|
def read_attribute_for_serialization(attribute)
|
|
|
|
|
self[attribute]
|
|
|
|
|
end
|
|
|
|
|
|
2021-10-22 12:18:43 +02:00
|
|
|
|
def spreadsheet_columns(types_de_champ)
|
2019-04-03 14:29:30 +02:00
|
|
|
|
[
|
|
|
|
|
['Dossier ID', :dossier_id],
|
|
|
|
|
['Ligne', :index]
|
2021-10-22 12:18:43 +02:00
|
|
|
|
] + Dossier.champs_for_export(champs, types_de_champ)
|
2019-04-03 14:29:30 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2018-12-18 11:17:52 +01:00
|
|
|
|
end
|