2024-07-25 11:42:50 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-08-30 13:00:13 +02:00
|
|
|
class ChampPresentations::RepetitionPresentation < ChampPresentations::BasePresentation
|
2024-07-25 11:42:50 +02:00
|
|
|
attr_reader :libelle
|
|
|
|
attr_reader :rows
|
|
|
|
|
|
|
|
def initialize(libelle, rows)
|
|
|
|
@libelle = libelle
|
|
|
|
@rows = rows
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
([libelle] + rows.map do |champs|
|
|
|
|
champs.map do |champ|
|
|
|
|
"#{champ.libelle} : #{champ}"
|
|
|
|
end.join("\n")
|
|
|
|
end).join("\n\n")
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_tiptap_node
|
|
|
|
{
|
|
|
|
type: 'orderedList',
|
|
|
|
attrs: { class: 'tdc-repetition' },
|
|
|
|
content: rows.map do |champs|
|
|
|
|
{
|
|
|
|
type: 'listItem',
|
|
|
|
content: [
|
|
|
|
{
|
|
|
|
type: 'descriptionList',
|
|
|
|
content: champs.map do |champ|
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: 'descriptionTerm',
|
2024-09-04 17:32:21 +02:00
|
|
|
attrs: champ.blank? ? { class: 'invisible' } : nil, # still render libelle so width & alignment are preserved
|
2024-07-25 11:42:50 +02:00
|
|
|
content: [
|
|
|
|
{
|
|
|
|
type: 'text',
|
|
|
|
text: champ.libelle
|
|
|
|
}
|
|
|
|
]
|
2024-09-04 17:32:21 +02:00
|
|
|
}.compact,
|
2024-07-25 11:42:50 +02:00
|
|
|
{
|
|
|
|
type: 'descriptionDetails',
|
|
|
|
content: [
|
|
|
|
{
|
|
|
|
type: 'text',
|
|
|
|
text: champ.to_s
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
end.flatten
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|