universal_table/app/models/table_column.rb

57 lines
1.5 KiB
Ruby
Raw Permalink Normal View History

2015-11-13 13:10:00 +00:00
class TableColumn
include Mongoid::Document
include Mongoid::Timestamps
field :key
field :title, localize: true
field :display_in_index, type: Boolean, default: true
field :type
2017-04-13 10:50:32 +00:00
field :date_format, default: "YYYY/MM/DD"
2015-11-13 13:10:00 +00:00
field :is_link_to_show, type: Boolean, default: false
2024-08-11 02:17:53 +00:00
field :is_searchable, type: Boolean
2015-11-13 13:10:00 +00:00
field :order, type: Integer
field :make_categorizable, type: Boolean, default: false
2022-02-24 09:31:45 +00:00
field :default_ordered_field, type: Boolean, default: false
field :order_direction,type: String,default: 'desc'
2024-07-20 00:45:45 +00:00
belongs_to :u_table, index: true
2024-07-14 14:57:37 +00:00
has_many :column_entries
index({display_in_index: -1}, { unique: false, background: true })
index({order: 1}, { unique: false, background: true })
index({key: 1}, { unique: false, background: true })
2015-11-13 13:10:00 +00:00
2022-02-24 11:34:53 +00:00
def sort_hash(direction)
case self.type
when "text"
{text: direction}
2022-02-25 06:49:00 +00:00
when "integer"
{number: direction}
2022-02-24 11:34:53 +00:00
when "editor"
{content: direction}
when "image"
{image: direction}
when "date"
{date: direction}
when "period"
{period_from: direction,period_to: direction}
end
end
2024-08-11 02:17:53 +00:00
def is_searchable
tmp = self[:is_searchable]
if tmp.nil?
case self.type
when "date", "period","image"
tmp = false
else
tmp = self.display_in_index
end
end
tmp
end
def self.filter_searchable
self.any_of({is_searchable: true}, {is_searchable:nil, display_in_index: true, :type.nin=> ["date", "period","image"]})
end
2015-11-13 13:10:00 +00:00
end