publication/app/controllers/publications_controller.rb

145 lines
4.3 KiB
Ruby
Raw Normal View History

2023-06-04 14:41:53 +00:00
class PublicationsController < ApplicationController
2018-10-04 02:47:23 +00:00
def index
params = OrbitHelper.params
categories = []
data = []
2023-06-04 14:41:53 +00:00
publications = Publication.order(created_at: :desc).filter_by_categories.filter_by_tags
2023-06-04 14:28:32 +00:00
.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
2023-06-04 14:41:53 +00:00
ModuleApp.find_by(key: 'publication').categories.each do |e|
2018-10-04 02:47:23 +00:00
categories << [e.id.to_s, e.title]
end
2023-06-04 14:41:53 +00:00
publications.each do |node|
2018-10-04 02:47:23 +00:00
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,
2023-06-04 14:41:53 +00:00
link_to_show: OrbitHelper.url_to_show("#{node.to_param}?mode=publication"),
2018-10-04 09:44:54 +00:00
link_to_list: OrbitHelper.url_to_show("#{node.to_param}?mode=many"),
2018-10-04 02:47:23 +00:00
}
end
{
2023-06-04 14:41:53 +00:00
"publications" => data,
2018-10-04 02:47:23 +00:00
"extras" => {
2023-06-04 14:41:53 +00:00
"widget-title" => t("module_name.publication"),
"th_cover" => t('publication.cover'),
"th_pub_date" => t('publication.pub_date'),
"th_title" => t('publication.title'),
"th_author" => t('publication.author'),
"th_chapter" => t('publication.chapter'),
"th_chapters" => t('publication.chapters'),
2018-10-04 02:47:23 +00:00
categories: categories
},
2023-06-04 14:41:53 +00:00
"total_pages" => publications.total_pages
2018-10-04 02:47:23 +00:00
}
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
2023-06-04 14:41:53 +00:00
show_publication
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
2023-06-04 14:41:53 +00:00
publication = Publication.find_by(uid: params[:uid])
chapters = Chapter.where(publication_id: publication.id).order(sort_number: :asc)
2023-06-04 14:28:32 +00:00
.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
2018-10-04 02:47:23 +00:00
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" => {
2023-06-04 14:41:53 +00:00
"widget-title" => t("module_name.publication"),
"th_title" => t('publications.chapter'),
2018-10-04 02:47:23 +00:00
"th_author" => t('chapter.author'),
"th_page" => t('chapter.page'),
"th_action" => t('chapter.action'),
2023-06-04 14:41:53 +00:00
"publication_title" => publication.title,
2018-10-04 02:47:23 +00:00
"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
2023-06-04 14:41:53 +00:00
def show_publication
2018-10-04 09:44:54 +00:00
params = OrbitHelper.params
2023-06-04 14:41:53 +00:00
publication = Publication.find_by(uid: params[:uid])
2018-10-04 09:44:54 +00:00
{
2023-06-04 14:41:53 +00:00
"title" => publication.title,
"title_title" => t('publication.title'),
"author" => publication.author,
"author_title" => t('publication.author'),
"cover" => publication.cover.url,
"cover_title" => t('publication.cover'),
"pub_date" => publication.pub_date.strftime('%Y-%m-%d'),
"pub_date_title" => t('publication.pub_date'),
"pub_information" => publication.pub_information,
"pub_information_title" => t('publication.pub_information'),
link_to_list: OrbitHelper.url_to_show("#{publication.to_param}?mode=many"),
2018-10-04 09:44:54 +00:00
"extras" => {
2023-06-04 14:41:53 +00:00
"mode" => "publication"
2018-10-04 02:47:23 +00:00
}
}
end
end