e_paper/app/controllers/e_papers_controller.rb

159 lines
4.8 KiB
Ruby

class EPapersController < ApplicationController
def index
params = OrbitHelper.params
page = Page.where(:page_id => params[:page_id]).first rescue nil
papers = Paper.can_display.filter_by_categories.desc(:period)
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,
"publish_date" => topic.created_at
}
end
{
"link_to_show" => OrbitHelper.url_to_show(paper.to_param),
"title" => paper.title,
"period" => paper.period,
"description" => paper.description.gsub(/(?:\n\r?|\r\n?)/, '<br>'),
"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])
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"
topics = paper.topics.asc(:created_at).collect do |topic|
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,
"description" => topic.description,
"publish_date" => topic.created_at,
"image_thumb" => timg,
"image_full" => fimg
}
end
{
"data" => {
"title" => paper.title,
"period" => paper.period,
"description" => paper.description,
"category" => paper.category.title,
"publish_date" => paper.created_at,
"paper_thumb_image" => paper_thumb,
"paper_full_image" => paper_full,
"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
def widget
tags = OrbitHelper.widget_tags
papers = Paper.filter_by_widget_categories.filter_by_tags(tags).desc(:period).collect do |paper|
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,
"link_to_show" => OrbitHelper.url_to_show(paper.to_param)
}
end
{
"papers" => papers,
"extras" => {
"more_url" => OrbitHelper.widget_more_url
}
}
end
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
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"
{
"episode" => topic.episode,
"content" => topic.content,
"publish_date" => topic.created_at,
"image_thumb" => timg,
"image_full" => fimg
}
end
private
def sub_params
params.require(:subscriber).permit!
end
end