2017-11-24 19:25:29 +01:00
|
|
|
module DossierHelper
|
2017-11-24 19:26:24 +01:00
|
|
|
def button_or_label_class(dossier)
|
2017-12-04 18:00:12 +01:00
|
|
|
if dossier.accepte?
|
2017-11-24 19:25:29 +01:00
|
|
|
'accepted'
|
2017-12-04 20:23:57 +01:00
|
|
|
elsif dossier.sans_suite?
|
2017-11-24 19:25:29 +01:00
|
|
|
'without-continuation'
|
2017-12-04 18:15:40 +01:00
|
|
|
elsif dossier.refuse?
|
2019-07-02 18:31:42 +02:00
|
|
|
'refused'
|
2017-11-24 19:25:29 +01:00
|
|
|
end
|
|
|
|
end
|
2017-12-05 16:07:05 +01:00
|
|
|
|
|
|
|
def highlight_if_unseen_class(seen_at, updated_at)
|
2020-02-26 22:17:55 +01:00
|
|
|
if updated_at.present? && seen_at&.<(updated_at)
|
2017-12-05 16:07:05 +01:00
|
|
|
"highlighted"
|
|
|
|
end
|
|
|
|
end
|
2018-06-25 18:07:16 +02:00
|
|
|
|
2018-06-28 17:19:22 +02:00
|
|
|
def url_for_dossier(dossier)
|
2018-07-04 09:59:35 +02:00
|
|
|
if dossier.brouillon?
|
2018-09-06 09:09:23 +02:00
|
|
|
brouillon_dossier_path(dossier)
|
2018-06-28 17:19:22 +02:00
|
|
|
else
|
2018-10-02 12:23:53 +02:00
|
|
|
dossier_path(dossier)
|
2018-06-28 17:19:22 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-16 11:57:58 +01:00
|
|
|
def url_for_new_dossier(procedure)
|
|
|
|
if procedure.brouillon?
|
|
|
|
new_dossier_url(procedure_id: procedure.id, brouillon: true)
|
|
|
|
else
|
|
|
|
new_dossier_url(procedure_id: procedure.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-19 17:55:30 +01:00
|
|
|
def dossier_form_class(dossier)
|
|
|
|
classes = ['form']
|
|
|
|
if autosave_available?(dossier)
|
|
|
|
classes << 'autosave-enabled'
|
|
|
|
end
|
|
|
|
classes.join(' ')
|
|
|
|
end
|
|
|
|
|
|
|
|
def autosave_available?(dossier)
|
|
|
|
dossier.brouillon? && Flipper.enabled?(:autosave_dossier_draft, dossier.user)
|
|
|
|
end
|
|
|
|
|
2018-06-25 18:07:16 +02:00
|
|
|
def dossier_submission_is_closed?(dossier)
|
2019-11-14 09:43:45 +01:00
|
|
|
dossier.brouillon? && dossier.procedure.close?
|
2018-06-25 18:07:16 +02:00
|
|
|
end
|
2018-11-06 18:44:32 +01:00
|
|
|
|
2019-12-19 13:22:40 +01:00
|
|
|
def dossier_display_state(dossier_or_state, lower: false)
|
|
|
|
state = dossier_or_state.is_a?(Dossier) ? dossier_or_state.state : dossier_or_state
|
|
|
|
display_state = I18n.t(state, scope: [:activerecord, :attributes, :dossier, :state])
|
|
|
|
lower ? display_state.downcase : display_state
|
2018-11-06 18:44:32 +01:00
|
|
|
end
|
2018-11-07 14:46:22 +01:00
|
|
|
|
|
|
|
def dossier_legacy_state(dossier)
|
|
|
|
case dossier.state
|
|
|
|
when Dossier.states.fetch(:en_construction)
|
|
|
|
'initiated'
|
|
|
|
when Dossier.states.fetch(:en_instruction)
|
|
|
|
'received'
|
|
|
|
when Dossier.states.fetch(:accepte)
|
|
|
|
'closed'
|
|
|
|
when Dossier.states.fetch(:refuse)
|
|
|
|
'refused'
|
|
|
|
when Dossier.states.fetch(:sans_suite)
|
|
|
|
'without_continuation'
|
|
|
|
else
|
|
|
|
dossier.state
|
|
|
|
end
|
|
|
|
end
|
2020-01-27 14:28:23 +01:00
|
|
|
|
|
|
|
# On the 22/01/2020, a technical error on the demarches-simplifees.fr
|
|
|
|
# instance caused some files attached to some dossiers to be deleted.
|
|
|
|
#
|
|
|
|
# This method returns true if the dossier contained attachments
|
|
|
|
# whose files were deleted during this incident.
|
|
|
|
def has_lost_attachments(dossier)
|
|
|
|
if dinum_instance?
|
|
|
|
dossiers_with_lost_attachments_ids.include?(dossier.id)
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-20 17:59:16 +01:00
|
|
|
def status_badge(state)
|
2020-03-24 13:53:15 +01:00
|
|
|
status_text = dossier_display_state(state, lower: true)
|
2020-03-20 17:59:16 +01:00
|
|
|
status_class = state.tr('_', '-')
|
|
|
|
content_tag(:span, status_text, class: "label #{status_class} ")
|
|
|
|
end
|
|
|
|
|
2020-01-27 14:28:23 +01:00
|
|
|
private
|
|
|
|
|
|
|
|
def dinum_instance?
|
|
|
|
ENV['APP_HOST']&.ends_with?('demarches-simplifiees.fr')
|
|
|
|
end
|
|
|
|
|
|
|
|
def dossiers_with_lost_attachments_ids
|
|
|
|
@@ids ||= YAML.load_file(Rails.root.join('config', 'dossiers-with-lost-attachments.yml'))
|
|
|
|
end
|
2017-11-24 19:25:29 +01:00
|
|
|
end
|