diff --git a/app/components/manager/dossier_champ_row_component.rb b/app/components/manager/dossier_champ_row_component.rb new file mode 100644 index 000000000..d3bedece7 --- /dev/null +++ b/app/components/manager/dossier_champ_row_component.rb @@ -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 diff --git a/app/components/manager/dossier_champ_row_component/dossier_champ_row_component.html.haml b/app/components/manager/dossier_champ_row_component/dossier_champ_row_component.html.haml new file mode 100644 index 000000000..2f6199047 --- /dev/null +++ b/app/components/manager/dossier_champ_row_component/dossier_champ_row_component.html.haml @@ -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) diff --git a/app/views/fields/champ_collection_field/_row.html.haml b/app/views/fields/champ_collection_field/_row.html.haml deleted file mode 100644 index 275dd530a..000000000 --- a/app/views/fields/champ_collection_field/_row.html.haml +++ /dev/null @@ -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 diff --git a/app/views/fields/champ_collection_field/_show.html.haml b/app/views/fields/champ_collection_field/_show.html.haml index a814897f4..5b2e94b1a 100644 --- a/app/views/fields/champ_collection_field/_show.html.haml +++ b/app/views/fields/champ_collection_field/_show.html.haml @@ -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