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?,
|
2023-09-04 15:14:50 +02:00
|
|
|
|
'fr-badge--info': !without_date? && !soon?
|
2023-06-07 19:11:37 +02:00
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def soon?
|
2023-09-04 15:14:50 +02:00
|
|
|
|
return false if object.sva_svr_decision_on.nil?
|
|
|
|
|
|
2023-06-07 19:11:37 +02:00
|
|
|
|
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
|
2023-09-04 15:14:50 +02:00
|
|
|
|
"#{human_decision} : "
|
2023-06-08 15:07:43 +02:00
|
|
|
|
end
|
2023-07-12 10:27:35 +02:00
|
|
|
|
|
|
|
|
|
def title
|
2023-09-04 15:14:50 +02:00
|
|
|
|
if previously_termine?
|
|
|
|
|
t('.previously_termine_title')
|
|
|
|
|
elsif depose_before_configuration?
|
|
|
|
|
t('.depose_before_configuration_title', decision: human_decision)
|
|
|
|
|
elsif without_date?
|
|
|
|
|
t('.manual_decision_title', decision: human_decision)
|
|
|
|
|
elsif pending_correction?
|
2023-07-12 10:27:35 +02:00
|
|
|
|
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-09-04 15:14:50 +02:00
|
|
|
|
|
|
|
|
|
def human_decision
|
|
|
|
|
procedure.sva_svr_configuration.human_decision
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def previously_termine?
|
|
|
|
|
return if !object.respond_to?(:previously_termine?)
|
|
|
|
|
|
|
|
|
|
object.previously_termine?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def depose_before_configuration?
|
|
|
|
|
return if !object.respond_to?(:sva_svr_decision_triggered_at)
|
|
|
|
|
|
|
|
|
|
object.sva_svr_decision_on.nil? && object.sva_svr_decision_triggered_at.nil?
|
|
|
|
|
end
|
2023-06-07 19:11:37 +02:00
|
|
|
|
end
|