2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-08-19 14:34:36 +02:00
|
|
|
class Column
|
2024-08-22 12:37:10 +02:00
|
|
|
TYPE_DE_CHAMP_TABLE = 'type_de_champ'
|
|
|
|
|
2024-08-20 18:41:04 +02:00
|
|
|
attr_reader :table, :column, :label, :classname, :type, :scope, :value_column, :filterable, :displayable
|
2024-07-19 18:03:15 +02:00
|
|
|
|
2024-10-07 21:46:59 +02:00
|
|
|
def initialize(procedure_id:, table:, column:, label: nil, type: :text, value_column: :value, filterable: true, displayable: true, classname: '', scope: '')
|
|
|
|
@procedure_id = procedure_id
|
2024-07-19 11:16:40 +02:00
|
|
|
@table = table
|
|
|
|
@column = column
|
|
|
|
@label = label || I18n.t(column, scope: [:activerecord, :attributes, :procedure_presentation, :fields, table])
|
|
|
|
@classname = classname
|
|
|
|
@type = type
|
|
|
|
@scope = scope
|
|
|
|
@value_column = value_column
|
|
|
|
@filterable = filterable
|
2024-09-02 17:25:46 +02:00
|
|
|
@displayable = displayable
|
2024-07-19 11:16:40 +02:00
|
|
|
end
|
|
|
|
|
2024-10-07 15:01:40 +02:00
|
|
|
def id = h_id.to_json
|
|
|
|
def h_id = { procedure_id: @procedure_id, column_id: "#{table}/#{column}" }
|
|
|
|
def ==(other) = h_id == other.h_id # using h_id instead of id to avoid inversion of keys
|
2024-07-19 11:16:40 +02:00
|
|
|
|
|
|
|
def to_json
|
|
|
|
{
|
2024-08-20 18:41:04 +02:00
|
|
|
table:, column:, label:, classname:, type:, scope:, value_column:, filterable:, displayable:
|
2024-07-19 11:16:40 +02:00
|
|
|
}
|
|
|
|
end
|
2024-10-07 15:00:22 +02:00
|
|
|
|
|
|
|
def self.find(h_id)
|
|
|
|
Procedure.with_discarded.find(h_id[:procedure_id]).find_column(h_id:)
|
|
|
|
end
|
2024-07-19 11:16:40 +02:00
|
|
|
end
|