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
|
2024-10-09 09:21:44 +02:00
|
|
|
# we cannot use column.id ( == { procedure_id, column_id }.to_json)
|
|
|
|
# as the order of the keys is not guaranteed
|
|
|
|
# instead, we are using h_id == { procedure_id:, column_id: }
|
|
|
|
# another way to find a column is to look for its label
|
2024-10-07 15:01:40 +02:00
|
|
|
def find_column(h_id: nil, label: nil)
|
2024-10-09 09:23:06 +02:00
|
|
|
column = columns.find { _1.h_id == h_id } if h_id.present?
|
|
|
|
column = columns.find { _1.label == label } if label.present?
|
|
|
|
|
2024-10-11 11:23:36 +02:00
|
|
|
raise ActiveRecord::RecordNotFound.new("Column: unable to find h_id: #{h_id} or label: #{label} for procedure_id #{id}") if column.nil?
|
2024-10-09 09:23:06 +02:00
|
|
|
|
|
|
|
column
|
2024-10-07 15:01:40 +02:00
|
|
|
end
|
2024-08-19 14:34:36 +02:00
|
|
|
|
|
|
|
def columns
|
2024-09-25 12:43:23 +02:00
|
|
|
Current.procedure_columns ||= {}
|
|
|
|
|
|
|
|
Current.procedure_columns[id] ||= begin
|
|
|
|
columns = dossier_columns
|
|
|
|
columns.concat(standard_columns)
|
|
|
|
columns.concat(individual_columns) if for_individual
|
|
|
|
columns.concat(moral_columns) if !for_individual
|
2024-10-30 16:09:40 +01:00
|
|
|
columns.concat(procedure_chorus_columns) if chorusable? && chorus_configuration.complete?
|
2024-09-25 12:43:23 +02:00
|
|
|
columns.concat(types_de_champ_columns)
|
|
|
|
end
|
2024-08-19 14:34:36 +02:00
|
|
|
end
|
|
|
|
|
2024-10-30 16:07:16 +01:00
|
|
|
def usager_columns_for_export
|
2024-10-28 17:16:48 +01:00
|
|
|
columns = [dossier_id_column, user_email_for_display_column, user_france_connected_column]
|
2024-10-28 17:07:22 +01:00
|
|
|
columns.concat(individual_columns) if for_individual
|
|
|
|
columns.concat(moral_columns) if !for_individual
|
2024-10-28 17:16:48 +01:00
|
|
|
columns.concat(procedure_chorus_columns) if chorusable? && chorus_configuration.complete?
|
2024-10-25 14:09:14 +02:00
|
|
|
|
2024-10-30 16:38:43 +01:00
|
|
|
# ensure the columns exist in main list
|
2024-11-15 16:45:32 +01:00
|
|
|
# otherwise, they will be found by the find_column method
|
2024-10-30 16:38:43 +01:00
|
|
|
columns.filter { _1.id.in?(self.columns.map(&:id)) }
|
2024-10-25 14:09:14 +02:00
|
|
|
end
|
|
|
|
|
2024-10-30 16:07:16 +01:00
|
|
|
def dossier_columns_for_export
|
2024-10-30 16:38:43 +01:00
|
|
|
columns = [dossier_state_column, dossier_archived_column]
|
2024-10-28 17:38:48 +01:00
|
|
|
columns.concat(dossier_dates_columns)
|
|
|
|
columns.concat([dossier_motivation_column])
|
|
|
|
columns.concat(sva_svr_columns(for_export: true)) if sva_svr_enabled?
|
2024-10-30 16:38:43 +01:00
|
|
|
columns.concat([groupe_instructeurs_id_column, followers_instructeurs_email_column])
|
|
|
|
|
|
|
|
# ensure the columns exist in main list
|
2024-11-15 16:45:32 +01:00
|
|
|
# otherwise, they will be found by the find_column method
|
2024-10-30 16:38:43 +01:00
|
|
|
columns.filter { _1.id.in?(self.columns.map(&:id)) }
|
2024-10-28 17:38:48 +01:00
|
|
|
end
|
2024-10-25 14:09:14 +02:00
|
|
|
|
2024-11-14 14:16:08 +01:00
|
|
|
def dossier_id_column = dossier_col(table: 'self', column: 'id', type: :integer)
|
2024-10-30 15:58:08 +01:00
|
|
|
|
2024-11-06 16:24:29 +01:00
|
|
|
def dossier_state_column
|
|
|
|
options_for_select = I18n.t('instructeurs.dossiers.filterable_state').map(&:to_a).map(&:reverse)
|
|
|
|
|
2024-11-06 21:18:31 +01:00
|
|
|
dossier_col(table: 'self', column: 'state', type: :enum, options_for_select:, displayable: false)
|
2024-11-06 16:24:29 +01:00
|
|
|
end
|
2024-10-30 15:58:08 +01:00
|
|
|
|
2024-11-06 21:18:31 +01:00
|
|
|
def notifications_column = dossier_col(table: 'notifications', column: 'notifications', label: "notifications", filterable: false)
|
2024-10-30 15:58:08 +01:00
|
|
|
|
|
|
|
def sva_svr_columns(for_export: false)
|
|
|
|
scope = [:activerecord, :attributes, :procedure_presentation, :fields, :self]
|
|
|
|
|
|
|
|
columns = [
|
2024-11-06 21:18:31 +01:00
|
|
|
dossier_col(table: 'self', column: 'sva_svr_decision_on', type: :date,
|
2024-10-30 15:58:08 +01:00
|
|
|
label: I18n.t("#{sva_svr_decision}_decision_on", scope:, type: sva_svr_configuration.human_decision))
|
|
|
|
]
|
|
|
|
if !for_export
|
2024-11-06 21:18:31 +01:00
|
|
|
columns << dossier_col(table: 'self', column: 'sva_svr_decision_before', type: :date, displayable: false,
|
2024-10-30 15:58:08 +01:00
|
|
|
label: I18n.t("#{sva_svr_decision}_decision_before", scope:))
|
|
|
|
end
|
|
|
|
columns
|
|
|
|
end
|
|
|
|
|
|
|
|
def default_sorted_column
|
|
|
|
SortedColumn.new(column: notifications_column, order: 'desc')
|
2024-10-25 14:09:14 +02:00
|
|
|
end
|
|
|
|
|
2024-10-30 15:58:08 +01:00
|
|
|
def default_displayed_columns = [email_column]
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2024-11-07 11:20:03 +01:00
|
|
|
def groupe_instructeurs_id_column = dossier_col(table: 'groupe_instructeur', column: 'id', type: :enum)
|
2024-10-28 17:38:48 +01:00
|
|
|
|
2024-11-06 21:18:31 +01:00
|
|
|
def followers_instructeurs_email_column = dossier_col(table: 'followers_instructeurs', column: 'email')
|
2024-09-30 20:48:54 +02:00
|
|
|
|
2024-11-12 17:34:22 +01:00
|
|
|
def dossier_archived_column = dossier_col(table: 'self', column: 'archived', type: :boolean, displayable: false, filterable: false);
|
2024-10-28 17:16:48 +01:00
|
|
|
|
2024-11-06 21:18:31 +01:00
|
|
|
def dossier_motivation_column = dossier_col(table: 'self', column: 'motivation', type: :text, displayable: false, filterable: false);
|
2024-10-09 15:16:13 +02:00
|
|
|
|
2024-11-06 21:18:31 +01:00
|
|
|
def user_email_for_display_column = dossier_col(table: 'self', column: 'user_email_for_display', filterable: false, displayable: false)
|
2024-10-28 17:16:48 +01:00
|
|
|
|
2024-11-12 17:34:22 +01:00
|
|
|
def user_france_connected_column = dossier_col(table: 'self', column: 'user_from_france_connect?', type: :boolean, filterable: false, displayable: false)
|
2024-10-28 17:16:48 +01:00
|
|
|
|
2024-11-06 21:18:31 +01:00
|
|
|
def dossier_labels_column = dossier_col(table: 'dossier_labels', column: 'label_id', type: :enum, options_for_select: labels.map { [_1.name, _1.id] })
|
2024-10-07 16:52:27 +02:00
|
|
|
|
2024-10-28 17:16:48 +01:00
|
|
|
def procedure_chorus_columns
|
|
|
|
['domaine_fonctionnel', 'referentiel_prog', 'centre_de_cout']
|
2024-11-06 21:18:31 +01:00
|
|
|
.map { |column| dossier_col(table: 'procedure', column:, displayable: false, filterable: false) }
|
2024-09-30 20:48:54 +02:00
|
|
|
end
|
|
|
|
|
2024-10-28 17:38:48 +01:00
|
|
|
def dossier_non_displayable_dates_columns
|
|
|
|
['updated_since', 'depose_since', 'en_construction_since', 'en_instruction_since', 'processed_since']
|
2024-11-06 21:18:31 +01:00
|
|
|
.map { |column| dossier_col(table: 'self', column:, type: :date, displayable: false) }
|
2024-08-19 14:34:36 +02:00
|
|
|
end
|
|
|
|
|
2024-10-25 14:09:14 +02:00
|
|
|
def dossier_dates_columns
|
|
|
|
['created_at', 'updated_at', 'last_champ_updated_at', 'depose_at', 'en_construction_at', 'en_instruction_at', 'processed_at']
|
2024-11-14 14:04:33 +01:00
|
|
|
.map { |column| dossier_col(table: 'self', column:, type: :datetime) }
|
2024-10-25 14:09:14 +02:00
|
|
|
end
|
|
|
|
|
2024-10-09 11:08:41 +02:00
|
|
|
def email_column
|
2024-11-06 21:18:31 +01:00
|
|
|
dossier_col(table: 'user', column: 'email')
|
2024-10-09 11:08:41 +02:00
|
|
|
end
|
|
|
|
|
2024-10-30 15:58:08 +01:00
|
|
|
def dossier_columns
|
|
|
|
columns = [dossier_id_column, notifications_column]
|
|
|
|
columns.concat([dossier_state_column])
|
|
|
|
columns.concat([dossier_archived_column])
|
|
|
|
columns.concat(dossier_dates_columns)
|
|
|
|
columns.concat([dossier_motivation_column])
|
|
|
|
columns.concat(sva_svr_columns(for_export: false)) if sva_svr_enabled?
|
|
|
|
columns.concat(dossier_non_displayable_dates_columns)
|
|
|
|
end
|
|
|
|
|
2024-08-19 14:34:36 +02:00
|
|
|
def standard_columns
|
|
|
|
[
|
2024-10-09 11:08:41 +02:00
|
|
|
email_column,
|
2024-10-28 17:16:48 +01:00
|
|
|
user_email_for_display_column,
|
2024-10-28 17:38:48 +01:00
|
|
|
followers_instructeurs_email_column,
|
|
|
|
groupe_instructeurs_id_column,
|
2024-11-06 21:18:31 +01:00
|
|
|
dossier_col(table: 'avis', column: 'question_answer', filterable: false),
|
2024-10-07 16:52:27 +02:00
|
|
|
user_france_connected_column,
|
|
|
|
dossier_labels_column
|
2024-08-19 14:34:36 +02:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
def individual_columns
|
2024-11-06 21:18:31 +01:00
|
|
|
['gender', 'nom', 'prenom'].map { |column| dossier_col(table: 'individual', column:) }
|
2024-11-12 17:34:22 +01:00
|
|
|
.concat ['mandataire_last_name', 'mandataire_first_name'].map { |column| dossier_col(table: 'self', column:) }
|
|
|
|
.concat ['for_tiers'].map { |column| dossier_col(table: 'self', column:, type: :boolean) }
|
2024-08-19 14:34:36 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def moral_columns
|
2024-10-25 14:09:14 +02:00
|
|
|
etablissements = ['entreprise_forme_juridique', 'entreprise_siren', 'entreprise_nom_commercial', 'entreprise_raison_sociale', 'entreprise_siret_siege_social']
|
2024-11-06 21:18:31 +01:00
|
|
|
.map { |column| dossier_col(table: 'etablissement', column:) }
|
2024-10-25 14:09:14 +02:00
|
|
|
|
2024-11-06 21:18:31 +01:00
|
|
|
etablissement_dates = ['entreprise_date_creation'].map { |column| dossier_col(table: 'etablissement', column:, type: :date) }
|
2024-08-19 14:34:36 +02:00
|
|
|
|
2024-10-25 14:09:14 +02:00
|
|
|
for_export = ["siege_social", "naf", "adresse", "numero_voie", "type_voie", "nom_voie", "complement_adresse", "localite", "code_insee_localite", "entreprise_siren", "entreprise_capital_social", "entreprise_numero_tva_intracommunautaire", "entreprise_forme_juridique_code", "entreprise_code_effectif_entreprise", "entreprise_etat_administratif", "entreprise_nom", "entreprise_prenom", "association_rna", "association_titre", "association_objet", "association_date_creation", "association_date_declaration", "association_date_publication"]
|
2024-11-06 21:18:31 +01:00
|
|
|
.map { |column| dossier_col(table: 'etablissement', column:, displayable: false, filterable: false) }
|
2024-08-19 14:34:36 +02:00
|
|
|
|
2024-11-06 21:18:31 +01:00
|
|
|
other = ['siret', 'libelle_naf', 'code_postal'].map { |column| dossier_col(table: 'etablissement', column:) }
|
2024-08-19 14:34:36 +02:00
|
|
|
|
2024-10-25 14:09:14 +02:00
|
|
|
[etablissements, etablissement_dates, other, for_export].flatten
|
2024-08-19 14:34:36 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def types_de_champ_columns
|
2024-11-04 11:39:08 +01:00
|
|
|
all_revisions_types_de_champ.flat_map { _1.columns(procedure: self) }
|
2024-08-19 14:34:36 +02:00
|
|
|
end
|
2024-11-06 21:18:31 +01:00
|
|
|
|
|
|
|
def dossier_col(**args) = Columns::DossierColumn.new(**(args.merge(procedure_id: id)))
|
2024-08-19 14:34:36 +02:00
|
|
|
end
|
|
|
|
end
|