39 lines
1.1 KiB
Ruby
39 lines
1.1 KiB
Ruby
class TableColumn
|
|
include Mongoid::Document
|
|
include Mongoid::Timestamps
|
|
|
|
field :key
|
|
field :title, localize: true
|
|
field :display_in_index, type: Boolean, default: true
|
|
field :type
|
|
field :date_format, default: "YYYY/MM/DD"
|
|
field :is_link_to_show, type: Boolean, default: false
|
|
field :order, type: Integer
|
|
field :make_categorizable, type: Boolean, default: false
|
|
field :default_ordered_field, type: Boolean, default: false
|
|
field :order_direction,type: String,default: 'desc'
|
|
belongs_to :u_table, :dependent => :destroy, index: true
|
|
|
|
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 })
|
|
|
|
def sort_hash(direction)
|
|
case self.type
|
|
when "text"
|
|
{text: direction}
|
|
when "integer"
|
|
{number: direction}
|
|
when "editor"
|
|
{content: direction}
|
|
when "image"
|
|
{image: direction}
|
|
when "date"
|
|
{date: direction}
|
|
when "period"
|
|
{period_from: direction,period_to: direction}
|
|
end
|
|
end
|
|
end |