2023-04-28 10:33:01 +02:00
|
|
|
class Dossiers::ChampRowShowComponent < ApplicationComponent
|
|
|
|
include ChampHelper
|
|
|
|
include DossierHelper
|
|
|
|
include ApplicationHelper
|
2023-06-28 09:55:57 +02:00
|
|
|
|
2023-04-28 10:33:01 +02:00
|
|
|
def initialize(champs:, demande_seen_at:, profile:, repetition:)
|
|
|
|
@repetition = repetition
|
|
|
|
@champs = champs
|
|
|
|
@demande_seen_at = demande_seen_at
|
|
|
|
@profile = profile
|
|
|
|
end
|
|
|
|
|
|
|
|
def updated_after_deposer?(champ)
|
|
|
|
return false if champ.dossier.depose_at.blank?
|
2023-06-28 09:55:57 +02:00
|
|
|
|
2023-04-28 10:33:01 +02:00
|
|
|
champ.updated_at > champ.dossier.depose_at
|
|
|
|
end
|
|
|
|
|
|
|
|
def number_with_html_delimiter(num)
|
|
|
|
# we are using the span delimiter that doesn't insert spaces when copying and pasting the number
|
|
|
|
number_with_delimiter(num, delimiter: tag.span(class: 'numbers-delimiter'))
|
|
|
|
end
|
2023-06-28 09:55:57 +02:00
|
|
|
|
|
|
|
def blank_key(champ)
|
|
|
|
key = ".blank"
|
|
|
|
key += "_optional" if @profile == "usager"
|
|
|
|
key += "_attachment" if champ.type_de_champ.piece_justificative?
|
|
|
|
|
|
|
|
key
|
|
|
|
end
|
2023-06-29 07:16:39 +02:00
|
|
|
|
|
|
|
def each_champ(&block)
|
2023-06-29 14:58:58 +02:00
|
|
|
@champs.filter { show_champ?(_1) && _1.visible? && !_1.exclude_from_view? }.each(&block)
|
2023-06-29 07:16:39 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# champ.blank? is overloaded, disable the cop
|
|
|
|
# rubocop:disable Rails/Present
|
|
|
|
def show_champ?(champ)
|
|
|
|
if view_usager?
|
|
|
|
true
|
|
|
|
elsif champ.blank? && updated_after_deposer?(champ)
|
|
|
|
true
|
|
|
|
else
|
|
|
|
!champ.blank?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
# rubocop:enable Rails/Present
|
|
|
|
|
|
|
|
def view_usager?
|
|
|
|
@profile == 'usager'
|
|
|
|
end
|
|
|
|
|
|
|
|
def view_instructeur?
|
|
|
|
@profile == 'instructeur'
|
|
|
|
end
|
2023-04-28 10:33:01 +02:00
|
|
|
end
|