# 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) 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 = "#{text}" end rows << { "title" => ct.title, "text" => text } if text != "" end { "uid" => entry.uid, "type" => self.section_type, "rows" => rows } end end def get_table_entries tids = self.table_entries.split(',') TableEntry.find(tids) end def get_frontend_object case self.section_type when "universal_table" { "section" => self.title, "section_uid" => self.id.to_s[0..5], "entries" => self.get_table_entries_for_frontend, "url_to_show" => "", "text" => "", "mind_map_title" => "", "mind_map_data" => "" } when "text" { "section" => self.title, "section_uid" => self.id.to_s[0..5], "entries" => [], "uid" => "", "type" => self.section_type, "url_to_show" => "", "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" => self.id.to_s[0..5], "entries" => [], "mind_map_title" => mm.title, "mind_map_data" => mm.mind_map_data.to_json, "uid" => "", "type" => self.section_type, "url_to_show" => "", "text" => "" } end end end