add shortcut for DossierColumn.new

This commit is contained in:
simon lehericey 2024-11-06 21:18:31 +01:00
parent 9fd3a460cd
commit 32d3ec2dc3
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5

View file

@ -51,25 +51,25 @@ module ColumnsConcern
columns.filter { _1.id.in?(self.columns.map(&:id)) } columns.filter { _1.id.in?(self.columns.map(&:id)) }
end end
def dossier_id_column = Columns::DossierColumn.new(procedure_id: id, table: 'self', column: 'id', type: :number) def dossier_id_column = dossier_col(table: 'self', column: 'id', type: :number)
def dossier_state_column def dossier_state_column
options_for_select = I18n.t('instructeurs.dossiers.filterable_state').map(&:to_a).map(&:reverse) options_for_select = I18n.t('instructeurs.dossiers.filterable_state').map(&:to_a).map(&:reverse)
Columns::DossierColumn.new(procedure_id: id, table: 'self', column: 'state', type: :enum, options_for_select:, displayable: false) dossier_col(table: 'self', column: 'state', type: :enum, options_for_select:, displayable: false)
end end
def notifications_column = Columns::DossierColumn.new(procedure_id: id, table: 'notifications', column: 'notifications', label: "notifications", filterable: false) def notifications_column = dossier_col(table: 'notifications', column: 'notifications', label: "notifications", filterable: false)
def sva_svr_columns(for_export: false) def sva_svr_columns(for_export: false)
scope = [:activerecord, :attributes, :procedure_presentation, :fields, :self] scope = [:activerecord, :attributes, :procedure_presentation, :fields, :self]
columns = [ columns = [
Columns::DossierColumn.new(procedure_id: id, table: 'self', column: 'sva_svr_decision_on', type: :date, dossier_col(table: 'self', column: 'sva_svr_decision_on', type: :date,
label: I18n.t("#{sva_svr_decision}_decision_on", scope:, type: sva_svr_configuration.human_decision)) label: I18n.t("#{sva_svr_decision}_decision_on", scope:, type: sva_svr_configuration.human_decision))
] ]
if !for_export if !for_export
columns << Columns::DossierColumn.new(procedure_id: id, table: 'self', column: 'sva_svr_decision_before', type: :date, displayable: false, columns << dossier_col(table: 'self', column: 'sva_svr_decision_before', type: :date, displayable: false,
label: I18n.t("#{sva_svr_decision}_decision_before", scope:)) label: I18n.t("#{sva_svr_decision}_decision_before", scope:))
end end
columns columns
@ -87,38 +87,38 @@ module ColumnsConcern
groupes = Current.user&.instructeur&.groupe_instructeurs || [] groupes = Current.user&.instructeur&.groupe_instructeurs || []
options_for_select = groupes.filter_map { [_1.label, _1.id] if _1.procedure_id == id } options_for_select = groupes.filter_map { [_1.label, _1.id] if _1.procedure_id == id }
Columns::DossierColumn.new(procedure_id: id, table: 'groupe_instructeur', column: 'id', type: :enum, options_for_select:) dossier_col(table: 'groupe_instructeur', column: 'id', type: :enum, options_for_select:)
end end
def followers_instructeurs_email_column = Columns::DossierColumn.new(procedure_id: id, table: 'followers_instructeurs', column: 'email') def followers_instructeurs_email_column = dossier_col(table: 'followers_instructeurs', column: 'email')
def dossier_archived_column = Columns::DossierColumn.new(procedure_id: id, table: 'self', column: 'archived', type: :text, displayable: false, filterable: false); def dossier_archived_column = dossier_col(table: 'self', column: 'archived', type: :text, displayable: false, filterable: false);
def dossier_motivation_column = Columns::DossierColumn.new(procedure_id: id, table: 'self', column: 'motivation', type: :text, displayable: false, filterable: false); def dossier_motivation_column = dossier_col(table: 'self', column: 'motivation', type: :text, displayable: false, filterable: false);
def user_email_for_display_column = Columns::DossierColumn.new(procedure_id: id, table: 'self', column: 'user_email_for_display', filterable: false, displayable: false) def user_email_for_display_column = dossier_col(table: 'self', column: 'user_email_for_display', filterable: false, displayable: false)
def user_france_connected_column = Columns::DossierColumn.new(procedure_id: id, table: 'self', column: 'user_from_france_connect?', filterable: false, displayable: false) def user_france_connected_column = dossier_col(table: 'self', column: 'user_from_france_connect?', filterable: false, displayable: false)
def dossier_labels_column = Columns::DossierColumn.new(procedure_id: id, table: 'dossier_labels', column: 'label_id', type: :enum, options_for_select: labels.map { [_1.name, _1.id] }) def dossier_labels_column = dossier_col(table: 'dossier_labels', column: 'label_id', type: :enum, options_for_select: labels.map { [_1.name, _1.id] })
def procedure_chorus_columns def procedure_chorus_columns
['domaine_fonctionnel', 'referentiel_prog', 'centre_de_cout'] ['domaine_fonctionnel', 'referentiel_prog', 'centre_de_cout']
.map { |column| Columns::DossierColumn.new(procedure_id: id, table: 'procedure', column:, displayable: false, filterable: false) } .map { |column| dossier_col(table: 'procedure', column:, displayable: false, filterable: false) }
end end
def dossier_non_displayable_dates_columns def dossier_non_displayable_dates_columns
['updated_since', 'depose_since', 'en_construction_since', 'en_instruction_since', 'processed_since'] ['updated_since', 'depose_since', 'en_construction_since', 'en_instruction_since', 'processed_since']
.map { |column| Columns::DossierColumn.new(procedure_id: id, table: 'self', column:, type: :date, displayable: false) } .map { |column| dossier_col(table: 'self', column:, type: :date, displayable: false) }
end end
def dossier_dates_columns def dossier_dates_columns
['created_at', 'updated_at', 'last_champ_updated_at', 'depose_at', 'en_construction_at', 'en_instruction_at', 'processed_at'] ['created_at', 'updated_at', 'last_champ_updated_at', 'depose_at', 'en_construction_at', 'en_instruction_at', 'processed_at']
.map { |column| Columns::DossierColumn.new(procedure_id: id, table: 'self', column:, type: :date) } .map { |column| dossier_col(table: 'self', column:, type: :date) }
end end
def email_column def email_column
Columns::DossierColumn.new(procedure_id: id, table: 'user', column: 'email') dossier_col(table: 'user', column: 'email')
end end
def dossier_columns def dossier_columns
@ -137,27 +137,27 @@ module ColumnsConcern
user_email_for_display_column, user_email_for_display_column,
followers_instructeurs_email_column, followers_instructeurs_email_column,
groupe_instructeurs_id_column, groupe_instructeurs_id_column,
Columns::DossierColumn.new(procedure_id: id, table: 'avis', column: 'question_answer', filterable: false), dossier_col(table: 'avis', column: 'question_answer', filterable: false),
user_france_connected_column, user_france_connected_column,
dossier_labels_column dossier_labels_column
] ]
end end
def individual_columns def individual_columns
['gender', 'nom', 'prenom'].map { |column| Columns::DossierColumn.new(procedure_id: id, table: 'individual', column:) } ['gender', 'nom', 'prenom'].map { |column| dossier_col(table: 'individual', column:) }
.concat ['for_tiers', 'mandataire_last_name', 'mandataire_first_name'].map { |column| Columns::DossierColumn.new(procedure_id: id, table: 'self', column:) } .concat ['for_tiers', 'mandataire_last_name', 'mandataire_first_name'].map { |column| dossier_col(table: 'self', column:) }
end end
def moral_columns def moral_columns
etablissements = ['entreprise_forme_juridique', 'entreprise_siren', 'entreprise_nom_commercial', 'entreprise_raison_sociale', 'entreprise_siret_siege_social'] etablissements = ['entreprise_forme_juridique', 'entreprise_siren', 'entreprise_nom_commercial', 'entreprise_raison_sociale', 'entreprise_siret_siege_social']
.map { |column| Columns::DossierColumn.new(procedure_id: id, table: 'etablissement', column:) } .map { |column| dossier_col(table: 'etablissement', column:) }
etablissement_dates = ['entreprise_date_creation'].map { |column| Columns::DossierColumn.new(procedure_id: id, table: 'etablissement', column:, type: :date) } etablissement_dates = ['entreprise_date_creation'].map { |column| dossier_col(table: 'etablissement', column:, type: :date) }
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"] 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"]
.map { |column| Columns::DossierColumn.new(procedure_id: id, table: 'etablissement', column:, displayable: false, filterable: false) } .map { |column| dossier_col(table: 'etablissement', column:, displayable: false, filterable: false) }
other = ['siret', 'libelle_naf', 'code_postal'].map { |column| Columns::DossierColumn.new(procedure_id: id, table: 'etablissement', column:) } other = ['siret', 'libelle_naf', 'code_postal'].map { |column| dossier_col(table: 'etablissement', column:) }
[etablissements, etablissement_dates, other, for_export].flatten [etablissements, etablissement_dates, other, for_export].flatten
end end
@ -165,5 +165,7 @@ module ColumnsConcern
def types_de_champ_columns def types_de_champ_columns
all_revisions_types_de_champ.flat_map { _1.columns(procedure: self) } all_revisions_types_de_champ.flat_map { _1.columns(procedure: self) }
end end
def dossier_col(**args) = Columns::DossierColumn.new(**(args.merge(procedure_id: id)))
end end
end end