[#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
|
end
|
||||||
|
|
||||||
def dossier_tags
|
def dossier_tags
|
||||||
super + dossier_tags_for_mail
|
TagsSubstitutionConcern::DOSSIER_TAGS + TagsSubstitutionConcern::DOSSIER_TAGS_FOR_MAIL
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,42 +4,7 @@ module TagsSubstitutionConcern
|
||||||
include Rails.application.routes.url_helpers
|
include Rails.application.routes.url_helpers
|
||||||
include ActionView::Helpers::UrlHelper
|
include ActionView::Helpers::UrlHelper
|
||||||
|
|
||||||
def tags
|
DOSSIER_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
|
|
||||||
[
|
|
||||||
{
|
{
|
||||||
libelle: 'motivation',
|
libelle: 'motivation',
|
||||||
description: 'Motivation facultative associée à la décision finale d’acceptation, refus ou classement sans suite',
|
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
|
available_for_states: Dossier::SOUMIS
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
end
|
|
||||||
|
|
||||||
def format_date(date)
|
DOSSIER_TAGS_FOR_MAIL = [
|
||||||
if date.present?
|
|
||||||
date.localtime.strftime('%d/%m/%Y')
|
|
||||||
else
|
|
||||||
''
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def dossier_tags_for_mail
|
|
||||||
[
|
|
||||||
{
|
{
|
||||||
libelle: 'lien dossier',
|
libelle: 'lien dossier',
|
||||||
description: '',
|
description: '',
|
||||||
|
@ -96,15 +51,8 @@ module TagsSubstitutionConcern
|
||||||
available_for_states: Dossier::SOUMIS
|
available_for_states: Dossier::SOUMIS
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
end
|
|
||||||
|
|
||||||
def users_dossier_recapitulatif_link(dossier)
|
INDIVIDUAL_TAGS = [
|
||||||
url = users_dossier_recapitulatif_url(dossier)
|
|
||||||
link_to(url, url, target: '_blank')
|
|
||||||
end
|
|
||||||
|
|
||||||
def individual_tags
|
|
||||||
[
|
|
||||||
{
|
{
|
||||||
libelle: 'civilité',
|
libelle: 'civilité',
|
||||||
description: 'M., Mme',
|
description: 'M., Mme',
|
||||||
|
@ -124,10 +72,8 @@ module TagsSubstitutionConcern
|
||||||
available_for_states: Dossier::SOUMIS
|
available_for_states: Dossier::SOUMIS
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
end
|
|
||||||
|
|
||||||
def entreprise_tags
|
ENTREPRISE_TAGS = [
|
||||||
[
|
|
||||||
{
|
{
|
||||||
libelle: 'SIREN',
|
libelle: 'SIREN',
|
||||||
description: '',
|
description: '',
|
||||||
|
@ -153,10 +99,8 @@ module TagsSubstitutionConcern
|
||||||
available_for_states: Dossier::SOUMIS
|
available_for_states: Dossier::SOUMIS
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
end
|
|
||||||
|
|
||||||
def etablissement_tags
|
ETABLISSEMENT_TAGS = [
|
||||||
[
|
|
||||||
{
|
{
|
||||||
libelle: 'adresse',
|
libelle: 'adresse',
|
||||||
description: '',
|
description: '',
|
||||||
|
@ -164,6 +108,57 @@ module TagsSubstitutionConcern
|
||||||
available_for_states: Dossier::SOUMIS
|
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
|
end
|
||||||
|
|
||||||
def replace_tags(text, dossier)
|
def replace_tags(text, dossier)
|
||||||
|
@ -176,9 +171,9 @@ module TagsSubstitutionConcern
|
||||||
|
|
||||||
tags_and_datas = [
|
tags_and_datas = [
|
||||||
[dossier_tags, dossier],
|
[dossier_tags, dossier],
|
||||||
[individual_tags, dossier.individual],
|
[INDIVIDUAL_TAGS, dossier.individual],
|
||||||
[entreprise_tags, dossier.entreprise],
|
[ENTREPRISE_TAGS, dossier.entreprise],
|
||||||
[etablissement_tags, dossier.entreprise&.etablissement]
|
[ETABLISSEMENT_TAGS, dossier.entreprise&.etablissement]
|
||||||
]
|
]
|
||||||
|
|
||||||
tags_and_datas
|
tags_and_datas
|
||||||
|
@ -202,7 +197,7 @@ module TagsSubstitutionConcern
|
||||||
if tag.key?(:target)
|
if tag.key?(:target)
|
||||||
value = data.send(tag[:target])
|
value = data.send(tag[:target])
|
||||||
else
|
else
|
||||||
value = tag[:lambda].(data)
|
value = instance_exec(data, &tag[:lambda])
|
||||||
end
|
end
|
||||||
replace_tag(acc, tag, value)
|
replace_tag(acc, tag, value)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue