demarches-normaliennes/app/models/column.rb

39 lines
995 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2024-08-19 14:34:36 +02:00
class Column
TYPE_DE_CHAMP_TABLE = 'type_de_champ'
attr_reader :table, :column, :label, :classname, :type, :scope, :value_column, :filterable, :displayable
2024-07-19 18:03:15 +02:00
2024-09-02 17:25:46 +02:00
def initialize(table:, column:, label: nil, type: :text, value_column: :value, filterable: true, displayable: true, classname: '', scope: '')
@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
# We need this for backward compatibility
2024-09-02 17:25:46 +02:00
@displayable = displayable
end
2024-07-19 18:03:15 +02:00
def id
"#{table}/#{column}"
end
def self.make_id(table, column)
"#{table}/#{column}"
end
def ==(other)
other.to_json == to_json
end
def to_json
{
table:, column:, label:, classname:, type:, scope:, value_column:, filterable:, displayable:
}
end
end