Add export and import and batch delete subscribers feature.
This commit is contained in:
1 parent
bb3236feba
commit
4735b107d7
12 files changed
+790
-2
No files matched your search
@@ -25,4 +25,87 @@ class Admin::EPaperSubscribersController < OrbitAdminController
|
||||
end
|
||||
redirect_to admin_e_paper_subscribers_path
|
||||
end
|
||||
|
||||
def export_excel
|
||||
@epaper_subscribers = EPaperSubscriber.where(:email.nin=>[nil,""]).desc(:created_at)
|
||||
@subscribers = @epaper_subscribers.where(:subscribed.ne=>false)
|
||||
@unsubscribers = @epaper_subscribers.where(:subscribed=>false)
|
||||
respond_to do |format|
|
||||
format.xlsx {
|
||||
response.headers['Content-Disposition'] = 'attachment; filename="'+Site.first.title+'-'+I18n.t('e_paper.e_paper')+'-'+I18n.t('e_paper.subscriber')+'.xlsx"'
|
||||
}
|
||||
end
|
||||
end
|
||||
def get_subscribers_modal
|
||||
@epaper_subscribers = EPaperSubscriber.where(:email.nin=>[nil,""]).desc(:created_at)
|
||||
@subscribers = @epaper_subscribers.where(:subscribed.ne=>false)
|
||||
@unsubscribers = @epaper_subscribers.where(:subscribed=>false)
|
||||
render :partial => 'modal_select', :layout => false
|
||||
end
|
||||
def import_from_excel
|
||||
workbook = RubyXL::Parser.parse(params["import_file"].tempfile)
|
||||
subscribe_sheet = workbook['Subscribe']
|
||||
unsubscribe_sheet = workbook['Unsubscribe']
|
||||
subscribe_sheet.each_with_index do |row, i|
|
||||
next if i < 1
|
||||
c0 = row.cells[0]
|
||||
c1 = row.cells[1]
|
||||
if c0
|
||||
email = c0.value
|
||||
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.language = language
|
||||
subscriber.save
|
||||
end
|
||||
end
|
||||
end
|
||||
unsubscribe_sheet.each_with_index do |row, i|
|
||||
next if i < 1
|
||||
c0 = row.cells[0]
|
||||
c1 = row.cells[1]
|
||||
if c0
|
||||
email = c0.value
|
||||
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.language = language
|
||||
subscriber.save
|
||||
end
|
||||
end
|
||||
end
|
||||
redirect_to admin_e_paper_subscribers_path
|
||||
end
|
||||
|
||||
def download_excel_format
|
||||
@subscribers = []
|
||||
@unsubscribers = []
|
||||
respond_to do |format|
|
||||
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
|
||||
|
||||
def delete_subscribers
|
||||
subscriber_ids = params['subscriber_ids']
|
||||
if subscriber_ids
|
||||
EPaperSubscriber.where(:id.in=>subscriber_ids).destroy
|
||||
end
|
||||
redirect_to admin_e_paper_subscribers_path
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user