class JournalsController < ApplicationController def index params = OrbitHelper.params categories = [] data = [] journals = Journal.filter_by_categories.filter_by_tags.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) ModuleApp.find_by(key: 'journal').categories.each do |e| categories << [e.id.to_s, e.title] end journals.each do |node| status = node.statuses_with_classname.collect do |stat| { status: stat[:name], "status-class" =>"status-#{stat[:classname]}" } end tags = node.tags.collect do |tag| { tag: tag.name } end data << { id: node.id.to_s, statuses: status, tags: tags, title: node.title, author: node.author, pub_date: node.pub_date.strftime('%Y-%m-%d'), cover: (OrbitHelper.is_mobile_view ? node.cover.mobile.url : node.cover.url), chapters: node.chapters.count, link_to_show: OrbitHelper.url_to_show("#{node.to_param}?list=journal"), } end { "journals" => data, "extras" => { "widget-title" => t("module_name.journal"), "th_cover" => t('journal.cover'), "th_pub_date" => t('journal.pub_date'), "th_title" => t('journal.title'), "th_author" => t('journal.author'), "th_chapter" => t('journal.chapter'), "th_chapters" => t('journal.chapters'), categories: categories }, "total_pages" => journals.total_pages } end def show params = OrbitHelper.params if params[:list] == 'journal' show_journal else show_chapter end end def widget #code end private def show_journal params = OrbitHelper.params journal = Journal.find_by(uid: params[:uid]) chapters = Chapter.where(journal_id: journal.id).page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) data = [] chapters.each do |node| data << { id: node.id.to_s, title: node.title, author: node.author, author_description: node.author_description, page: node.page, text: node.text, link_to_show: OrbitHelper.url_to_show("#{node.to_param}?list=chapter"), file: node.file.url } end { "chapters" => data, "extras" => { "widget-title" => t("module_name.journal"), "th_title" => t('journals.chapter'), "th_author" => t('chapter.author'), "th_page" => t('chapter.page'), "th_action" => t('chapter.action'), "journal_title" => journal.title, "mode" => "many" }, "total_pages" => chapters.total_pages } end def show_chapter params = OrbitHelper.params chapter = Chapter.find_by(uid: params[:uid]) { "title" => chapter.title, "title_title" => t('chapter.title'), "author" => chapter.author, "author_title" => t('chapter.author'), "author_description" => chapter.author_description, "author_description_title" => t('chapter.author_description'), "text" => chapter.text, "text_title" => t('chapter.text'), "extras" => { "mode" => "one" } } end end