demarches-normaliennes/app/models/procedure_presentation.rb

46 lines
1.6 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2018-03-06 13:44:29 +01:00
class ProcedurePresentation < ApplicationRecord
self.ignored_columns += ["displayed_fields", "filters", "sort"]
belongs_to :assign_to, optional: false
has_many :exports, dependent: :destroy
delegate :procedure, :instructeur, to: :assign_to
2024-10-07 15:00:05 +02:00
attribute :displayed_columns, :column, array: true
2024-09-25 17:41:58 +02:00
attribute :sorted_column, :sorted_column
def sorted_column = super || procedure.default_sorted_column # Dummy override to set default value
2024-09-27 12:50:57 +02:00
attribute :a_suivre_filters, :filtered_column, array: true
attribute :suivis_filters, :filtered_column, array: true
attribute :traites_filters, :filtered_column, array: true
attribute :tous_filters, :filtered_column, array: true
attribute :supprimes_filters, :filtered_column, array: true
attribute :supprimes_recemment_filters, :filtered_column, array: true
attribute :expirant_filters, :filtered_column, array: true
attribute :archives_filters, :filtered_column, array: true
2024-10-09 11:08:41 +02:00
before_create { self.displayed_columns = procedure.default_displayed_columns }
validates_associated :displayed_columns, :sorted_column, :a_suivre_filters, :suivis_filters,
:traites_filters, :tous_filters, :supprimes_filters, :expirant_filters, :archives_filters
2024-10-07 18:10:08 +02:00
def filters_for(statut)
send(filters_name_for(statut))
end
def filters_name_for(statut) = statut.tr('-', '_').then { "#{_1}_filters" }
def displayed_fields_for_headers
columns = [
procedure.dossier_id_column,
2024-10-07 15:00:05 +02:00
*displayed_columns,
procedure.dossier_state_column
]
2024-11-13 10:44:51 +01:00
columns.concat(procedure.sva_svr_columns.filter(&:displayable)) if procedure.sva_svr_enabled?
columns
end
2017-10-02 17:03:30 +02:00
end