add procedure_id to column.id
This commit is contained in:
parent
3c7521a428
commit
3740a79219
14 changed files with 65 additions and 49 deletions
|
@ -12,7 +12,7 @@ class Instructeurs::ColumnPickerComponent < ApplicationComponent
|
|||
def displayable_columns_for_select
|
||||
[
|
||||
procedure.columns.filter(&:displayable).map { |column| [column.label, column.id] },
|
||||
procedure_presentation.displayed_fields.map { Column.new(**_1.deep_symbolize_keys).id }
|
||||
procedure_presentation.displayed_fields.map { Column.new(**_1.deep_symbolize_keys.merge(procedure_id: procedure.id)).id }
|
||||
]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,7 +5,8 @@ class Column
|
|||
|
||||
attr_reader :table, :column, :label, :classname, :type, :scope, :value_column, :filterable, :displayable
|
||||
|
||||
def initialize(table:, column:, label: nil, type: :text, value_column: :value, filterable: true, displayable: true, classname: '', scope: '')
|
||||
def initialize(procedure_id:, table:, column:, label: nil, type: :text, value_column: :value, filterable: true, displayable: true, classname: '', scope: '')
|
||||
@procedure_id = procedure_id
|
||||
@table = table
|
||||
@column = column
|
||||
@label = label || I18n.t(column, scope: [:activerecord, :attributes, :procedure_presentation, :fields, table])
|
||||
|
|
|
@ -4,7 +4,7 @@ module AddressableColumnConcern
|
|||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
def columns(displayable: true, prefix: nil)
|
||||
def columns(procedure_id:, displayable: true, prefix: nil)
|
||||
super.concat([
|
||||
["code postal (5 chiffres)", ['postal_code'], :text],
|
||||
["commune", ['city_name'], :text],
|
||||
|
@ -12,6 +12,7 @@ module AddressableColumnConcern
|
|||
["region", ['region_name'], :enum]
|
||||
].map do |(label, value_column, type)|
|
||||
Columns::JSONPathColumn.new(
|
||||
procedure_id:,
|
||||
table: Column::TYPE_DE_CHAMP_TABLE,
|
||||
column: stable_id,
|
||||
label: "#{libelle_with_prefix(prefix)} – #{label}",
|
||||
|
|
|
@ -15,23 +15,23 @@ module ColumnsConcern
|
|||
end
|
||||
|
||||
def dossier_id_column
|
||||
Column.new(table: 'self', column: 'id', classname: 'number-col', type: :number)
|
||||
Column.new(procedure_id: id, table: 'self', column: 'id', classname: 'number-col', type: :number)
|
||||
end
|
||||
|
||||
def notifications_column
|
||||
Column.new(table: 'notifications', column: 'notifications', label: "notifications", filterable: false)
|
||||
Column.new(procedure_id: id, table: 'notifications', column: 'notifications', label: "notifications", filterable: false)
|
||||
end
|
||||
|
||||
def dossier_columns
|
||||
common = [dossier_id_column, notifications_column]
|
||||
|
||||
dates = ['created_at', 'updated_at', 'depose_at', 'en_construction_at', 'en_instruction_at', 'processed_at']
|
||||
.map { |column| Column.new(table: 'self', column:, type: :date) }
|
||||
.map { |column| Column.new(procedure_id: id, table: 'self', column:, type: :date) }
|
||||
|
||||
non_displayable_dates = ['updated_since', 'depose_since', 'en_construction_since', 'en_instruction_since', 'processed_since']
|
||||
.map { |column| Column.new(table: 'self', column:, type: :date, displayable: false) }
|
||||
.map { |column| Column.new(procedure_id: id, table: 'self', column:, type: :date, displayable: false) }
|
||||
|
||||
states = [Column.new(table: 'self', column: 'state', type: :enum, scope: 'instructeurs.dossiers.filterable_state', displayable: false)]
|
||||
states = [Column.new(procedure_id: id, table: 'self', column: 'state', type: :enum, scope: 'instructeurs.dossiers.filterable_state', displayable: false)]
|
||||
|
||||
[common, dates, sva_svr_columns(for_filters: true), non_displayable_dates, states].flatten.compact
|
||||
end
|
||||
|
@ -42,12 +42,12 @@ module ColumnsConcern
|
|||
scope = [:activerecord, :attributes, :procedure_presentation, :fields, :self]
|
||||
|
||||
columns = [
|
||||
Column.new(table: 'self', column: 'sva_svr_decision_on', type: :date,
|
||||
Column.new(procedure_id: id, 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
|
||||
columns << Column.new(table: 'self', column: 'sva_svr_decision_before', type: :date, displayable: false,
|
||||
columns << Column.new(procedure_id: id, table: 'self', column: 'sva_svr_decision_before', type: :date, displayable: false,
|
||||
label: I18n.t("#{sva_svr_decision}_decision_before", scope:))
|
||||
end
|
||||
|
||||
|
@ -58,30 +58,30 @@ module ColumnsConcern
|
|||
|
||||
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) # not filterable ?
|
||||
Column.new(procedure_id: id, table: 'user', column: 'email'),
|
||||
Column.new(procedure_id: id, table: 'followers_instructeurs', column: 'email'),
|
||||
Column.new(procedure_id: id, table: 'groupe_instructeur', column: 'id', type: :enum),
|
||||
Column.new(procedure_id: id, table: 'avis', column: 'question_answer', filterable: false) # not filterable ?
|
||||
]
|
||||
end
|
||||
|
||||
def individual_columns
|
||||
['nom', 'prenom', 'gender'].map { |column| Column.new(table: 'individual', column:) }
|
||||
['nom', 'prenom', 'gender'].map { |column| Column.new(procedure_id: id, 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:) }
|
||||
.map { |column| Column.new(procedure_id: id, table: 'etablissement', column:) }
|
||||
|
||||
etablissement_dates = ['entreprise_date_creation'].map { |column| Column.new(table: 'etablissement', column:, type: :date) }
|
||||
etablissement_dates = ['entreprise_date_creation'].map { |column| Column.new(procedure_id: id, table: 'etablissement', column:, type: :date) }
|
||||
|
||||
other = ['siret', 'libelle_naf', 'code_postal'].map { |column| Column.new(table: 'etablissement', column:) }
|
||||
other = ['siret', 'libelle_naf', 'code_postal'].map { |column| Column.new(procedure_id: id, table: 'etablissement', column:) }
|
||||
|
||||
[etablissements, etablissement_dates, other].flatten
|
||||
end
|
||||
|
||||
def types_de_champ_columns
|
||||
all_revisions_types_de_champ.flat_map(&:columns)
|
||||
all_revisions_types_de_champ.flat_map { _1.columns(procedure_id: id) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -31,9 +31,9 @@ class ProcedurePresentation < ApplicationRecord
|
|||
|
||||
def displayed_fields_for_headers
|
||||
[
|
||||
Column.new(table: 'self', column: 'id', classname: 'number-col'),
|
||||
*displayed_fields.map { Column.new(**_1.deep_symbolize_keys) },
|
||||
Column.new(table: 'self', column: 'state', classname: 'state-col'),
|
||||
Column.new(procedure_id: procedure.id, table: 'self', column: 'id', classname: 'number-col'),
|
||||
*displayed_fields.map { Column.new(**_1.deep_symbolize_keys.merge(procedure_id: procedure.id)) },
|
||||
Column.new(procedure_id: procedure.id, table: 'self', column: 'state', classname: 'state-col'),
|
||||
*procedure.sva_svr_columns
|
||||
]
|
||||
end
|
||||
|
@ -201,7 +201,7 @@ class ProcedurePresentation < ApplicationRecord
|
|||
.map do |(table, column), filters|
|
||||
values = filters.pluck('value')
|
||||
value_column = filters.pluck('value_column').compact.first || :value
|
||||
dossier_column = procedure.find_column(id: Column.make_id(table, column)) # hack to find json path columns
|
||||
dossier_column = procedure.find_column(id: Column.make_id(procedure.id, table, column)) # hack to find json path columns
|
||||
if dossier_column.is_a?(Columns::JSONPathColumn)
|
||||
dossier_column.filtered_ids(dossiers, values)
|
||||
else
|
||||
|
|
|
@ -27,9 +27,9 @@ class TypesDeChamp::RepetitionTypeDeChamp < TypesDeChamp::TypeDeChampBase
|
|||
ActiveStorage::Filename.new(str.delete('[]*?')).sanitized
|
||||
end
|
||||
|
||||
def columns(displayable: true, prefix: nil)
|
||||
def columns(procedure_id:, displayable: true, prefix: nil)
|
||||
@type_de_champ.procedure
|
||||
.all_revisions_types_de_champ(parent: @type_de_champ)
|
||||
.flat_map { _1.columns(displayable: false, prefix: libelle) }
|
||||
.flat_map { _1.columns(procedure_id:, displayable: false, prefix: libelle) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -98,9 +98,10 @@ class TypesDeChamp::TypeDeChampBase
|
|||
end
|
||||
end
|
||||
|
||||
def columns(displayable: true, prefix: nil)
|
||||
def columns(procedure_id:, displayable: true, prefix: nil)
|
||||
[
|
||||
Column.new(
|
||||
procedure_id:,
|
||||
table: Column::TYPE_DE_CHAMP_TABLE,
|
||||
column: stable_id.to_s,
|
||||
label: libelle_with_prefix(prefix),
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
- filters.each_with_index do |filter, i|
|
||||
- if i > 0
|
||||
= " ou "
|
||||
= link_to remove_filter_instructeur_procedure_path(procedure, { statut: statut, column: "#{filter['table']}/#{filter['column']}", value: filter['value'] }),
|
||||
= link_to remove_filter_instructeur_procedure_path(procedure, { statut: statut, column: Column.make_id(procedure.id, filter['table'], filter['column']), value: filter['value'] }),
|
||||
class: "fr-tag fr-tag--dismiss fr-my-1w", aria: { label: "Retirer le filtre #{filter['column']}" } do
|
||||
= "#{filter['label'].truncate(50)} : #{procedure_presentation.human_value_for_filter(filter)}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue