demarches-normaliennes/app/helpers/dossier_helper.rb

151 lines
4.8 KiB
Ruby
Raw Normal View History

module DossierHelper
include EtablissementHelper
def button_or_label_class(dossier)
2017-12-04 18:00:12 +01:00
if dossier.accepte?
'accepted'
elsif dossier.sans_suite?
'without-continuation'
2017-12-04 18:15:40 +01:00
elsif dossier.refuse?
'refused'
end
end
def highlight_if_unseen_class(seen_at, updated_at)
if updated_at.present? && seen_at&.<(updated_at)
"highlighted"
end
end
def url_for_dossier(dossier)
if dossier.brouillon?
brouillon_dossier_path(dossier)
else
2018-10-02 12:23:53 +02:00
dossier_path(dossier)
end
end
2021-06-24 11:57:05 +02:00
def url_for_new_dossier(revision)
new_dossier_url(procedure_id: revision.procedure.id, brouillon: revision.draft? ? true : nil)
2019-01-16 11:57:58 +01:00
end
def commencer_dossier_vide_for_revision_path(revision)
revision.draft? ? commencer_dossier_vide_test_path(path: revision.procedure.path) : commencer_dossier_vide_path(path: revision.procedure.path)
end
def dossier_submission_is_closed?(dossier)
return false if dossier.editing_fork?
dossier.brouillon? && dossier.procedure.close?
end
2018-11-06 18:44:32 +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 = Dossier.human_attribute_name("state.#{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
def class_badge_state(state)
case state
when Dossier.states.fetch(:en_construction)
'fr-badge--purple-glycine'
when Dossier.states.fetch(:en_instruction)
'fr-badge--new'
when Dossier.states.fetch(:accepte)
'fr-badge--success'
when Dossier.states.fetch(:refuse), Dossier.states.fetch(:sans_suite)
'fr-badge--warning'
when Dossier.states.fetch(:brouillon)
''
else
''
end
end
def status_badge(state, alignment_class = '')
2020-03-24 13:53:15 +01:00
status_text = dossier_display_state(state, lower: true)
2023-06-08 14:41:42 +02:00
tag.span status_text, role: 'status', class: class_names(
'fr-badge fr-badge--sm' => true,
'fr-badge--no-icon' => [Dossier.states.fetch(:en_instruction), Dossier.states.fetch(:accepte)].exclude?(state),
2023-06-08 14:41:42 +02:00
class_badge_state(state) => true,
alignment_class => true
)
end
2020-03-25 10:58:26 +01:00
def deletion_reason_badge(reason)
if reason.present?
status_text = I18n.t(reason, scope: 'activerecord.attributes.deleted_dossier.reason')
2020-03-25 10:58:26 +01:00
status_class = reason.tr('_', '-')
else
status_text = I18n.t('activerecord.attributes.deleted_dossier.reason.unknown')
2020-03-25 10:58:26 +01:00
status_class = 'unknown'
end
2020-09-24 15:14:48 +02:00
tag.span(status_text, class: "label #{status_class} ")
2020-03-25 10:58:26 +01:00
end
def pending_correction_badge(for_profile, html_class: nil)
tag.span(Dossier.human_attribute_name("pending_correction.#{for_profile}"), class: ['fr-badge fr-badge--sm fr-badge--warning super', html_class], role: 'status')
end
def correction_resolved_badge(html_class: nil)
tag.span(Dossier.human_attribute_name("pending_correction.resolved"), class: ['fr-badge fr-badge--sm fr-badge--success super', html_class], role: 'status')
end
def demandeur_dossier(dossier)
2023-11-14 16:11:17 +01:00
if dossier.procedure.for_individual? && dossier.for_tiers?
return t('shared.dossiers.beneficiaire', mandataire: dossier.mandataire_full_name, beneficiaire: "#{dossier&.individual&.prenom} #{dossier&.individual&.nom}")
end
if dossier.procedure.for_individual?
return "#{dossier&.individual&.nom} #{dossier&.individual&.prenom}"
end
return "" if dossier.etablissement.blank?
if dossier.etablissement.diffusable_commercialement == false
"SIRET #{pretty_siret(dossier.etablissement.siret)}"
else
raison_sociale_or_name(dossier.etablissement)
end
end
def safe_expiration_date(dossier)
l(dossier.expiration_date, format: '%d/%m/%Y')
end
def annuaire_link(siren_or_siret = nil)
base_url = "https://annuaire-entreprises.data.gouv.fr"
return base_url if siren_or_siret.blank?
"#{base_url}/rechercher?terme=#{siren_or_siret}"
end
2021-06-16 11:46:25 +02:00
def france_connect_informations(user_information)
if user_information.full_name.empty?
t("shared.dossiers.france_connect_informations.details_no_name")
elsif user_information.updated_at.present?
t("shared.dossiers.france_connect_informations.details_updated",
name: user_information.full_name,
date: l(user_information.updated_at.to_date, format: :default))
else
t("shared.dossiers.france_connect_informations.details", name: user_information.full_name)
end
end
end