fix save file issue
This commit is contained in:
parent
1d03717714
commit
fd5d23a86c
|
|
@ -1,5 +1,25 @@
|
||||||
|
require 'rubyXL'
|
||||||
|
|
||||||
class Admin::EPaperSubscribersController < OrbitAdminController
|
class Admin::EPaperSubscribersController < OrbitAdminController
|
||||||
|
|
||||||
|
RackTempMiddleExist = defined?(Rack::TempfileReaper)
|
||||||
|
RACK_TEMPFILES = defined?(Rack::RACK_TEMPFILES) ? Rack::RACK_TEMPFILES : 'rack.tempfiles'
|
||||||
|
Is_Rails5 = (Rails.version.to_f >= 5)
|
||||||
|
|
||||||
|
if RackTempMiddleExist
|
||||||
|
if Is_Rails5
|
||||||
|
def fix_tempfile_reaper
|
||||||
|
request.set_header(RACK_TEMPFILES, [])
|
||||||
|
end
|
||||||
|
else
|
||||||
|
def fix_tempfile_reaper
|
||||||
|
env[RACK_TEMPFILES] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
def fix_tempfile_reaper; end
|
||||||
|
end
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
super
|
super
|
||||||
@app_title = "e_paper"
|
@app_title = "e_paper"
|
||||||
|
|
@ -12,21 +32,21 @@ class Admin::EPaperSubscribersController < OrbitAdminController
|
||||||
@filter_fields.delete(:status)
|
@filter_fields.delete(:status)
|
||||||
@filter_fields.delete(:category)
|
@filter_fields.delete(:category)
|
||||||
@filter_fields.delete(:tags)
|
@filter_fields.delete(:tags)
|
||||||
@subscribers = EPaperSubscriber.order_by(sort)
|
|
||||||
|
|
||||||
@subscribers = search_data(@subscribers,[:email]).page(params[:page]).per(10)
|
@subscribers = EPaperSubscriber.order_by(sort)
|
||||||
|
@subscribers = search_data(@subscribers, [:email]).page(params[:page]).per(10)
|
||||||
|
|
||||||
@thread = (params[:thread_id] ? Multithread.find(params[:thread_id]) : nil rescue nil)
|
@thread = (params[:thread_id] ? Multithread.find(params[:thread_id]) : nil rescue nil)
|
||||||
if @thread && @thread.status[:status] == 'finish'
|
if @thread && @thread.status[:status] == 'finish'
|
||||||
@thread = nil
|
@thread = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
render :partial => "index" if request.xhr?
|
render :partial => "index" if request.xhr?
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
subscriber = EPaperSubscriber.find(params[:id]) rescue nil
|
subscriber = EPaperSubscriber.find(params[:id]) rescue nil
|
||||||
if !subscriber.nil?
|
subscriber.destroy if subscriber
|
||||||
subscriber.destroy
|
|
||||||
end
|
|
||||||
redirect_to admin_e_paper_subscribers_path
|
redirect_to admin_e_paper_subscribers_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -34,89 +54,110 @@ class Admin::EPaperSubscribersController < OrbitAdminController
|
||||||
@epaper_subscribers = EPaperSubscriber.where(:email.nin=>[nil,""]).desc(:created_at)
|
@epaper_subscribers = EPaperSubscriber.where(:email.nin=>[nil,""]).desc(:created_at)
|
||||||
@subscribers = @epaper_subscribers.where(:subscribed.ne=>false)
|
@subscribers = @epaper_subscribers.where(:subscribed.ne=>false)
|
||||||
@unsubscribers = @epaper_subscribers.where(:subscribed=>false)
|
@unsubscribers = @epaper_subscribers.where(:subscribed=>false)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.xlsx {
|
format.xlsx {
|
||||||
response.headers['Content-Disposition'] = 'attachment; filename="'+Site.first.title+'-'+I18n.t('e_paper.e_paper')+'-'+I18n.t('e_paper.subscriber')+'.xlsx"'
|
response.headers['Content-Disposition'] =
|
||||||
|
'attachment; filename="' +
|
||||||
|
Site.first.title + '-' +
|
||||||
|
I18n.t('e_paper.e_paper') + '-' +
|
||||||
|
I18n.t('e_paper.subscriber') + '.xlsx"'
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_subscribers_modal
|
def get_subscribers_modal
|
||||||
@epaper_subscribers = EPaperSubscriber.where(:email.nin=>[nil,""]).desc(:created_at)
|
@epaper_subscribers = EPaperSubscriber.where(:email.nin=>[nil,""]).desc(:created_at)
|
||||||
@subscribers = @epaper_subscribers.where(:subscribed.ne=>false)
|
@subscribers = @epaper_subscribers.where(:subscribed.ne=>false)
|
||||||
@unsubscribers = @epaper_subscribers.where(:subscribed=>false)
|
@unsubscribers = @epaper_subscribers.where(:subscribed=>false)
|
||||||
render :partial => 'modal_select', :layout => false
|
render :partial => 'modal_select', :layout => false
|
||||||
end
|
end
|
||||||
|
|
||||||
def import_from_excel
|
def import_from_excel
|
||||||
thread = Multithread.where(:key=>'import_epaper_subscribers').first
|
thread = Multithread.where(:key=>'import_epaper_subscribers').first
|
||||||
if thread.nil?
|
if thread.nil?
|
||||||
thread = Multithread.create(:key=>'import_epaper_subscribers',:status=>{:status=>'Processing'})
|
thread = Multithread.create(:key=>'import_epaper_subscribers', :status=>{:status=>'Processing'})
|
||||||
else
|
else
|
||||||
thread.update(:status=>{:status=>'Processing'})
|
thread.update(:status=>{:status=>'Processing'})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
file = params["import_file"]
|
||||||
|
tempfile = file.tempfile
|
||||||
|
|
||||||
|
ObjectSpace.undefine_finalizer(tempfile)
|
||||||
|
fix_tempfile_reaper
|
||||||
|
|
||||||
Thread.new do
|
Thread.new do
|
||||||
workbook = RubyXL::Parser.parse(params["import_file"].tempfile)
|
workbook = RubyXL::Parser.parse(tempfile)
|
||||||
|
|
||||||
subscribe_sheet = workbook['Subscribe']
|
subscribe_sheet = workbook['Subscribe']
|
||||||
unsubscribe_sheet = workbook['Unsubscribe']
|
unsubscribe_sheet = workbook['Unsubscribe']
|
||||||
all_count = (subscribe_sheet ? (subscribe_sheet.count - 1) : 0) + (unsubscribe_sheet ? (unsubscribe_sheet.count - 1) : 0)
|
|
||||||
|
all_count =
|
||||||
|
(subscribe_sheet ? (subscribe_sheet.count - 1) : 0) +
|
||||||
|
(unsubscribe_sheet ? (unsubscribe_sheet.count - 1) : 0)
|
||||||
|
|
||||||
puts_every_count = [all_count * 3 / 100, 1].max
|
puts_every_count = [all_count * 3 / 100, 1].max
|
||||||
current_count = 0
|
current_count = 0
|
||||||
finish_percent = 0
|
finish_percent = 0
|
||||||
thread.update(:status=>{:status=>'Importing','all_count'=>all_count,'current_count'=>current_count,'finish_percent'=>finish_percent})
|
|
||||||
|
thread.update(
|
||||||
|
:status=>{
|
||||||
|
:status=>'Importing',
|
||||||
|
'all_count'=>all_count,
|
||||||
|
'current_count'=>current_count,
|
||||||
|
'finish_percent'=>finish_percent
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
if subscribe_sheet
|
||||||
subscribe_sheet.each_with_index do |row, i|
|
subscribe_sheet.each_with_index do |row, i|
|
||||||
next if i < 1
|
next if i < 1
|
||||||
c0 = row.cells[0]
|
email = row.cells[0]&.value
|
||||||
c1 = row.cells[1]
|
next if email.blank?
|
||||||
if c0
|
|
||||||
email = c0.value
|
subscriber = EPaperSubscriber.where(:email=>email).first || EPaperSubscriber.new(:email=>email)
|
||||||
if email.present?
|
|
||||||
subscriber = EPaperSubscriber.where(:email=>email).first
|
|
||||||
if subscriber.nil?
|
|
||||||
subscriber = EPaperSubscriber.new(:email=>email)
|
|
||||||
end
|
|
||||||
language = c1.value
|
|
||||||
if language.blank?
|
|
||||||
language = I18n.locale.to_s
|
|
||||||
end
|
|
||||||
subscriber.subscribed = true
|
subscriber.subscribed = true
|
||||||
subscriber.language = language
|
subscriber.language = row.cells[1]&.value.presence || I18n.locale.to_s
|
||||||
subscriber.save
|
subscriber.save
|
||||||
end
|
|
||||||
end
|
|
||||||
current_count += 1
|
current_count += 1
|
||||||
if current_count % puts_every_count == 0
|
if current_count % puts_every_count == 0
|
||||||
finish_percent = (current_count * 100.0 / all_count).round(1)
|
finish_percent = (current_count * 100.0 / all_count).round(1)
|
||||||
thread.update(:status=>{:status=>'Importing','all_count'=>all_count,'current_count'=>current_count,'finish_percent'=>finish_percent})
|
thread.update(:status=>{:status=>'Importing','all_count'=>all_count,'current_count'=>current_count,'finish_percent'=>finish_percent})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if unsubscribe_sheet
|
||||||
unsubscribe_sheet.each_with_index do |row, i|
|
unsubscribe_sheet.each_with_index do |row, i|
|
||||||
next if i < 1
|
next if i < 1
|
||||||
c0 = row.cells[0]
|
email = row.cells[0]&.value
|
||||||
c1 = row.cells[1]
|
next if email.blank?
|
||||||
if c0
|
|
||||||
email = c0.value
|
subscriber = EPaperSubscriber.where(:email=>email).first || EPaperSubscriber.new(:email=>email)
|
||||||
if email.present?
|
|
||||||
subscriber = EPaperSubscriber.where(:email=>email).first
|
|
||||||
if subscriber.nil?
|
|
||||||
subscriber = EPaperSubscriber.new(:email=>email)
|
|
||||||
end
|
|
||||||
language = c1.value
|
|
||||||
if language.blank?
|
|
||||||
language = I18n.locale.to_s
|
|
||||||
end
|
|
||||||
subscriber.subscribed = false
|
subscriber.subscribed = false
|
||||||
subscriber.language = language
|
subscriber.language = row.cells[1]&.value.presence || I18n.locale.to_s
|
||||||
subscriber.save
|
subscriber.save
|
||||||
end
|
|
||||||
end
|
|
||||||
current_count += 1
|
current_count += 1
|
||||||
if current_count % puts_every_count == 0
|
if current_count % puts_every_count == 0
|
||||||
finish_percent = (current_count * 100.0 / all_count).round(1)
|
finish_percent = (current_count * 100.0 / all_count).round(1)
|
||||||
thread.update(:status=>{:status=>'Importing','all_count'=>all_count,'current_count'=>current_count,'finish_percent'=>finish_percent})
|
thread.update(:status=>{:status=>'Importing','all_count'=>all_count,'current_count'=>current_count,'finish_percent'=>finish_percent})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
finish_percent = 100
|
|
||||||
thread.update(:status=>{:status=>'finish','all_count'=>all_count,'current_count'=>current_count,'finish_percent'=>finish_percent})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
thread.update(
|
||||||
|
:status=>{
|
||||||
|
:status=>'finish',
|
||||||
|
'all_count'=>all_count,
|
||||||
|
'current_count'=>current_count,
|
||||||
|
'finish_percent'=>100
|
||||||
|
}
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
redirect_to admin_e_paper_subscribers_path(thread_id: thread.id)
|
redirect_to admin_e_paper_subscribers_path(thread_id: thread.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -125,45 +166,82 @@ class Admin::EPaperSubscribersController < OrbitAdminController
|
||||||
@unsubscribers = []
|
@unsubscribers = []
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.xlsx {
|
format.xlsx {
|
||||||
response.headers['Content-Disposition'] = 'attachment; filename="'+Site.first.title+'-'+I18n.t('e_paper.e_paper')+'-'+I18n.t('e_paper.subscriber')+'excel_format.xlsx"'
|
response.headers['Content-Disposition'] =
|
||||||
|
'attachment; filename="' +
|
||||||
|
Site.first.title + '-' +
|
||||||
|
I18n.t('e_paper.e_paper') + '-' +
|
||||||
|
I18n.t('e_paper.subscriber') + 'excel_format.xlsx"'
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def batch_delete_subscribers
|
def batch_delete_subscribers
|
||||||
@thread = (params[:thread_id] ? Multithread.find(params[:thread_id]) : nil rescue nil)
|
@thread = (params[:thread_id] ? Multithread.find(params[:thread_id]) : nil rescue nil)
|
||||||
if @thread && @thread.status[:status] == 'finish'
|
if @thread && @thread.status[:status] == 'finish'
|
||||||
@thread = nil
|
@thread = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_subscribers
|
def delete_subscribers
|
||||||
subscriber_ids = params['subscriber_ids']
|
subscriber_ids = params['subscriber_ids']
|
||||||
|
|
||||||
thread = Multithread.where(:key=>'delete_epaper_subscribers').first
|
thread = Multithread.where(:key=>'delete_epaper_subscribers').first
|
||||||
if thread.nil?
|
if thread.nil?
|
||||||
thread = Multithread.create(:key=>'delete_epaper_subscriber',:status=>{:status=>'Processing'})
|
thread = Multithread.create(
|
||||||
|
:key=>'delete_epaper_subscribers',
|
||||||
|
:status=>{:status=>'Processing'}
|
||||||
|
)
|
||||||
else
|
else
|
||||||
thread.update(:status=>{:status=>'Processing'})
|
thread.update(:status=>{:status=>'Processing'})
|
||||||
end
|
end
|
||||||
if subscriber_ids
|
|
||||||
|
if subscriber_ids.present?
|
||||||
all_count = subscriber_ids.count
|
all_count = subscriber_ids.count
|
||||||
puts_every_count = [all_count * 3 / 100, 1].max
|
puts_every_count = [all_count * 3 / 100, 1].max
|
||||||
current_count = 0
|
current_count = 0
|
||||||
finish_percent = 0
|
finish_percent = 0
|
||||||
thread.update(:status=>{:status=>'Deleting','all_count'=>all_count,'current_count'=>current_count,'finish_percent'=>finish_percent})
|
|
||||||
|
thread.update(
|
||||||
|
:status=>{
|
||||||
|
:status=>'Deleting',
|
||||||
|
'all_count'=>all_count,
|
||||||
|
'current_count'=>current_count,
|
||||||
|
'finish_percent'=>finish_percent
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
Thread.new do
|
Thread.new do
|
||||||
EPaperSubscriber.where(:id.in=>subscriber_ids).to_a.each do |s|
|
EPaperSubscriber.where(:id.in=>subscriber_ids).to_a.each do |s|
|
||||||
s.destroy
|
s.destroy
|
||||||
current_count += 1
|
current_count += 1
|
||||||
|
|
||||||
if current_count % puts_every_count == 0
|
if current_count % puts_every_count == 0
|
||||||
finish_percent = (current_count * 100.0 / all_count).round(1)
|
finish_percent = (current_count * 100.0 / all_count).round(1)
|
||||||
thread.update(:status=>{:status=>'Deleting','all_count'=>all_count,'current_count'=>current_count,'finish_percent'=>finish_percent})
|
thread.update(
|
||||||
|
:status=>{
|
||||||
|
:status=>'Deleting',
|
||||||
|
'all_count'=>all_count,
|
||||||
|
'current_count'=>current_count,
|
||||||
|
'finish_percent'=>finish_percent
|
||||||
|
}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
finish_percent = 100
|
|
||||||
thread.update(:status=>{:status=>'finish','all_count'=>all_count,'current_count'=>current_count,'finish_percent'=>finish_percent})
|
thread.update(
|
||||||
|
:status=>{
|
||||||
|
:status=>'finish',
|
||||||
|
'all_count'=>all_count,
|
||||||
|
'current_count'=>current_count,
|
||||||
|
'finish_percent'=>100
|
||||||
|
}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
thread.update(:status=>{:status=>'finish'})
|
thread.update(:status=>{:status=>'finish'})
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_to admin_e_paper_subscribers_batch_delete_subscribers_path(thread_id: thread.id)
|
redirect_to admin_e_paper_subscribers_batch_delete_subscribers_path(thread_id: thread.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
class EPapersController < ApplicationController
|
class EPapersController < ApplicationController
|
||||||
FrontendMethods = ["papers", "topics"]
|
FrontendMethods = ["papers", "topics","showpaper"]
|
||||||
EmptyImg = "data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA="
|
EmptyImg = "data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA="
|
||||||
EmptyImgUrl = "#{EmptyImg}\" style=\"display: none;"
|
EmptyImgUrl = "#{EmptyImg}\" style=\"display: none;"
|
||||||
def self.custom_widget_data
|
def self.custom_widget_data
|
||||||
|
|
@ -91,7 +91,7 @@ class EPapersController < ApplicationController
|
||||||
{
|
{
|
||||||
"title" => criteria.title,
|
"title" => criteria.title,
|
||||||
"description" => criteria.description,
|
"description" => criteria.description,
|
||||||
"link_to_show" => OrbitHelper.url_to_show(criteria.to_param) + "?method=topics"
|
"link_to_show" => OrbitHelper.url_to_show(criteria.to_param) + "?method=showpaper"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
{
|
{
|
||||||
|
|
@ -129,6 +129,23 @@ class EPapersController < ApplicationController
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def showpaper
|
||||||
|
params = OrbitHelper.params
|
||||||
|
if params[:uid].present?
|
||||||
|
criteria = PaperCriteria.where(:uid => params[:uid]).first
|
||||||
|
return if criteria.nil?
|
||||||
|
end
|
||||||
|
if criteria.banner_image.present?
|
||||||
|
banner_image = EPaperImage.find(criteria.banner_image).image.url
|
||||||
|
end
|
||||||
|
{
|
||||||
|
"title" => criteria.title,
|
||||||
|
"banner_image" => banner_image,
|
||||||
|
"content" => criteria.content,
|
||||||
|
"description" => criteria.description
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def topics
|
def topics
|
||||||
params = OrbitHelper.params
|
params = OrbitHelper.params
|
||||||
if params[:uid].present?
|
if params[:uid].present?
|
||||||
|
|
@ -197,7 +214,7 @@ class EPapersController < ApplicationController
|
||||||
{
|
{
|
||||||
"title" => criteria.title,
|
"title" => criteria.title,
|
||||||
"description" => criteria.description,
|
"description" => criteria.description,
|
||||||
"link_to_show" => OrbitHelper.widget_item_url(criteria.to_param) + "?method=topics"
|
"link_to_show" => OrbitHelper.widget_item_url(criteria.to_param) + "?method=showpaper"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
{
|
{
|
||||||
|
|
@ -263,7 +280,7 @@ class EPapersController < ApplicationController
|
||||||
{
|
{
|
||||||
"categories" => data,
|
"categories" => data,
|
||||||
"extras" => {
|
"extras" => {
|
||||||
"read_more" => OrbitHelper.widget_more_url + "?method=topics"
|
"read_more" => OrbitHelper.widget_more_url + "?method=showpaper"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
@ -300,7 +317,7 @@ class EPapersController < ApplicationController
|
||||||
{
|
{
|
||||||
"categories" => data,
|
"categories" => data,
|
||||||
"extras" => {
|
"extras" => {
|
||||||
"read_more" => OrbitHelper.widget_more_url + "?method=topics"
|
"read_more" => OrbitHelper.widget_more_url + "?method=showpaper"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
<%= render_view %>
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
<h1>{{title}}</h1>
|
||||||
|
<img src="{{banner_image}}"/>
|
||||||
|
<div>{{description}}</div>
|
||||||
|
<div>{{content}}</div>
|
||||||
Loading…
Reference in New Issue