clean facets_concern

This commit is contained in:
simon lehericey 2024-07-21 17:51:06 +02:00 committed by mfo
parent 60c6c86d70
commit ef63579e2e
No known key found for this signature in database
GPG key ID: 7CE3E1F5B794A8EC

View file

@ -4,80 +4,41 @@ module FacetsConcern
included do
TYPE_DE_CHAMP = 'type_de_champ'
def find_facet(id:)
facets.find { |f| f.id == id }
end
def find_facet(id:) = facets.find { |f| f.id == id }
def facets
facets = dossier_facets
facets.push(
Facet.new(table: 'user', column: 'email', type: :text),
Facet.new(table: 'followers_instructeurs', column: 'email', type: :text),
Facet.new(table: 'groupe_instructeur', column: 'id', type: :enum),
Facet.new(table: 'avis', column: 'question_answer', filterable: false)
)
if for_individual
facets.push(
Facet.new(table: "individual", column: "prenom", type: :text),
Facet.new(table: "individual", column: "nom", type: :text),
Facet.new(table: "individual", column: "gender", type: :text)
)
end
if !for_individual
facets.push(
Facet.new(table: 'etablissement', column: 'entreprise_siren', type: :text),
Facet.new(table: 'etablissement', column: 'entreprise_forme_juridique', type: :text),
Facet.new(table: 'etablissement', column: 'entreprise_nom_commercial', type: :text),
Facet.new(table: 'etablissement', column: 'entreprise_raison_sociale', type: :text),
Facet.new(table: 'etablissement', column: 'entreprise_siret_siege_social', type: :text),
Facet.new(table: 'etablissement', column: 'entreprise_date_creation', type: :date),
Facet.new(table: 'etablissement', column: 'siret', type: :text),
Facet.new(table: 'etablissement', column: 'libelle_naf', type: :text),
Facet.new(table: 'etablissement', column: 'code_postal', type: :text)
)
end
facets.concat(standard_facets)
facets.concat(individual_facets) if for_individual
facets.concat(moral_facets) if !for_individual
facets.concat(types_de_champ_facets)
facets
end
def dossier_facets
[
Facet.new(table: 'self', column: 'created_at', type: :date),
Facet.new(table: 'self', column: 'updated_at', type: :date),
Facet.new(table: 'self', column: 'depose_at', type: :date),
Facet.new(table: 'self', column: 'en_construction_at', type: :date),
Facet.new(table: 'self', column: 'en_instruction_at', type: :date),
Facet.new(table: 'self', column: 'processed_at', type: :date),
*sva_svr_facets(for_filters: true),
Facet.new(table: 'self', column: 'updated_since', type: :date, virtual: true),
Facet.new(table: 'self', column: 'depose_since', type: :date, virtual: true),
Facet.new(table: 'self', column: 'en_construction_since', type: :date, virtual: true),
Facet.new(table: 'self', column: 'en_instruction_since', type: :date, virtual: true),
Facet.new(table: 'self', column: 'processed_since', type: :date, virtual: true),
Facet.new(table: 'self', column: 'state', type: :enum, scope: 'instructeurs.dossiers.filterable_state', virtual: true)
].compact_blank
dates = ['created_at', 'updated_at', 'depose_at', 'en_construction_at', 'en_instruction_at', 'processed_at']
.map { |column| Facet.new(table: 'self', column:, type: :date) }
virtual_dates = ['updated_since', 'depose_since', 'en_construction_since', 'en_instruction_since', 'processed_since']
.map { |column| Facet.new(table: 'self', column:, type: :date, virtual: true) }
states = [Facet.new(table: 'self', column: 'state', type: :enum, scope: 'instructeurs.dossiers.filterable_state', virtual: true)]
[dates, sva_svr_facets(for_filters: true), virtual_dates, states].flatten.compact
end
def sva_svr_facets(for_filters: false)
return if !sva_svr_enabled?
i18n_scope = [:activerecord, :attributes, :procedure_presentation, :fields, :self]
scope = [:activerecord, :attributes, :procedure_presentation, :fields, :self]
facets = []
facets << Facet.new(table: 'self', column: 'sva_svr_decision_on',
type: :date,
label: I18n.t("#{sva_svr_decision}_decision_on", scope: i18n_scope),
classname: for_filters ? '' : 'sva-col')
facets = [
Facet.new(table: 'self', column: 'sva_svr_decision_on', type: :date,
label: I18n.t("#{sva_svr_decision}_decision_on", scope:), classname: for_filters ? '' : 'sva-col')
]
if for_filters
facets << Facet.new(table: 'self', column: 'sva_svr_decision_before',
label: I18n.t("#{sva_svr_decision}_decision_before", scope: i18n_scope),
type: :date, virtual: true)
facets << Facet.new(table: 'self', column: 'sva_svr_decision_before', type: :date, virtual: true,
label: I18n.t("#{sva_svr_decision}_decision_before", scope:))
end
facets
@ -85,6 +46,30 @@ module FacetsConcern
private
def standard_facets
[
Facet.new(table: 'user', column: 'email'),
Facet.new(table: 'followers_instructeurs', column: 'email'),
Facet.new(table: 'groupe_instructeur', column: 'id', type: :enum),
Facet.new(table: 'avis', column: 'question_answer', filterable: false)
]
end
def individual_facets
['nom', 'prenom', 'gender'].map { |column| Facet.new(table: 'individual', column:) }
end
def moral_facets
etablissements = ['entreprise_siren', 'entreprise_forme_juridique', 'entreprise_nom_commercial', 'entreprise_raison_sociale', 'entreprise_siret_siege_social']
.map { |column| Facet.new(table: 'etablissement', column:) }
etablissement_dates = ['entreprise_date_creation'].map { |column| Facet.new(table: 'etablissement', column:, type: :date) }
other = ['siret', 'libelle_naf', 'code_postal'].map { |column| Facet.new(table: 'etablissement', column:) }
[etablissements, etablissement_dates, other].flatten
end
def types_de_champ_facets
types_de_champ_for_procedure_presentation
.pluck(:type_champ, :libelle, :stable_id)