e_paper/app/controllers/e_papers_controller.rb

159 lines
4.8 KiB
Ruby
Raw Permalink Normal View History

2017-07-05 09:16:55 +00:00
class EPapersController < ApplicationController
def index
params = OrbitHelper.params
page = Page.where(:page_id => params[:page_id]).first rescue nil
2017-08-07 09:14:05 +00:00
papers = Paper.can_display.filter_by_categories.desc(:period)
2017-07-05 09:16:55 +00:00
f = papers.collect do |paper|
statuses = paper.statuses_with_classname.collect do |status|
{
"status" => status["name"],
"status-class" => "status-#{status['classname']}"
}
end
topics = paper.topics.collect do |topic|
{
"episode" => topic.episode,
"content" => topic.content,
2017-08-04 07:51:42 +00:00
"publish_date" => topic.created_at
2017-07-05 09:16:55 +00:00
}
end
{
"link_to_show" => OrbitHelper.url_to_show(paper.to_param),
"title" => paper.title,
"period" => paper.period,
2017-08-07 09:14:05 +00:00
"description" => paper.description.gsub(/(?:\n\r?|\r\n?)/, '<br>'),
2017-07-05 09:16:55 +00:00
"category" => paper.category.title,
"topic" => topics
}
end
{
"papers" => f,
"extras" => {
"widget-title"=>"EPaper",
"th_title" => t('e_paper.title'),
"th_category" => t('category'),
"th_period" => t('e_paper.period'),
"th_description" => t('e_paper.description'),
"th_history" => t('e_paper.history'),
"th_intro" => t('e_paper.intro'),
"th_episode" => t('e_paper.topic_name'),
"date" => t('e_paper.date')
},
"total_pages" => papers.total_pages
}
end
def show
params = OrbitHelper.params
paper = Paper.find_by(:uid => params[:uid])
2017-08-07 07:46:44 +00:00
paper_thumb = !paper.image.nil? && !paper.image.url.nil? ? paper.image.thumb.url : "http://www.placehold.it/400x400/EFEFEF/AAAAAA"
paper_full = !paper.image.nil? && !paper.image.url.nil? ? paper.image.url : "http://www.placehold.it/1000x1000/EFEFEF/AAAAAA"
2017-08-07 09:14:05 +00:00
topics = paper.topics.asc(:created_at).collect do |topic|
2017-08-07 07:46:44 +00:00
timg = !topic.image.nil? && !topic.image.url.nil? ? topic.image.thumb.url : "http://www.placehold.it/400x400/EFEFEF/AAAAAA"
fimg = !topic.image.nil? && !topic.image.url.nil? ? topic.image.url : "http://www.placehold.it/1000x1000/EFEFEF/AAAAAA"
{
"link_to_show" => OrbitHelper.url_to_show(topic.to_param) + "?method=showtopic",
"episode" => topic.episode,
"content" => topic.content,
2017-08-07 09:53:17 +00:00
"description" => topic.description,
2017-08-07 07:46:44 +00:00
"publish_date" => topic.created_at,
"image_thumb" => timg,
"image_full" => fimg
}
end
2017-07-05 09:16:55 +00:00
{
"data" => {
"title" => paper.title,
"period" => paper.period,
"description" => paper.description,
"category" => paper.category.title,
2017-08-04 07:51:42 +00:00
"publish_date" => paper.created_at,
2017-08-07 07:46:44 +00:00
"paper_thumb_image" => paper_thumb,
"paper_full_image" => paper_full,
2017-07-05 09:16:55 +00:00
"th_title" => t('e_paper.title'),
"th_category" => t('category'),
"th_period" => t('e_paper.period'),
"th_description" => t('e_paper.description'),
"th_history" => t('e_paper.history'),
"th_intro" => t('e_paper.intro'),
"th_episode" => t('e_paper.topic_name'),
"date" => t('e_paper.date'),
},
"topics" => topics
}
end
def subscriber_widget
{}
end
2017-08-09 10:35:21 +00:00
def widget
tags = OrbitHelper.widget_tags
2017-08-16 06:03:39 +00:00
papers = Paper.filter_by_widget_categories.filter_by_tags(tags).desc(:period).collect do |paper|
2017-08-09 10:35:21 +00:00
paper_thumb = !paper.image.nil? && !paper.image.url.nil? ? paper.image.thumb.url : "http://www.placehold.it/400x400/EFEFEF/AAAAAA"
{
"title" => paper.title,
"date" => paper.period,
"description" => paper.description,
"image_thumb" => paper_thumb,
2017-08-17 07:18:40 +00:00
"link_to_show" => OrbitHelper.widget_item_url(paper.to_param)
2017-08-09 10:35:21 +00:00
}
end
{
"papers" => papers,
"extras" => {
"more_url" => OrbitHelper.widget_more_url
}
}
end
2017-07-05 09:16:55 +00:00
def subscribeuser
if Subscriber.where(:email => params[:email]).count == 0
subscriber = Subscriber.new
subscriber.email = params[:email]
subscriber.save
data = {"success" => true, "msg" => "Successfully Subscribed!!!"}
else
data = {"success" => false, "msg" => "Already Subscribed!!!"}
end
render :json => data.to_json
end
def unsubscribeuser
subscriber = Subscriber.where(:email => params[:email]).first rescue nil
if !subscriber.nil?
subscriber.destroy
data = {"success" => true, "msg" => "Successfully Unsubscribed!!!"}
# else
# data = {"success" => false, "msg" => "Already Subscribed!!!"}
end
render :json => data.to_json
end
def showtopic
params = OrbitHelper.params
topic = Topic.where(:uid => params[:uid]).first
2017-08-07 07:46:44 +00:00
timg = !topic.image.nil? && !topic.image.url.nil? ? topic.image.thumb.url : "http://www.placehold.it/400x400/EFEFEF/AAAAAA"
fimg = !topic.image.nil? && !topic.image.url.nil? ? topic.image.url : "http://www.placehold.it/1000x1000/EFEFEF/AAAAAA"
2017-07-05 09:16:55 +00:00
{
"episode" => topic.episode,
"content" => topic.content,
2017-08-07 07:46:44 +00:00
"publish_date" => topic.created_at,
"image_thumb" => timg,
"image_full" => fimg
2017-07-05 09:16:55 +00:00
}
end
private
def sub_params
params.require(:subscriber).permit!
end
end