2018-10-04 02:47:23 +00:00
|
|
|
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,
|
2018-10-04 09:44:54 +00:00
|
|
|
link_to_show: OrbitHelper.url_to_show("#{node.to_param}?mode=journal"),
|
|
|
|
link_to_list: OrbitHelper.url_to_show("#{node.to_param}?mode=many"),
|
|
|
|
|
2018-10-04 02:47:23 +00:00
|
|
|
}
|
|
|
|
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
|
2018-10-04 09:44:54 +00:00
|
|
|
if params[:mode] == 'many'
|
|
|
|
show_list
|
|
|
|
elsif params[:mode] == 'chapter'
|
2018-10-04 02:47:23 +00:00
|
|
|
show_chapter
|
2018-10-04 09:44:54 +00:00
|
|
|
else
|
|
|
|
show_journal
|
2018-10-04 02:47:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def widget
|
|
|
|
#code
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-10-04 09:44:54 +00:00
|
|
|
def show_list
|
2018-10-04 02:47:23 +00:00
|
|
|
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,
|
2018-10-04 09:44:54 +00:00
|
|
|
link_to_show: OrbitHelper.url_to_show("#{node.to_param}?mode=chapter"),
|
2018-10-04 05:29:27 +00:00
|
|
|
file: (node.file.present? ? node.file.url : ''),
|
|
|
|
file_class: (node.file.present? ? '' : 'hidden')
|
2018-10-04 02:47:23 +00:00
|
|
|
}
|
|
|
|
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" => {
|
2018-10-04 09:44:54 +00:00
|
|
|
"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,
|
|
|
|
"pub_date_title" => t('journal.pub_date'),
|
|
|
|
"pub_information" => journal.pub_information,
|
|
|
|
"pub_information_title" => t('journal.pub_information'),
|
|
|
|
"extras" => {
|
|
|
|
"mode" => "journal"
|
2018-10-04 02:47:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|