90 lines
2.3 KiB
Ruby
90 lines
2.3 KiB
Ruby
# encoding: utf-8
|
|
class CurationPostSection
|
|
include Mongoid::Document
|
|
include Mongoid::Timestamps
|
|
|
|
field :title, localize: true
|
|
field :section_type
|
|
field :text, localize: true
|
|
field :universal_table
|
|
field :table_entries
|
|
field :mind_map_id
|
|
|
|
SECTION_TYPES = ["text", "universal_table", "mind_map"]
|
|
|
|
belongs_to :curation_post
|
|
|
|
def get_table_entries_for_frontend
|
|
module_app = ModuleApp.find_by_key("universal_table")
|
|
tids = self.table_entries.split(',')
|
|
table_entries = TableEntry.find(tids) rescue []
|
|
table_entries.map do |entry|
|
|
rows = []
|
|
entry.column_entries.each do |ce|
|
|
ct = ce.table_column
|
|
next if ct.nil?
|
|
next if ct.display_in_index === false
|
|
text = ce.get_frontend_text(ct)
|
|
if ct.is_link_to_show
|
|
text = "<a class='tabletitle' href='#{OrbitHelper.cal_url_to_show(module_app, entry)}'>#{text}</a>"
|
|
end
|
|
rows << {
|
|
"title" => ct.title,
|
|
"text" => text
|
|
} if text != ""
|
|
end
|
|
rows << {
|
|
"title" => I18n.t("universal_table.hashtags"),
|
|
"text" => entry.tags_for_frontend
|
|
}
|
|
{
|
|
"uid" => entry.uid,
|
|
"type" => self.section_type,
|
|
"rows" => rows
|
|
}
|
|
end
|
|
end
|
|
|
|
def get_table_entries
|
|
tids = self.table_entries.split(',')
|
|
TableEntry.find(tids) rescue []
|
|
end
|
|
|
|
def get_frontend_object
|
|
uid = self.id.to_s[0,5] + self.id.to_s[-5,5]
|
|
case self.section_type
|
|
when "universal_table"
|
|
{
|
|
"section" => self.title,
|
|
"section_uid" => uid,
|
|
"entries" => self.get_table_entries_for_frontend,
|
|
"type" => self.section_type,
|
|
"text" => "",
|
|
"mind_map_title" => "",
|
|
"mind_map_data" => ""
|
|
}
|
|
when "text"
|
|
{
|
|
"section" => self.title,
|
|
"section_uid" => uid,
|
|
"entries" => [],
|
|
"type" => self.section_type,
|
|
"text" => self.text.html_safe,
|
|
"mind_map_title" => "",
|
|
"mind_map_data" => ""
|
|
}
|
|
when "mind_map"
|
|
mm = MindMap.find(self.mind_map_id)
|
|
{
|
|
"section" => self.title,
|
|
"section_uid" => uid,
|
|
"entries" => [],
|
|
"type" => self.section_type,
|
|
"text" => "",
|
|
"mind_map_title" => mm.title,
|
|
"mind_map_data" => mm.mind_map_data.to_json
|
|
}
|
|
end
|
|
end
|
|
end
|