chore(manager): replace dossier champ row by a view component
This commit is contained in:
parent
42867569a5
commit
b8bfb55fb2
4 changed files with 65 additions and 30 deletions
45
app/components/manager/dossier_champ_row_component.rb
Normal file
45
app/components/manager/dossier_champ_row_component.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
class Manager::DossierChampRowComponent < ApplicationComponent
|
||||
with_collection_parameter :row
|
||||
|
||||
attr_reader :row
|
||||
|
||||
def initialize(row:)
|
||||
@row = row
|
||||
end
|
||||
|
||||
def icon
|
||||
return unless row.visible?
|
||||
|
||||
if row.mandatory_blank?
|
||||
"🔴"
|
||||
else
|
||||
"🟢"
|
||||
end
|
||||
end
|
||||
|
||||
def status
|
||||
if !row.visible? && row.conditional?
|
||||
"masqué, conditionnel"
|
||||
elsif row.blank? && !row.piece_justificative_file.attached?
|
||||
"vide"
|
||||
else
|
||||
"rempli"
|
||||
end
|
||||
end
|
||||
|
||||
def cell_class(cell: nil)
|
||||
class_names(
|
||||
'cell-data': true,
|
||||
'cell-disabled': !row.visible?,
|
||||
'pl-8': cell == :label && row.child?
|
||||
)
|
||||
end
|
||||
|
||||
def nested_rows
|
||||
if row.respond_to?(:rows)
|
||||
row.rows
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
%tr
|
||||
%td{ class: cell_class(cell: :label) }
|
||||
= row.libelle
|
||||
- if row.mandatory?
|
||||
%span.mandatory{ style: 'color: #A10005;' } *
|
||||
%td{ class: cell_class }
|
||||
= I18n.t("activerecord.attributes.type_de_champ.type_champs.#{row.type_champ}")
|
||||
|
||||
%td{ class: cell_class }
|
||||
= icon
|
||||
= status
|
||||
|
||||
- nested_rows.each_with_index do |group_rows, index|
|
||||
%thead
|
||||
%tr
|
||||
%td.cell-group-header{ colspan: 3 }
|
||||
= "Bloc ##{index + 1} “#{row.libelle}”"
|
||||
|
||||
= render Manager::DossierChampRowComponent.with_collection(group_rows)
|
|
@ -1,29 +0,0 @@
|
|||
%tr
|
||||
%td.cell-data{ class: [row.child? ? "pl-8" : nil, row.visible? ? nil : "cell-disabled"] }
|
||||
= row.libelle
|
||||
- if row.mandatory?
|
||||
%span.mandatory{ style: 'color: #A10005;' } *
|
||||
%td.cell-data{ class: [row.visible? ? nil : "cell-disabled"] }
|
||||
= I18n.t("activerecord.attributes.type_de_champ.type_champs.#{row.type_champ}")
|
||||
|
||||
%td.cell-data{ class: [row.visible? ? nil : "cell-disabled"] }
|
||||
- if row.visible?
|
||||
- if row.mandatory_blank?
|
||||
🔴
|
||||
- else
|
||||
🟢
|
||||
|
||||
- if !row.visible? && row.conditional?
|
||||
masqué, conditionnel
|
||||
- elsif row.blank? && !row.piece_justificative_file.attached?
|
||||
vide
|
||||
- else
|
||||
rempli
|
||||
|
||||
- if row.respond_to?(:rows)
|
||||
- row.rows.each_with_index do |group_rows, index|
|
||||
%thead
|
||||
%tr
|
||||
%td.cell-group-header{ colspan: 3}
|
||||
= "Bloc ##{index + 1} “#{row.libelle}”"
|
||||
= render partial: "fields/champ_collection_field/row", collection: group_rows, as: :row
|
|
@ -6,6 +6,6 @@
|
|||
%td.cell-label Type de champ
|
||||
%td.cell-label Rempli
|
||||
%tbody
|
||||
= render partial: "fields/champ_collection_field/row", collection: field.data, as: :row
|
||||
= render Manager::DossierChampRowComponent.with_collection(field.data)
|
||||
- else
|
||||
Aucun
|
||||
|
|
Loading…
Reference in a new issue