diff --git a/app/controllers/e_papers_controller.rb b/app/controllers/e_papers_controller.rb index 69471cd..e863aeb 100644 --- a/app/controllers/e_papers_controller.rb +++ b/app/controllers/e_papers_controller.rb @@ -1,27 +1,85 @@ class EPapersController < ApplicationController FrontendMethods = ["papers", "topics"] + EmptyImg = "data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA=" + EmptyImgUrl = "#{EmptyImg}\" style=\"display: none;" + def self.custom_widget_data + ac = ActionController::Base.new + ac.render_to_string("e_papers/custom_widget_data",:locals=>{:@custom_data_field=>@custom_data_field,:@field_name=>@field_name}) + end def index - topics = EPaperTopic.filter_by_categories.filter_by_tags.desc(:period) - data = topics.collect do |topic| + page_no = OrbitHelper.page_number + data_count = OrbitHelper.page_data_count + page = (OrbitHelper.page rescue Page.where(:url=>params[:url]).first) + page_layout = page.layout + custom_data_field = page.custom_data_field + if custom_data_field + criteria_id = (custom_data_field["criteria_id"] || "all" rescue "all") + epaper_topics = nil + if criteria_id == "all" + epaper_topics = EPaperTopic.all + else + criteria = PaperCriteria.where(:id => criteria_id).first + epaper_topics = criteria.epaper_topics + end + else + epaper_topics = EPaperTopic.all + criteria = nil + end + topics = epaper_topics.filter_by_categories.filter_by_tags.desc(:period).page(page_no).per(data_count) + total_pages = topics.total_pages + page_url = page.get_url rescue page.url + if page_layout.include?("_latest") + topics_group = topics.group_by(&:category) + data = topics_group.collect do |category, topics| + category_title = (category ? category.title : "") + topics_data = topics.collect do |topic| + { + "title" => topic.title, + "criteria_title" => topic.criteria_title, + "link_to_show" => OrbitHelper.url_to_show(topic.to_param), + "description" => topic.description, + "img_url" => topic.image.url || EmptyImgUrl, + "img_url_thumb" => topic.image.thumb.url || EmptyImgUrl, + "category" => category_title, + "category_title" => category_title, + "publish_date" => topic.period + } + end + { + "category_title" => category_title, + "category_link" => "#{page_url}?method=topics&category=#{category.id.to_s}", + "topics" => topics_data + } + end { - "title" => topic.title, - "criteria_title" => topic.criteria_title, - "link_to_show" => OrbitHelper.url_to_show(topic.to_param), - "description" => topic.description, - "img_url" => topic.image.url, - "img_url_thumb" => topic.image.thumb.url, - "category" => (topic.category.title rescue ""), - "category_title" => (topic.category.title rescue ""), - "publish_date" => topic.period + "categories" => data, + "extras" => { + + }, + "total_pages" => total_pages + } + else + data = topics.to_a.collect do |topic| + { + "title" => topic.title, + "criteria_title" => topic.criteria_title, + "link_to_show" => OrbitHelper.url_to_show(topic.to_param), + "description" => topic.description, + "img_url" => topic.image.url || EmptyImgUrl, + "img_url_thumb" => topic.image.thumb.url || EmptyImgUrl, + "category" => (topic.category.title rescue ""), + "category_title" => (topic.category.title rescue ""), + "publish_date" => topic.period + } + end + { + "topics" => data, + "extras" => { + + }, + "total_pages" => total_pages } end - { - "topics" => data, - "extras" => { - - }, - "total_pages" => (topics.count * 1.0 / OrbitHelper.page_data_count).ceil - } end def papers @@ -58,8 +116,8 @@ class EPapersController < ApplicationController "content" => epaper.content, "publish_date" => epaper.period, "description" => epaper.description, - "image_url" => epaper.image.url, - "image_thumb_url" => epaper.image.thumb.url, + "image_url" => epaper.image.url || EmptyImgUrl, + "image_thumb_url" => epaper.image.thumb.url || EmptyImgUrl, "title" => epaper.title, "category_title" => epaper.category.title, "criteria_title" => epaper.criteria_title, @@ -71,11 +129,17 @@ class EPapersController < ApplicationController def topics params = OrbitHelper.params - criteria = PaperCriteria.where(:uid => params[:uid]).first - if params["category"].present? - papers = criteria.epaper_topics.where(:category_id => params["category"]).group_by(&:category) + if params[:uid].present? + criteria = PaperCriteria.where(:uid => params[:uid]).first + return if criteria.nil? + epaper_topics = criteria.epaper_topics else - papers = criteria.epaper_topics.group_by(&:category) + epaper_topics = EPaperTopic.all + end + if params["category"].present? + papers = epaper_topics.where(:category_id => params["category"]).group_by(&:category) + else + papers = epaper_topics.group_by(&:category) end data = [] papers_sorted = get_all_categories.map do |v| @@ -92,8 +156,8 @@ class EPapersController < ApplicationController "title" => topic.title, "link_to_show" => OrbitHelper.url_to_show(topic.to_param), "description" => topic.description, - "img_url" => topic.image.url, - "img_url_thumb" => topic.image.thumb.url, + "img_url" => topic.image.url || EmptyImgUrl, + "img_url_thumb" => topic.image.thumb.url || EmptyImgUrl, "category" => category.title } end @@ -151,8 +215,8 @@ class EPapersController < ApplicationController "title" => topic.title, "link_to_show" => OrbitHelper.widget_item_url(topic.to_param), "description" => topic.description, - "img_url" => topic.image.url, - "img_url_thumb" => topic.image.thumb.url, + "img_url" => topic.image.url || EmptyImgUrl, + "img_url_thumb" => topic.image.thumb.url || EmptyImgUrl, "category" => (topic.category.title rescue nil), "link_to_show_wise" => OrbitHelper.widget_more_url + "/" + topic.to_param } @@ -183,8 +247,8 @@ class EPapersController < ApplicationController "title" => topic.title, "link_to_show" => OrbitHelper.widget_item_url(topic.to_param), "description" => topic.description, - "img_url" => topic.image.url, - "img_url_thumb" => topic.image.thumb.url, + "img_url" => topic.image.url || EmptyImgUrl, + "img_url_thumb" => topic.image.thumb.url || EmptyImgUrl, "category" => (category.title rescue nil) } end @@ -220,8 +284,8 @@ class EPapersController < ApplicationController "title" => topic.title, "link_to_show" => OrbitHelper.widget_item_url(topic.to_param), "description" => topic.description, - "img_url" => topic.image.url, - "img_url_thumb" => topic.image.thumb.url, + "img_url" => topic.image.url || EmptyImgUrl, + "img_url_thumb" => topic.image.thumb.url || EmptyImgUrl, "category" => (category.title rescue nil) } end diff --git a/app/views/e_papers/custom_widget_data.html.erb b/app/views/e_papers/custom_widget_data.html.erb new file mode 100644 index 0000000..8a03219 --- /dev/null +++ b/app/views/e_papers/custom_widget_data.html.erb @@ -0,0 +1,10 @@ +<% if @field_name == "page" %> +