Update epaper email format.(Display different category's epaper in different block)

This commit is contained in:
BoHung Chiu 2020-07-02 12:04:09 +08:00
parent e838ad96bc
commit 4b7bc9ef8f
2 changed files with 57 additions and 15 deletions

View File

@ -47,8 +47,27 @@ def initialize
def send_test_email def send_test_email
paper_criteria = PaperCriteria.find(params[:id]) paper_criteria = PaperCriteria.find(params[:id])
papers = paper_criteria.epaper_topics.group_by(&:category)
papers_data = []
page = Page.where(:module => "e_paper").first.url rescue "" page = Page.where(:module => "e_paper").first.url rescue ""
email = Email.new(:mail_subject => paper_criteria.sending_title, :mail_lang => :zh_tw, :template => "admin/e_paper_criterias/emailer", :template_data => {"paper" => paper_criteria, "page" => "http://" + request.host_with_port + page, "siteurl" => "http://" + request.host_with_port }, :mail_to => params[:email]) papers_sorted = get_all_categories.map do |v|
tmp = papers.select{|cat,topics| (cat.id==v.id rescue false)}
if tmp.count==0
tmp = nil
end
tmp
end.compact
papers_sorted.each do |paper|
paper.each do |category, topics|
topics_data = Array(topics).compact
papers_data << {
"category_title" => (category.title rescue nil),
"category" => category,
"topics" => topics_data
}
end
end
email = Email.new(:mail_subject => paper_criteria.sending_title, :mail_lang => :zh_tw, :template => "admin/e_paper_criterias/emailer", :template_data => {"paper" => paper_criteria, "page" => "http://" + request.host_with_port + page, "siteurl" => "http://" + request.host_with_port ,"papers_data" => papers_data }, :mail_to => params[:email])
email.deliver email.deliver
render :json => {"success" => true}.to_json render :json => {"success" => true}.to_json
end end
@ -65,5 +84,12 @@ def initialize
def paper_criteria_params def paper_criteria_params
params.require(:paper_criteria).permit! params.require(:paper_criteria).permit!
end end
def get_all_categories
app = ModuleApp.where(key: 'e_paper').first
asc_flag = app.asc rescue true
app.categories.enabled.sort_by do |category|
tmp = category.sort_number.to_i rescue 0
asc_flag ? tmp : -tmp
end
end
end end

View File

@ -1,6 +1,7 @@
<% paper = @data["paper"] %> <% paper = @data["paper"] %>
<% page = @data["page"] %> <% page = @data["page"] %>
<% siteurl = @data["siteurl"] %> <% siteurl = @data["siteurl"] %>
<% papers_data = @data["papers_data"] %>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
@ -145,6 +146,17 @@
text-align: center; text-align: center;
border-bottom: 1px solid #c8c8c8; border-bottom: 1px solid #c8c8c8;
} }
.category_title{
clear: both;
margin: 50px -15px 0;
background: #96210f;
padding: 20px 10px;
text-align: center;
font-weight: 700;
border-radius: 10px 10px 0 0;
width: 50%;
margin: 10px;
}
</style> </style>
</head> </head>
<body> <body>
@ -157,18 +169,22 @@
</div> </div>
<div class="ep-content"> <div class="ep-content">
<% paper.epaper_topics.desc(:created_at).each do |topic| %> <% papers_data.each do |papers_data_hash| %>
<div class="ep-content-item"> <h3 class="category_title"><a class="category_title_link" href="<%=page + "/#{paper.to_param}?method=topics&category=#{papers_data_hash["category"].id}" %>" style="color: #fff;text-decoration: none;"><%= papers_data_hash["category_title"] %></a></h3>
<a class="ep-content-title" href="<%= page + "/" + topic.to_param %>" target="_blank"><%= topic.title %></a> <% topics = papers_data_hash["topics"] %>
<div class="ep-img" style="width: 40%; float:left;"> <% topics.each do |topic| %>
<img src="<%= siteurl + "/" + topic.image.thumb.url %>" style="width: 100%;"> <div class="ep-content-item">
</div> <a class="ep-content-title" href="<%= page + "/" + topic.to_param %>" target="_blank"><%= topic.title %></a>
<div class="ep-con" style="width: 58%; float: right;"> <div class="ep-img" style="width: 40%; float:left;">
<% t = strip_tags(topic.content) %> <img src="<%= siteurl + "/" + topic.image.thumb.url %>" style="width: 100%;">
<%= topic.description %> </div>
<a class="ep-content-more" href="<%= page + "/" + topic.to_param %>" target="_blank">more</a> <div class="ep-con" style="width: 58%; float: right;">
</div> <% t = strip_tags(topic.content) %>
</div> <%= topic.description %>
<a class="ep-content-more" href="<%= page + "/" + topic.to_param %>" target="_blank">more</a>
</div>
</div>
<% end %>
<% end %> <% end %>
</div> </div>
</div> </div>