2023-06-07 19:11:37 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Instructeurs::SVASVRDecisionBadgeComponent < ApplicationComponent
|
|
|
|
attr_reader :object
|
2023-06-08 15:26:51 +02:00
|
|
|
attr_reader :procedure
|
2023-06-08 15:07:43 +02:00
|
|
|
attr_reader :with_label
|
2023-06-07 19:11:37 +02:00
|
|
|
|
2023-06-08 15:26:51 +02:00
|
|
|
def initialize(projection_or_dossier:, procedure:, with_label: false)
|
2023-06-07 19:11:37 +02:00
|
|
|
@object = projection_or_dossier
|
2023-06-08 15:26:51 +02:00
|
|
|
@procedure = procedure
|
|
|
|
@decision = procedure.sva_svr_configuration.decision.to_sym
|
2023-06-08 15:07:43 +02:00
|
|
|
@with_label = with_label
|
2023-06-07 19:11:37 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def render?
|
2023-06-08 15:26:51 +02:00
|
|
|
return false unless procedure.sva_svr_enabled?
|
|
|
|
|
2023-06-07 19:11:37 +02:00
|
|
|
[:en_construction, :en_instruction].include? object.state.to_sym
|
|
|
|
end
|
|
|
|
|
|
|
|
def without_date?
|
|
|
|
object.sva_svr_decision_on.nil?
|
|
|
|
end
|
|
|
|
|
|
|
|
def classes
|
|
|
|
class_names(
|
|
|
|
'fr-badge fr-badge--sm': true,
|
|
|
|
'fr-badge--warning': soon?,
|
|
|
|
'fr-badge--info': !soon?
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def soon?
|
|
|
|
object.sva_svr_decision_on < 7.days.from_now.to_date
|
|
|
|
end
|
|
|
|
|
|
|
|
def pending_correction?
|
|
|
|
object.pending_correction?
|
|
|
|
end
|
|
|
|
|
|
|
|
def days_count
|
|
|
|
(object.sva_svr_decision_on - Date.current).to_i
|
|
|
|
end
|
|
|
|
|
|
|
|
def sva?
|
|
|
|
@decision == :sva
|
|
|
|
end
|
|
|
|
|
|
|
|
def svr?
|
|
|
|
@decision == :svr
|
|
|
|
end
|
2023-06-08 15:07:43 +02:00
|
|
|
|
|
|
|
def label_for_badge
|
|
|
|
sva? ? "SVA :" : "SVR :"
|
|
|
|
end
|
2023-07-12 10:27:35 +02:00
|
|
|
|
|
|
|
def title
|
|
|
|
return if without_date?
|
|
|
|
|
|
|
|
if pending_correction?
|
|
|
|
t(".dossier_terminated_x_days_after_correction", count: days_count)
|
|
|
|
else
|
|
|
|
t(".dossier_terminated_on", date: helpers.l(object.sva_svr_decision_on))
|
|
|
|
end
|
|
|
|
end
|
2023-06-07 19:11:37 +02:00
|
|
|
end
|