From 75267a21058fc1b6c28eaa8a4bf68b52e4ea3b79 Mon Sep 17 00:00:00 2001
From: rulingcom
Date: Thu, 28 May 2026 12:55:22 +0800
Subject: [PATCH] Fix export and view
---
.../admin/event_news_controller.rb | 5 +-
...el.xlsx.axlsx => _export_excel.xlsx.axlsx} | 510 +++++++++---------
app/views/admin/event_news/_form.html.erb | 3 +-
3 files changed, 259 insertions(+), 259 deletions(-)
rename app/views/admin/event_news/{export_excel.xlsx.axlsx => _export_excel.xlsx.axlsx} (97%)
diff --git a/app/controllers/admin/event_news_controller.rb b/app/controllers/admin/event_news_controller.rb
index f77f428..47e188a 100644
--- a/app/controllers/admin/event_news_controller.rb
+++ b/app/controllers/admin/event_news_controller.rb
@@ -123,14 +123,15 @@ class Admin::EventNewsController < OrbitAdminController
if update_flag
Thread.new do
begin
+ @module_app = ModuleApp.where(:key => 'event_news_mod').first
@event_news = EventNews.where(:category_id.ne=>nil).desc(:created_at)
last_updated = EventNews.max(:updated_at).to_i
filename = "public/event_news_export_#{last_updated}.xlsx"
if File.exist?(filename)
@thread.update(:status=>{:status=>'finish','finish_percent'=>100,'info'=>I18n.t('event_news.read_from_cache')})
else
- excel_contents = render_to_string( handlers: [:axlsx], formats: [:xlsx] , layout: false, template: 'admin/event_news/export_excel.xlsx', locals: {:@event_news=>@event_news,:@thread=>@thread} )
- File.open(filename, 'w') do |f|
+ excel_contents = render_to_string( handlers: [:axlsx], formats: [:xlsx] , partial: 'export_excel.xlsx' )
+ File.open(filename, 'wb') do |f|
f.write excel_contents
end
end
diff --git a/app/views/admin/event_news/export_excel.xlsx.axlsx b/app/views/admin/event_news/_export_excel.xlsx.axlsx
similarity index 97%
rename from app/views/admin/event_news/export_excel.xlsx.axlsx
rename to app/views/admin/event_news/_export_excel.xlsx.axlsx
index e0bc7eb..0abc586 100644
--- a/app/views/admin/event_news/export_excel.xlsx.axlsx
+++ b/app/views/admin/event_news/_export_excel.xlsx.axlsx
@@ -1,256 +1,256 @@
-# encoding: utf-8
-
-wb = xlsx_package.workbook
-
-wb.add_worksheet(name: "EventNewsModule") do |sheet|
-
- heading = sheet.styles.add_style(:b => true, :locked => true)
- example = sheet.styles.add_style(:i => true)
- row = []
- row1 = []
- row2 = []
-
- row << t("category")
- row1 << "select"
- t = ""
- categories = @module_app.categories.asc(:created_at)
- categories.each_with_index do |cat,i|
- t = t + "#{i}" + " -> " + cat.title + ", "
- end
- if categories.count > 0
- t = t + " Example : 0"
- else
- t = "Leave this field blank"
- end
- row2 << t
-
- row << t("tags")
- row1 << "select"
- t = ""
- tags = @module_app.tags.asc(:created_at)
- tags.each_with_index do |tag,i|
- t = t + "#{i}" + " -> " + tag.name + ", "
- end
- if tags.count > 0
- t = t + " Example : 0,1,2"
- else
- t = "Leave this field blank"
- end
- row2 << t
-
- row << t("event_news.event_date")
- row1 << "datetime"
- row2 << "Format: YYYY/MM/DD HH:mm, Example: 2015/12/10 15:20"
-
- row << t("event_news.start_date")
- row1 << "datetime"
- row2 << "Format: YYYY/MM/DD HH:mm, Example: 2015/12/10 15:30"
-
- row << t("event_news.end_date")
- row1 << "datetime"
- row2 << "Format: YYYY/MM/DD HH:mm, Example: 2015/12/12 17:30"
-
- row << t("top")
- row1 << "boolean"
- row2 << "0 for false, 1 for true"
-
- row << t("hot")
- row1 << "boolean"
- row2 << "0 for false, 1 for true"
-
- row << t("hide")
- row1 << "boolean"
- row2 << "0 for false, 1 for true "
-
- row << t("image")
- row1 << "url"
- row2 << "http://www.example.com/images/example.png"
-
- row << t("image") + " " + t("description") + " - " + t("en")
- row1 << "textfield"
- row2 << ""
- row << t("image") + " " + t("description") + " - " + t("zh_tw")
- row1 << "textfield"
- row2 << ""
-
- row << t("title") + " - " + t("en")
- row1 << "textfield"
- row2 << ""
- row << t("title") + " - " + t("zh_tw")
- row1 << "textfield"
- row2 << ""
-
- row << t("event_news.speaker") + " - " + t("en")
- row1 << "textfield"
- row2 << ""
- row << t("event_news.speaker") + " - " + t("zh_tw")
- row1 << "textfield"
- row2 << ""
-
- row << t("event_news.host") + " - " + t("en")
- row1 << "textfield"
- row2 << ""
- row << t("event_news.host") + " - " + t("zh_tw")
- row1 << "textfield"
- row2 << ""
-
- row << t("subtitle") + " - " + t("en")
- row1 << "textarea"
- row2 << ""
- row << t("subtitle") + " - " + t("zh_tw")
- row1 << "textarea"
- row2 << ""
-
- row << t("content") + " - " + t("en")
- row1 << "editor"
- row2 << ""
- row << t("content") + " - " + t("zh_tw")
- row1 << "editor"
- row2 << ""
-
- row << t("event_news.notes") + " - " + t("en")
- row1 << "editor"
- row2 << ""
- row << t("event_news.notes") + " - " + t("zh_tw")
- row1 << "editor"
- row2 << ""
-
- row << t("link")
- row1 << "textfield"
- row2 << "Seperate with ';'. Example: http://rulingcom.com; http://google.com"
-
- row << t("link") + " " + t("url_alt") + " - " + t("en")
- row1 << "textfield"
- row2 << "Seperate with ';' with respective to the links in the link columns. Example : Rulingcom official site; Google search engine"
- row << t("link") + " " + t("url_alt") + " - " + t("zh_tw")
- row1 << "textfield"
- row2 << "Seperate with ';' with respective to the links in the link columns. Example : Rulingcom official site; Google search engine"
-
- row << t("file_")
- row1 << "textfield"
- row2 << "Seperate with ';'. Example: http://www.example.com/images/example.png; http://www.example.com/images/example2.png"
-
- row << t("file_") + " " + t("description") + " - " + t("en")
- row1 << "textfield"
- row2 << "Seperate with ';' with respective to the links in the link columns. Example : Great view; Nice potrait"
- row << t("file_") + " " + t("description") + " - " + t("zh_tw")
- row1 << "textfield"
- row2 << "Seperate with ';' with respective to the links in the link columns. Example : Great view; Nice potrait"
-
- row << t("file_") + " " + t("alternative") + " - " + t("en")
- row1 << "textfield"
- row2 << "Seperate with ';' with respective to the links in the link columns. Example : example1; example2"
- row << t("file_") + " " + t("alternative") + " - " + t("zh_tw")
- row1 << "textfield"
- row2 << "Seperate with ';' with respective to the links in the link columns. Example : example1; example2"
-
- row << t("event_news.place") + "-" + t("en")
- row1 << "textfield"
- row2 << ""
- row << t("event_news.place") + "-" + t("zh_tw")
- row1 << "textfield"
- row2 << ""
- row << t("event_news.event_end_date")
- row1 << "datetime"
- row2 << "Format: YYYY/MM/DD HH:mm, Example: 2015/12/10 15:20"
- row << t("event_news.carousel_image") + "-" + t("image")
- row1 << "url"
- row2 << "Seperate with ';'. Example: http://www.example.com/images/example.png; http://www.example.com/images/example2.png"
- row << t("event_news.carousel_image") + "-" + t("description") + " - " + t("en")
- row1 << "textfield"
- row2 << "Seperate with ';' with respective to the links in the link columns. Example : Great view; Nice potrait"
- row << t("event_news.carousel_image") + "-" + t("description") + " - " + t("zh_tw")
- row1 << "textfield"
- row2 << "Seperate with ';' with respective to the links in the link columns. Example : Great view; Nice potrait"
- sheet.add_row row, :style => heading
- sheet.add_row row1
- sheet.add_row row2, :style => example
- if @thread
- all_count = @event_news.count
- puts_every_count = [all_count * 3 / 100, 1].max
- current_count = 0
- finish_percent = 0
- @thread.update(:status=>{:status=>'Processing','all_count'=>all_count,'current_count'=>current_count,'finish_percent'=>finish_percent})
- end
- @event_news.each do |anns|
- row = []
- row << categories.to_a.index(anns.category)
- t = []
- anns.tags.each do |tag|
- t << tags.to_a.index(tag)
- end
- row << t.join(",")
- row << (anns.event_date.strftime("%Y/%m/%d %H:%M") rescue "")
- row << (anns.postdate.strftime("%Y/%m/%d %H:%M") rescue "")
- row << (anns.deadline.strftime("%Y/%m/%d %H:%M") rescue "")
- row << (anns.is_top? ? 1 : 0)
- row << (anns.is_hot? ? 1 : 0)
- row << (anns.is_hidden? ? 1 : 0)
- row << ("http://" + request.host_with_port + anns.image.url rescue "")
- row << anns.image_description_translations["en"]
- row << anns.image_description_translations["zh_tw"]
- row << anns.title_translations["en"]
- row << anns.title_translations["zh_tw"]
- row << anns.speaker_translations["en"]
- row << anns.speaker_translations["zh_tw"]
- row << anns.host_translations["en"]
- row << anns.host_translations["zh_tw"]
- row << anns.subtitle_translations["en"]
- row << anns.subtitle_translations["zh_tw"]
- row << anns.text_translations["en"]
- row << anns.text_translations["zh_tw"]
- row << anns.notes_translations["en"]
- row << anns.notes_translations["zh_tw"]
-
- links = anns.event_news_links.asc(:created_at)
- t = links.collect{|l|l.url}
- row << t.join(";")
- t = links.collect{|l|l.title_translations["en"]}
- row << t.join(";")
- t = links.collect{|l|l.title_translations["zh_tw"]}
- row << t.join(";")
-
- files = anns.event_news_files.asc(:created_at)
- t = files.collect{|f|("http://" + request.host_with_port + f.file.url rescue nil)}
- t.delete(nil)
- row << t.join(";")
- t = files.collect{|l|l.description_translations["en"]}
- row << t.join(";")
- t = files.collect{|l|l.description_translations["zh_tw"]}
- row << t.join(";")
- t = files.collect{|l|l.title_translations["en"]}
- row << t.join(";")
- t = files.collect{|l|l.title_translations["zh_tw"]}
- row << t.join(";")
- row << anns.place_translations["en"]
- row << anns.place_translations["zh_tw"]
-
- row << (anns.event_end_date.strftime("%Y/%m/%d %H:%M") rescue "")
-
- carousel_images = anns.event_carousel_images.asc(:created_at)
- t = carousel_images.collect{|f|("http://" + request.host_with_port + f.file.url rescue nil)}
- t.delete(nil)
- row << t.join(";")
- t = carousel_images.collect{|l|l.description_translations["en"]}
- row << t.join(";")
- t = carousel_images.collect{|l|l.description_translations["zh_tw"]}
- row << t.join(";")
- sheet.add_row row
- if @thread
- current_count += 1
- if current_count % puts_every_count == 0
- finish_percent = (current_count * 100.0 / all_count).round(1)
- @thread.update(:status=>{:status=>'Processing','all_count'=>all_count,'current_count'=>current_count,'finish_percent'=>finish_percent})
- end
- end
- end
- if @thread
- finish_percent = 100
- @thread.update(:status=>{:status=>'finish','all_count'=>all_count,'current_count'=>current_count,'finish_percent'=>finish_percent})
- end
-
-
-
-
-
+# encoding: utf-8
+
+wb = xlsx_package.workbook
+
+wb.add_worksheet(name: "EventNewsModule") do |sheet|
+
+ heading = sheet.styles.add_style(:b => true, :locked => true)
+ example = sheet.styles.add_style(:i => true)
+ row = []
+ row1 = []
+ row2 = []
+
+ row << t("category")
+ row1 << "select"
+ t = ""
+ categories = @module_app.categories.asc(:created_at)
+ categories.each_with_index do |cat,i|
+ t = t + "#{i}" + " -> " + cat.title + ", "
+ end
+ if categories.count > 0
+ t = t + " Example : 0"
+ else
+ t = "Leave this field blank"
+ end
+ row2 << t
+
+ row << t("tags")
+ row1 << "select"
+ t = ""
+ tags = @module_app.tags.asc(:created_at)
+ tags.each_with_index do |tag,i|
+ t = t + "#{i}" + " -> " + tag.name + ", "
+ end
+ if tags.count > 0
+ t = t + " Example : 0,1,2"
+ else
+ t = "Leave this field blank"
+ end
+ row2 << t
+
+ row << t("event_news.event_date")
+ row1 << "datetime"
+ row2 << "Format: YYYY/MM/DD HH:mm, Example: 2015/12/10 15:20"
+
+ row << t("event_news.start_date")
+ row1 << "datetime"
+ row2 << "Format: YYYY/MM/DD HH:mm, Example: 2015/12/10 15:30"
+
+ row << t("event_news.end_date")
+ row1 << "datetime"
+ row2 << "Format: YYYY/MM/DD HH:mm, Example: 2015/12/12 17:30"
+
+ row << t("top")
+ row1 << "boolean"
+ row2 << "0 for false, 1 for true"
+
+ row << t("hot")
+ row1 << "boolean"
+ row2 << "0 for false, 1 for true"
+
+ row << t("hide")
+ row1 << "boolean"
+ row2 << "0 for false, 1 for true "
+
+ row << t("image")
+ row1 << "url"
+ row2 << "http://www.example.com/images/example.png"
+
+ row << t("image") + " " + t("description") + " - " + t("en")
+ row1 << "textfield"
+ row2 << ""
+ row << t("image") + " " + t("description") + " - " + t("zh_tw")
+ row1 << "textfield"
+ row2 << ""
+
+ row << t("title") + " - " + t("en")
+ row1 << "textfield"
+ row2 << ""
+ row << t("title") + " - " + t("zh_tw")
+ row1 << "textfield"
+ row2 << ""
+
+ row << t("event_news.speaker") + " - " + t("en")
+ row1 << "textfield"
+ row2 << ""
+ row << t("event_news.speaker") + " - " + t("zh_tw")
+ row1 << "textfield"
+ row2 << ""
+
+ row << t("event_news.host") + " - " + t("en")
+ row1 << "textfield"
+ row2 << ""
+ row << t("event_news.host") + " - " + t("zh_tw")
+ row1 << "textfield"
+ row2 << ""
+
+ row << t("subtitle") + " - " + t("en")
+ row1 << "textarea"
+ row2 << ""
+ row << t("subtitle") + " - " + t("zh_tw")
+ row1 << "textarea"
+ row2 << ""
+
+ row << t("content") + " - " + t("en")
+ row1 << "editor"
+ row2 << ""
+ row << t("content") + " - " + t("zh_tw")
+ row1 << "editor"
+ row2 << ""
+
+ row << t("event_news.notes") + " - " + t("en")
+ row1 << "editor"
+ row2 << ""
+ row << t("event_news.notes") + " - " + t("zh_tw")
+ row1 << "editor"
+ row2 << ""
+
+ row << t("link")
+ row1 << "textfield"
+ row2 << "Seperate with ';'. Example: http://rulingcom.com; http://google.com"
+
+ row << t("link") + " " + t("url_alt") + " - " + t("en")
+ row1 << "textfield"
+ row2 << "Seperate with ';' with respective to the links in the link columns. Example : Rulingcom official site; Google search engine"
+ row << t("link") + " " + t("url_alt") + " - " + t("zh_tw")
+ row1 << "textfield"
+ row2 << "Seperate with ';' with respective to the links in the link columns. Example : Rulingcom official site; Google search engine"
+
+ row << t("file_")
+ row1 << "textfield"
+ row2 << "Seperate with ';'. Example: http://www.example.com/images/example.png; http://www.example.com/images/example2.png"
+
+ row << t("file_") + " " + t("description") + " - " + t("en")
+ row1 << "textfield"
+ row2 << "Seperate with ';' with respective to the links in the link columns. Example : Great view; Nice potrait"
+ row << t("file_") + " " + t("description") + " - " + t("zh_tw")
+ row1 << "textfield"
+ row2 << "Seperate with ';' with respective to the links in the link columns. Example : Great view; Nice potrait"
+
+ row << t("file_") + " " + t("alternative") + " - " + t("en")
+ row1 << "textfield"
+ row2 << "Seperate with ';' with respective to the links in the link columns. Example : example1; example2"
+ row << t("file_") + " " + t("alternative") + " - " + t("zh_tw")
+ row1 << "textfield"
+ row2 << "Seperate with ';' with respective to the links in the link columns. Example : example1; example2"
+
+ row << t("event_news.place") + "-" + t("en")
+ row1 << "textfield"
+ row2 << ""
+ row << t("event_news.place") + "-" + t("zh_tw")
+ row1 << "textfield"
+ row2 << ""
+ row << t("event_news.event_end_date")
+ row1 << "datetime"
+ row2 << "Format: YYYY/MM/DD HH:mm, Example: 2015/12/10 15:20"
+ row << t("event_news.carousel_image") + "-" + t("image")
+ row1 << "url"
+ row2 << "Seperate with ';'. Example: http://www.example.com/images/example.png; http://www.example.com/images/example2.png"
+ row << t("event_news.carousel_image") + "-" + t("description") + " - " + t("en")
+ row1 << "textfield"
+ row2 << "Seperate with ';' with respective to the links in the link columns. Example : Great view; Nice potrait"
+ row << t("event_news.carousel_image") + "-" + t("description") + " - " + t("zh_tw")
+ row1 << "textfield"
+ row2 << "Seperate with ';' with respective to the links in the link columns. Example : Great view; Nice potrait"
+ sheet.add_row row, :style => heading
+ sheet.add_row row1
+ sheet.add_row row2, :style => example
+ if @thread
+ all_count = @event_news.count
+ puts_every_count = [all_count * 3 / 100, 1].max
+ current_count = 0
+ finish_percent = 0
+ @thread.update(:status=>{:status=>'Processing','all_count'=>all_count,'current_count'=>current_count,'finish_percent'=>finish_percent})
+ end
+ @event_news.each do |anns|
+ row = []
+ row << categories.to_a.index(anns.category)
+ t = []
+ anns.tags.each do |tag|
+ t << tags.to_a.index(tag)
+ end
+ row << t.join(",")
+ row << (anns.event_date.strftime("%Y/%m/%d %H:%M") rescue "")
+ row << (anns.postdate.strftime("%Y/%m/%d %H:%M") rescue "")
+ row << (anns.deadline.strftime("%Y/%m/%d %H:%M") rescue "")
+ row << (anns.is_top? ? 1 : 0)
+ row << (anns.is_hot? ? 1 : 0)
+ row << (anns.is_hidden? ? 1 : 0)
+ row << ("http://" + request.host_with_port + anns.image.url rescue "")
+ row << anns.image_description_translations["en"]
+ row << anns.image_description_translations["zh_tw"]
+ row << anns.title_translations["en"]
+ row << anns.title_translations["zh_tw"]
+ row << anns.speaker_translations["en"]
+ row << anns.speaker_translations["zh_tw"]
+ row << anns.host_translations["en"]
+ row << anns.host_translations["zh_tw"]
+ row << anns.subtitle_translations["en"]
+ row << anns.subtitle_translations["zh_tw"]
+ row << anns.text_translations["en"]
+ row << anns.text_translations["zh_tw"]
+ row << anns.notes_translations["en"]
+ row << anns.notes_translations["zh_tw"]
+
+ links = anns.event_news_links.asc(:created_at)
+ t = links.collect{|l|l.url}
+ row << t.join(";")
+ t = links.collect{|l|l.title_translations["en"]}
+ row << t.join(";")
+ t = links.collect{|l|l.title_translations["zh_tw"]}
+ row << t.join(";")
+
+ files = anns.event_news_files.asc(:created_at)
+ t = files.collect{|f|("http://" + request.host_with_port + f.file.url rescue nil)}
+ t.delete(nil)
+ row << t.join(";")
+ t = files.collect{|l|l.description_translations["en"]}
+ row << t.join(";")
+ t = files.collect{|l|l.description_translations["zh_tw"]}
+ row << t.join(";")
+ t = files.collect{|l|l.title_translations["en"]}
+ row << t.join(";")
+ t = files.collect{|l|l.title_translations["zh_tw"]}
+ row << t.join(";")
+ row << anns.place_translations["en"]
+ row << anns.place_translations["zh_tw"]
+
+ row << (anns.event_end_date.strftime("%Y/%m/%d %H:%M") rescue "")
+
+ carousel_images = anns.event_carousel_images.asc(:created_at)
+ t = carousel_images.collect{|f|("http://" + request.host_with_port + f.file.url rescue nil)}
+ t.delete(nil)
+ row << t.join(";")
+ t = carousel_images.collect{|l|l.description_translations["en"]}
+ row << t.join(";")
+ t = carousel_images.collect{|l|l.description_translations["zh_tw"]}
+ row << t.join(";")
+ sheet.add_row row
+ if @thread
+ current_count += 1
+ if current_count % puts_every_count == 0
+ finish_percent = (current_count * 100.0 / all_count).round(1)
+ @thread.update(:status=>{:status=>'Processing','all_count'=>all_count,'current_count'=>current_count,'finish_percent'=>finish_percent})
+ end
+ end
+ end
+ if @thread
+ finish_percent = 100
+ @thread.update(:status=>{:status=>'finish','all_count'=>all_count,'current_count'=>current_count,'finish_percent'=>finish_percent})
+ end
+
+
+
+
+
end
\ No newline at end of file
diff --git a/app/views/admin/event_news/_form.html.erb b/app/views/admin/event_news/_form.html.erb
index 0d956d0..5a9e7cd 100644
--- a/app/views/admin/event_news/_form.html.erb
+++ b/app/views/admin/event_news/_form.html.erb
@@ -378,7 +378,6 @@
<%= t(:add) %>
-
@@ -428,7 +427,7 @@
<% end %>
-
+