class JournalsController < ApplicationController def index params = OrbitHelper.params categories = [] data = [] journals = Journal.order(created_at: :desc).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}?mode=journal"), link_to_list: OrbitHelper.url_to_show("#{node.to_param}?mode=many"), } 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[:mode] == 'many' show_list elsif params[:mode] == 'chapter' show_chapter else show_journal end end def widget #code end private def show_list params = OrbitHelper.params journal = Journal.find_by(uid: params[:uid]) chapters = Chapter.where(journal_id: journal.id).order(sort_number: :asc) .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, link_to_show: OrbitHelper.url_to_show("#{node.to_param}?mode=chapter"), file: (node.file.present? ? node.file.url : ''), file_class: (node.file.present? ? '' : 'hidden') } 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" => "chapter" } } end def show_journal params = OrbitHelper.params journal = Journal.find_by(uid: params[:uid]) { "title" => journal.title, "title_title" => t('journal.title'), "author" => journal.author, "author_title" => t('journal.author'), "cover" => journal.cover.url, "cover_title" => t('journal.cover'), "pub_date" => journal.pub_date.strftime('%Y-%m-%d'), "pub_date_title" => t('journal.pub_date'), "pub_information" => journal.pub_information, "pub_information_title" => t('journal.pub_information'), link_to_list: OrbitHelper.url_to_show("#{journal.to_param}?mode=many"), "extras" => { "mode" => "journal" } } end end