Update epaper email format.(Display different category's epaper in different block)
This commit is contained in:
parent
e838ad96bc
commit
4b7bc9ef8f
|
@ -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
|
|
@ -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,18 +169,22 @@
|
|||
</div>
|
||||
|
||||
<div class="ep-content">
|
||||
<% paper.epaper_topics.desc(:created_at).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;">
|
||||
<img src="<%= siteurl + "/" + topic.image.thumb.url %>" style="width: 100%;">
|
||||
</div>
|
||||
<div class="ep-con" style="width: 58%; float: right;">
|
||||
<% t = strip_tags(topic.content) %>
|
||||
<%= topic.description %>
|
||||
<a class="ep-content-more" href="<%= page + "/" + topic.to_param %>" target="_blank">more</a>
|
||||
</div>
|
||||
</div>
|
||||
<% 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;">
|
||||
<img src="<%= siteurl + "/" + topic.image.thumb.url %>" style="width: 100%;">
|
||||
</div>
|
||||
<div class="ep-con" style="width: 58%; float: right;">
|
||||
<% t = strip_tags(topic.content) %>
|
||||
<%= topic.description %>
|
||||
<a class="ep-content-more" href="<%= page + "/" + topic.to_param %>" target="_blank">more</a>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue