epaper/app/controllers/admin/e_paper_criterias_controlle...

89 lines
3.3 KiB
Ruby
Raw Normal View History

require 'rake'
2019-05-28 15:54:32 +00:00
class Admin::EPaperCriteriasController < OrbitAdminController
def initialize
super
@app_title = "e_paper"
end
2024-11-15 10:20:00 +00:00
2019-05-28 15:54:32 +00:00
def index
@table_fields = [t('e_paper.criteria_title'),t('e_paper.date_span')]
@filter_fields = filter_fields([], @module_app.tags)
@filter_fields.delete(:status)
@filter_fields.delete(:categories)
@criterias = PaperCriteria.order_by(sort)
# .with_tags(filters("tags"))
2024-11-15 10:20:00 +00:00
2019-05-28 15:54:32 +00:00
@criterias = search_data(@criterias,[:title]).page(params[:page]).per(10)
#@url = "/" + I18n.locale.to_s + "/" +Page.where(:module => "e_paper").first.url + "?method=papers"
2024-11-15 10:20:00 +00:00
render :partial => "index" if request.xhr?
2019-05-28 15:54:32 +00:00
end
def new
@paper_criteria = PaperCriteria.new
end
def create
paper_criteria = PaperCriteria.create(paper_criteria_params)
redirect_to admin_e_paper_criterias_path
end
def edit
@paper_criteria = PaperCriteria.find(params[:id])
end
def update
paper_criteria = PaperCriteria.find(params[:id])
paper_criteria.update_attributes(paper_criteria_params)
redirect_to admin_e_paper_criterias_path
end
def destroy
paper_criteria = PaperCriteria.find(params[:id])
paper_criteria.destroy
redirect_to admin_e_paper_criterias_path
end
2024-11-15 10:20:00 +00:00
2019-05-28 15:54:32 +00:00
def send_test_email
paper_criteria = PaperCriteria.find(params[:id])
page = Page.where(:module => "e_paper").first.url rescue ""
2020-08-26 09:57:30 +00:00
papers_data = Admin::EpaperHelper.get_paper_data(paper_criteria)
2022-12-02 03:47:34 +00:00
email = Email.new(:mail_subject => paper_criteria.sending_title, :mail_lang => I18n.locale, :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], :module_app_key=>'e_paper')
2019-05-28 15:54:32 +00:00
email.deliver
render :json => {"success" => true}.to_json
end
def send_newsletter
Orbit::Application.load_tasks
2020-11-30 13:27:49 +00:00
rake = Rake::Task['epaper:send_email'].execute(OpenStruct.new({:paper_criteria_id => params[:id], :domain => request.host_with_port, :locale => I18n.locale.to_s}))
# rake = Rake::Task['epaper:send_email'].invoke([params[:id], request.host_with_port])
2020-08-28 12:49:47 +00:00
paper = PaperCriteria.find(params[:id]) rescue nil
if !paper.nil? && paper.invalid_emails.blank?
2024-09-15 02:22:04 +00:00
email_sentdate = paper.get_email_sentdate
if paper.get_email_sentdate
msg = I18n.t('e_paper.newsletter_will_be_sent', {time: email_sentdate.strftime("%Y-%m-%d %H:%M")})
else
msg = I18n.t('e_paper.newsletter_sent')
end
2024-11-15 10:20:00 +00:00
render :json => {"success" => true, "msg" => msg}.to_json
2020-08-28 12:49:47 +00:00
else
invalid_email_list = paper.invalid_emails rescue 'can not find paper'
render :json => {"success" => false,"invalid_emails"=>invalid_email_list}.to_json
end
end
def get_failed_emails
send_failed_emails = PaperCriteria.find(params[:id]).send_failed_emails rescue nil
render :json => {'data' => (send_failed_emails.blank? ? 'None' : send_failed_emails)}
end
def get_invalid_emails
invalid_emails = PaperCriteria.find(params[:id]).invalid_emails rescue nil
render :json => {'data' => (invalid_emails.blank? ? 'None' : invalid_emails)}
2019-05-28 15:54:32 +00:00
end
private
def paper_criteria_params
params.require(:paper_criteria).permit!
end
2024-11-15 10:20:00 +00:00
end