From c39be9a84aa8fc5d44f1680c4fbcebb1f5acbc07 Mon Sep 17 00:00:00 2001 From: Bohung Date: Mon, 9 Aug 2021 12:22:45 +0800 Subject: [PATCH] Update import and export feature. --- app/helpers/admin/event_news_helper.rb | 17 +++++++++++-- app/models/event_news.rb | 2 +- .../admin/event_news/excel_format.xlsx.axlsx | 13 +++++++++- .../admin/event_news/export_excel.xlsx.axlsx | 24 ++++++++++++++++++- 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/app/helpers/admin/event_news_helper.rb b/app/helpers/admin/event_news_helper.rb index 5aaba9c..57a5c6a 100644 --- a/app/helpers/admin/event_news_helper.rb +++ b/app/helpers/admin/event_news_helper.rb @@ -132,8 +132,8 @@ module Admin::EventNewsHelper files.each_with_index do |file, i| bf = EventNewsFile.new bf.remote_file_url = file.strip rescue nil - bf.title_translations = {"en" => (desc_en[i] rescue ""), "zh_tw" => (desc_zh_tw[i] rescue "")} - bf.description_translations = {"en" => (alt_en[i] rescue ""), "zh_tw" => (alt_zh_tw[i] rescue "")} + bf.title_translations = {"en" => (alt_en[i] rescue ""), "zh_tw" => (alt_zh_tw[i] rescue "")} + bf.description_translations = {"en" => (desc_en[i] rescue ""), "zh_tw" => (desc_zh_tw[i] rescue "")} bf.event_news_id = anns.id bf.save end @@ -144,6 +144,19 @@ module Admin::EventNewsHelper value["zh_tw"] = val anns.place_translations = value.clone value = {} + when 33 + anns.event_end_date = val + when 34 + carousel_images = val.split(";") rescue [] + desc_en = row.cells[35].value.split(";") rescue [] + desc_zh_tw = row.cells[36].value.split(";") rescue [] + carousel_images.each_with_index do |image, i| + bc = EventCarouselImage.new + bc.remote_file_url = image.strip rescue nil + bc.description_translations = {"en" => (desc_en[i] rescue ""), "zh_tw" => (desc_zh_tw[i] rescue "")} + bc.event_news_id = anns.id + bc.save + end end end anns.create_user_id = current_user.id.to_s diff --git a/app/models/event_news.rb b/app/models/event_news.rb index 2d21575..b97754e 100644 --- a/app/models/event_news.rb +++ b/app/models/event_news.rb @@ -34,7 +34,7 @@ class EventNews field :update_user_id field :public, :type => Boolean, :default => true field :event_date , :type => DateTime, :default => Time.now - field :event_end_date , :type => DateTime, :default => Time.now + field :event_end_date , :type => DateTime field :postdate , :type => DateTime, :default => Time.now field :deadline , :type => DateTime field :rss2_sn diff --git a/app/views/admin/event_news/excel_format.xlsx.axlsx b/app/views/admin/event_news/excel_format.xlsx.axlsx index 3ad39b8..73c2063 100644 --- a/app/views/admin/event_news/excel_format.xlsx.axlsx +++ b/app/views/admin/event_news/excel_format.xlsx.axlsx @@ -148,7 +148,18 @@ wb.add_worksheet(name: "EventNewsModule") do |sheet| 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 diff --git a/app/views/admin/event_news/export_excel.xlsx.axlsx b/app/views/admin/event_news/export_excel.xlsx.axlsx index 60ecec9..532fb78 100644 --- a/app/views/admin/event_news/export_excel.xlsx.axlsx +++ b/app/views/admin/event_news/export_excel.xlsx.axlsx @@ -150,7 +150,18 @@ wb.add_worksheet(name: "EventNewsModule") do |sheet| 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 @@ -207,6 +218,17 @@ wb.add_worksheet(name: "EventNewsModule") do |sheet| 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 end