[#1203] Define tags in constants rather than methods
This commit is contained in:
parent
db5bf39e32
commit
a21dee680d
2 changed files with 130 additions and 135 deletions
|
@ -19,6 +19,6 @@ module MailTemplateConcern
|
|||
end
|
||||
|
||||
def dossier_tags
|
||||
super + dossier_tags_for_mail
|
||||
TagsSubstitutionConcern::DOSSIER_TAGS + TagsSubstitutionConcern::DOSSIER_TAGS_FOR_MAIL
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,42 +4,7 @@ module TagsSubstitutionConcern
|
|||
include Rails.application.routes.url_helpers
|
||||
include ActionView::Helpers::UrlHelper
|
||||
|
||||
def tags
|
||||
if procedure.for_individual?
|
||||
identity_tags = individual_tags
|
||||
else
|
||||
identity_tags = entreprise_tags + etablissement_tags
|
||||
end
|
||||
|
||||
filter_tags(identity_tags + dossier_tags) + procedure_type_de_champ_public_private_tags
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def filter_tags(tags)
|
||||
# Implementation note: emails and attestation generations are generally
|
||||
# triggerred by changes to the dossier’s state. The email or attestation
|
||||
# is generated right after the dossier has reached its new state.
|
||||
#
|
||||
# DOSSIER_STATE should be equal to this new state.
|
||||
#
|
||||
# For instance, for an email that gets generated for the brouillon->en_construction
|
||||
# transition, DOSSIER_STATE should equal 'en_construction'.
|
||||
|
||||
if !defined?(self.class::DOSSIER_STATE)
|
||||
raise NameError.new("The class #{self.class.name} includes TagsSubstitutionConcern, it should define the DOSSIER_STATE constant but it does not", :DOSSIER_STATE)
|
||||
end
|
||||
|
||||
tags.select { |tag| tag[:available_for_states].include?(self.class::DOSSIER_STATE) }
|
||||
end
|
||||
|
||||
def procedure_type_de_champ_public_private_tags
|
||||
(procedure.types_de_champ + procedure.types_de_champ_private)
|
||||
.map { |tdc| { libelle: tdc.libelle, description: tdc.description } }
|
||||
end
|
||||
|
||||
def dossier_tags
|
||||
[
|
||||
DOSSIER_TAGS = [
|
||||
{
|
||||
libelle: 'motivation',
|
||||
description: 'Motivation facultative associée à la décision finale d’acceptation, refus ou classement sans suite',
|
||||
|
@ -77,18 +42,8 @@ module TagsSubstitutionConcern
|
|||
available_for_states: Dossier::SOUMIS
|
||||
}
|
||||
]
|
||||
end
|
||||
|
||||
def format_date(date)
|
||||
if date.present?
|
||||
date.localtime.strftime('%d/%m/%Y')
|
||||
else
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
def dossier_tags_for_mail
|
||||
[
|
||||
DOSSIER_TAGS_FOR_MAIL = [
|
||||
{
|
||||
libelle: 'lien dossier',
|
||||
description: '',
|
||||
|
@ -96,15 +51,8 @@ module TagsSubstitutionConcern
|
|||
available_for_states: Dossier::SOUMIS
|
||||
}
|
||||
]
|
||||
end
|
||||
|
||||
def users_dossier_recapitulatif_link(dossier)
|
||||
url = users_dossier_recapitulatif_url(dossier)
|
||||
link_to(url, url, target: '_blank')
|
||||
end
|
||||
|
||||
def individual_tags
|
||||
[
|
||||
INDIVIDUAL_TAGS = [
|
||||
{
|
||||
libelle: 'civilité',
|
||||
description: 'M., Mme',
|
||||
|
@ -124,10 +72,8 @@ module TagsSubstitutionConcern
|
|||
available_for_states: Dossier::SOUMIS
|
||||
}
|
||||
]
|
||||
end
|
||||
|
||||
def entreprise_tags
|
||||
[
|
||||
ENTREPRISE_TAGS = [
|
||||
{
|
||||
libelle: 'SIREN',
|
||||
description: '',
|
||||
|
@ -153,10 +99,8 @@ module TagsSubstitutionConcern
|
|||
available_for_states: Dossier::SOUMIS
|
||||
}
|
||||
]
|
||||
end
|
||||
|
||||
def etablissement_tags
|
||||
[
|
||||
ETABLISSEMENT_TAGS = [
|
||||
{
|
||||
libelle: 'adresse',
|
||||
description: '',
|
||||
|
@ -164,6 +108,57 @@ module TagsSubstitutionConcern
|
|||
available_for_states: Dossier::SOUMIS
|
||||
}
|
||||
]
|
||||
|
||||
def tags
|
||||
if procedure.for_individual?
|
||||
identity_tags = INDIVIDUAL_TAGS
|
||||
else
|
||||
identity_tags = ENTREPRISE_TAGS + ETABLISSEMENT_TAGS
|
||||
end
|
||||
|
||||
filter_tags(identity_tags + dossier_tags) + procedure_type_de_champ_public_private_tags
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def format_date(date)
|
||||
if date.present?
|
||||
date.localtime.strftime('%d/%m/%Y')
|
||||
else
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
def users_dossier_recapitulatif_link(dossier)
|
||||
url = users_dossier_recapitulatif_url(dossier)
|
||||
link_to(url, url, target: '_blank')
|
||||
end
|
||||
|
||||
def dossier_tags
|
||||
# Overridden by MailTemplateConcern
|
||||
DOSSIER_TAGS
|
||||
end
|
||||
|
||||
def filter_tags(tags)
|
||||
# Implementation note: emails and attestation generations are generally
|
||||
# triggerred by changes to the dossier’s state. The email or attestation
|
||||
# is generated right after the dossier has reached its new state.
|
||||
#
|
||||
# DOSSIER_STATE should be equal to this new state.
|
||||
#
|
||||
# For instance, for an email that gets generated for the brouillon->en_construction
|
||||
# transition, DOSSIER_STATE should equal 'en_construction'.
|
||||
|
||||
if !defined?(self.class::DOSSIER_STATE)
|
||||
raise NameError.new("The class #{self.class.name} includes TagsSubstitutionConcern, it should define the DOSSIER_STATE constant but it does not", :DOSSIER_STATE)
|
||||
end
|
||||
|
||||
tags.select { |tag| tag[:available_for_states].include?(self.class::DOSSIER_STATE) }
|
||||
end
|
||||
|
||||
def procedure_type_de_champ_public_private_tags
|
||||
(procedure.types_de_champ + procedure.types_de_champ_private)
|
||||
.map { |tdc| { libelle: tdc.libelle, description: tdc.description } }
|
||||
end
|
||||
|
||||
def replace_tags(text, dossier)
|
||||
|
@ -176,9 +171,9 @@ module TagsSubstitutionConcern
|
|||
|
||||
tags_and_datas = [
|
||||
[dossier_tags, dossier],
|
||||
[individual_tags, dossier.individual],
|
||||
[entreprise_tags, dossier.entreprise],
|
||||
[etablissement_tags, dossier.entreprise&.etablissement]
|
||||
[INDIVIDUAL_TAGS, dossier.individual],
|
||||
[ENTREPRISE_TAGS, dossier.entreprise],
|
||||
[ETABLISSEMENT_TAGS, dossier.entreprise&.etablissement]
|
||||
]
|
||||
|
||||
tags_and_datas
|
||||
|
@ -202,7 +197,7 @@ module TagsSubstitutionConcern
|
|||
if tag.key?(:target)
|
||||
value = data.send(tag[:target])
|
||||
else
|
||||
value = tag[:lambda].(data)
|
||||
value = instance_exec(data, &tag[:lambda])
|
||||
end
|
||||
replace_tag(acc, tag, value)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue