diff --git a/app/controllers/admin/e_paper_criterias_controller.rb b/app/controllers/admin/e_paper_criterias_controller.rb index 6b3fd4e..5067f49 100644 --- a/app/controllers/admin/e_paper_criterias_controller.rb +++ b/app/controllers/admin/e_paper_criterias_controller.rb @@ -47,8 +47,27 @@ def initialize def send_test_email paper_criteria = PaperCriteria.find(params[:id]) - 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 = paper_criteria.epaper_topics.group_by(&:category) + papers_data = [] + page = Page.where(:module => "e_paper").first.url rescue "" + 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 \ No newline at end of file diff --git a/app/views/admin/e_paper_criterias/emailer.html.erb b/app/views/admin/e_paper_criterias/emailer.html.erb index dcfacdc..492ffb2 100644 --- a/app/views/admin/e_paper_criterias/emailer.html.erb +++ b/app/views/admin/e_paper_criterias/emailer.html.erb @@ -1,6 +1,7 @@ <% paper = @data["paper"] %> <% page = @data["page"] %> <% siteurl = @data["siteurl"] %> +<% papers_data = @data["papers_data"] %>
@@ -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; + } @@ -157,18 +169,22 @@