This commit is contained in:
BoHung Chiu 2022-06-26 15:53:39 +08:00
parent f4c48ddf72
commit b7b5a74315
2 changed files with 8 additions and 3 deletions

View File

@ -180,15 +180,19 @@ class Admin::AnnouncementsController < OrbitAdminController
end end
end end
if update_flag if update_flag
@host = Site.first.root_url
if @host == "http"
@host = request.protocol + request.host_with_port
end
Thread.new do Thread.new do
begin begin
@announcements = Bulletin.all.desc(:created_at) @announcements = Bulletin.all.desc(:created_at)
last_updated = Bulletin.max(:updated_at).to_i last_updated = [Bulletin.max(:updated_at).to_i, AnnouncementSetting.max(:updated_at).to_i].max
filename = "public/announcement_export_#{last_updated}.xlsx" filename = "public/announcement_export_#{last_updated}.xlsx"
if File.exist?(filename) if File.exist?(filename)
@thread.update(:status=>{:status=>'finish','finish_percent'=>100,'info'=>I18n.t('announcement.read_from_cache')}) @thread.update(:status=>{:status=>'finish','finish_percent'=>100,'info'=>I18n.t('announcement.read_from_cache')})
else else
excel_contents = render_to_string( handlers: [:axlsx], formats: [:xlsx] ,partial: 'export_excel.xlsx',locals: {:@announcements=>@announcements,:@thread=>@thread} ) excel_contents = render_to_string( handlers: [:axlsx], formats: [:xlsx] ,partial: 'export_excel.xlsx',locals: {:@announcements=>@announcements,:@thread=>@thread, :@host=>@host} )
File.open(filename, 'w') do |f| File.open(filename, 'w') do |f|
f.write excel_contents f.write excel_contents
end end

View File

@ -143,7 +143,8 @@ wb.add_worksheet(name: "Annoucement") do |sheet|
row << (anns.is_top? ? 1 : 0) row << (anns.is_top? ? 1 : 0)
row << (anns.is_hot? ? 1 : 0) row << (anns.is_hot? ? 1 : 0)
row << (anns.is_hidden? ? 1 : 0) row << (anns.is_hidden? ? 1 : 0)
row << ("http://" + request.host_with_port + anns.image.url rescue "") image_url = anns.image.url rescue ""
row << (image_url.blank? ? "" : (@host + image_url))
row << anns.image_description_translations["en"] row << anns.image_description_translations["en"]
row << anns.image_description_translations["zh_tw"] row << anns.image_description_translations["zh_tw"]
row << anns.title_translations["en"] row << anns.title_translations["en"]