2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-08-19 14:34:36 +02:00
|
|
|
module ColumnsConcern
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
def find_column(id:) = columns.find { |f| f.id == id }
|
|
|
|
|
|
|
|
def columns
|
|
|
|
columns = dossier_columns
|
|
|
|
columns.concat(standard_columns)
|
|
|
|
columns.concat(individual_columns) if for_individual
|
|
|
|
columns.concat(moral_columns) if !for_individual
|
|
|
|
columns.concat(types_de_champ_columns)
|
|
|
|
end
|
|
|
|
|
|
|
|
def dossier_columns
|
2024-09-17 11:39:18 +02:00
|
|
|
common = [Column.new(table: 'self', column: 'id', classname: 'number-col', type: :number), Column.new(table: 'notifications', column: 'notifications', label: "notifications", filterable: false)]
|
2024-08-19 14:34:36 +02:00
|
|
|
|
|
|
|
dates = ['created_at', 'updated_at', 'depose_at', 'en_construction_at', 'en_instruction_at', 'processed_at']
|
|
|
|
.map { |column| Column.new(table: 'self', column:, type: :date) }
|
|
|
|
|
2024-09-02 17:27:35 +02:00
|
|
|
non_displayable_dates = ['updated_since', 'depose_since', 'en_construction_since', 'en_instruction_since', 'processed_since']
|
2024-08-20 18:41:04 +02:00
|
|
|
.map { |column| Column.new(table: 'self', column:, type: :date, displayable: false) }
|
2024-08-19 14:34:36 +02:00
|
|
|
|
2024-08-20 18:41:04 +02:00
|
|
|
states = [Column.new(table: 'self', column: 'state', type: :enum, scope: 'instructeurs.dossiers.filterable_state', displayable: false)]
|
2024-08-19 14:34:36 +02:00
|
|
|
|
2024-09-02 17:27:35 +02:00
|
|
|
[common, dates, sva_svr_columns(for_filters: true), non_displayable_dates, states].flatten.compact
|
2024-08-19 14:34:36 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def sva_svr_columns(for_filters: false)
|
|
|
|
return if !sva_svr_enabled?
|
|
|
|
|
|
|
|
scope = [:activerecord, :attributes, :procedure_presentation, :fields, :self]
|
|
|
|
|
|
|
|
columns = [
|
|
|
|
Column.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
|
2024-08-20 18:41:04 +02:00
|
|
|
columns << Column.new(table: 'self', column: 'sva_svr_decision_before', type: :date, displayable: false,
|
2024-08-19 14:34:36 +02:00
|
|
|
label: I18n.t("#{sva_svr_decision}_decision_before", scope:))
|
|
|
|
end
|
|
|
|
|
|
|
|
columns
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def standard_columns
|
|
|
|
[
|
|
|
|
Column.new(table: 'user', column: 'email'),
|
|
|
|
Column.new(table: 'followers_instructeurs', column: 'email'),
|
|
|
|
Column.new(table: 'groupe_instructeur', column: 'id', type: :enum),
|
|
|
|
Column.new(table: 'avis', column: 'question_answer', filterable: false)
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
def individual_columns
|
|
|
|
['nom', 'prenom', 'gender'].map { |column| Column.new(table: 'individual', column:) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def moral_columns
|
|
|
|
etablissements = ['entreprise_siren', 'entreprise_forme_juridique', 'entreprise_nom_commercial', 'entreprise_raison_sociale', 'entreprise_siret_siege_social']
|
|
|
|
.map { |column| Column.new(table: 'etablissement', column:) }
|
|
|
|
|
|
|
|
etablissement_dates = ['entreprise_date_creation'].map { |column| Column.new(table: 'etablissement', column:, type: :date) }
|
|
|
|
|
|
|
|
other = ['siret', 'libelle_naf', 'code_postal'].map { |column| Column.new(table: 'etablissement', column:) }
|
|
|
|
|
|
|
|
[etablissements, etablissement_dates, other].flatten
|
|
|
|
end
|
|
|
|
|
|
|
|
def types_de_champ_columns
|
2024-08-22 12:37:10 +02:00
|
|
|
all_revisions_types_de_champ.flat_map(&:columns)
|
2024-08-19 14:34:36 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|