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
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 ""
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
render :json => {"success" => true}.to_json
end
@ -65,5 +84,12 @@ def initialize
def paper_criteria_params
params.require(:paper_criteria).permit!
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

View File

@ -1,6 +1,7 @@
<% paper = @data["paper"] %>
<% page = @data["page"] %>
<% siteurl = @data["siteurl"] %>
<% papers_data = @data["papers_data"] %>
<!DOCTYPE html>
<html>
<head>
@ -145,6 +146,17 @@
text-align: center;
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>
</head>
<body>
@ -157,7 +169,10 @@
</div>
<div class="ep-content">
<% paper.epaper_topics.desc(:created_at).each do |topic| %>
<% papers_data.each do |papers_data_hash| %>
<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>
<% topics = papers_data_hash["topics"] %>
<% topics.each do |topic| %>
<div class="ep-content-item">
<a class="ep-content-title" href="<%= page + "/" + topic.to_param %>" target="_blank"><%= topic.title %></a>
<div class="ep-img" style="width: 40%; float:left;">
@ -170,6 +185,7 @@
</div>
</div>
<% end %>
<% end %>
</div>
</div>