Fix bug(data split in index). Add paper criteria filter for index page.

This commit is contained in:
邱博亞 2022-12-08 23:42:02 +08:00
parent 103ea0311b
commit 75bec0fe3d
11 changed files with 142 additions and 43 deletions

View File

@ -1,15 +1,72 @@
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,
"img_url_thumb" => topic.image.thumb.url,
"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
{
"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
@ -20,9 +77,10 @@ class EPapersController < ApplicationController
"extras" => {
},
"total_pages" => (topics.count * 1.0 / OrbitHelper.page_data_count).ceil
"total_pages" => total_pages
}
end
end
def papers
params = OrbitHelper.params
@ -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
if params[:uid].present?
criteria = PaperCriteria.where(:uid => params[:uid]).first
if params["category"].present?
papers = criteria.epaper_topics.where(:category_id => params["category"]).group_by(&:category)
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

View File

@ -0,0 +1,10 @@
<% if @field_name == "page" %>
<div id="e_papers_data">
<div class="control-group input-content">
<label class="control-label muted" for="criteria_id"><%=t("e_paper.criteria_title")%> :</label>
<div class="controls">
<%= select_tag("#{@field_name}[custom_data_field][criteria_id]", options_for_select(([[t("e_paper.all_criteria"), "all"]] + PaperCriteria.all.desc(:start_date).map{|criteria| [criteria.title, criteria.id.to_s]}), (@custom_data_field["criteria_id"] rescue nil)), :id=>"criteria_id" )%>
</div>
</div>
</div>
<% end %>

View File

@ -4,6 +4,7 @@ en:
restful_actions:
batch_delete_subscribers: "Batch Delete Subscribers"
e_paper:
all_criteria: All Issue
show_progress: "Show Progress"
delete_subscribers_hint2: "Delete Subscribers below forever."
delete_subscribers_hint1: "Do you realy want to delete Subscribers you added forever?"
@ -32,7 +33,7 @@ en:
published: "Published"
subscribers: Subscribers
test_mail: Send Test Email
paper_criteria: ePaper Issue
paper_criteria: EPaper Issue
criteria_title: Issue Title
date_span: Article Date Range
new_criteria: New Issue

View File

@ -4,6 +4,7 @@ zh_tw:
restful_actions:
batch_delete_subscribers: "批次刪除訂閱者"
e_paper:
all_criteria: 所有電子報
show_progress: "顯示進度"
delete_subscribers_hint2: "永久刪除以下訂閱者"
delete_subscribers_hint1: "您確定真的要永久刪除所選的訂閱者嗎?"

View File

@ -18,7 +18,7 @@ module EPaper
base_url File.expand_path File.dirname(__FILE__)
#widget_methods ["criteria_list","category_wise_articles","latest_criteria", "latest_slider", "subscribe"]
widget_methods ["widget"]
widget_settings [{"data_count"=>30}]
widget_settings [{"data_count"=>30, "enable_custom_widget_data"=>true}]
taggable "EPaperCriteria"
categorizable
authorizable

View File

@ -1,7 +1,3 @@
<%= javascript_include_tag "plugin/owl.carousel.min.js"%>
<link rel="stylesheet" type="text/css" href="/assets/template/owl.carousel.min.css">
<link rel="stylesheet" type="text/css" href="/assets/template/owl.theme.default.min.css">
<div class="latest_slider" data-list="categories" data-level="0">
<div class="banner-Container owl-carousel owl-theme" data-list="topics" data-level="1">
<div class="item">

View File

@ -1,7 +1,3 @@
<%= javascript_include_tag "plugin/owl.carousel.min.js"%>
<link rel="stylesheet" type="text/css" href="/assets/template/owl.carousel.min.css">
<link rel="stylesheet" type="text/css" href="/assets/template/owl.theme.default.min.css">
<div class="latest-fullslider" data-list="categories" data-level="0">
<div class="banner-Container owl-carousel owl-theme" data-list="topics" data-level="1">
<div class="item">

View File

@ -20,3 +20,5 @@
</div>
</div>
{{pagination_goes_here}}

View File

@ -27,3 +27,4 @@
</div>
</div>
{{pagination_goes_here}}

View File

@ -0,0 +1,20 @@
<div class="latest-criteria epaper-index2" data-list="categories" data-level="0">
<h3><a href="{{category_link}}">{{category_title}}</a></h3>
<div data-list="topics" data-level="1">
<div class='epaper-index2-container row'>
<h4>
<a href="{{link_to_show}}">{{title}}</a>
<a href="{{link_to_show}}"><span>{{category_title}}</span></a>
</h4>
<div class="epaper-leftimg col-lg-5 col-xs-12">
<img src="{{img_url_thumb}}" alt="{{title}}">
</div>
<div class="epaper-rightContent col-lg-7 col-xs-12" >
<div class="epaper-description"><a href="{{link_to_show}}">{{description}}</a></div>
</div>
</div>
</div>
</div>
{{pagination_goes_here}}

View File

@ -12,7 +12,15 @@
"filename" : "epaper_index2",
"name" : {
"zh_tw" : "2. 電子報列表-title",
"en" : "1. Thumbnail ( widget-title, question )"
"en" : "2. Thumbnail ( widget-title, question )"
},
"thumbnail" : "thumb.png"
},
{
"filename" : "epaper_index2_latest",
"name" : {
"zh_tw" : "3. 電子報列表-latest",
"en" : "3. Thumbnail ( widget-title, question )"
},
"thumbnail" : "thumb.png"
}