Update import and export feature.

This commit is contained in:
BoHung Chiu 2021-08-09 12:22:45 +08:00
parent 18c00013ea
commit c39be9a84a
4 changed files with 51 additions and 5 deletions

View File

@ -132,8 +132,8 @@ module Admin::EventNewsHelper
files.each_with_index do |file, i| files.each_with_index do |file, i|
bf = EventNewsFile.new bf = EventNewsFile.new
bf.remote_file_url = file.strip rescue nil bf.remote_file_url = file.strip rescue nil
bf.title_translations = {"en" => (desc_en[i] rescue ""), "zh_tw" => (desc_zh_tw[i] rescue "")} bf.title_translations = {"en" => (alt_en[i] rescue ""), "zh_tw" => (alt_zh_tw[i] rescue "")}
bf.description_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.event_news_id = anns.id
bf.save bf.save
end end
@ -144,6 +144,19 @@ module Admin::EventNewsHelper
value["zh_tw"] = val value["zh_tw"] = val
anns.place_translations = value.clone anns.place_translations = value.clone
value = {} 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
end end
anns.create_user_id = current_user.id.to_s anns.create_user_id = current_user.id.to_s

View File

@ -34,7 +34,7 @@ class EventNews
field :update_user_id field :update_user_id
field :public, :type => Boolean, :default => true field :public, :type => Boolean, :default => true
field :event_date , :type => DateTime, :default => Time.now 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 :postdate , :type => DateTime, :default => Time.now
field :deadline , :type => DateTime field :deadline , :type => DateTime
field :rss2_sn field :rss2_sn

View File

@ -148,7 +148,18 @@ wb.add_worksheet(name: "EventNewsModule") do |sheet|
row << t("event_news.place") + "-" + t("zh_tw") row << t("event_news.place") + "-" + t("zh_tw")
row1 << "textfield" row1 << "textfield"
row2 << "" 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 row, :style => heading
sheet.add_row row1 sheet.add_row row1
sheet.add_row row2, :style => example sheet.add_row row2, :style => example

View File

@ -150,7 +150,18 @@ wb.add_worksheet(name: "EventNewsModule") do |sheet|
row << t("event_news.place") + "-" + t("zh_tw") row << t("event_news.place") + "-" + t("zh_tw")
row1 << "textfield" row1 << "textfield"
row2 << "" 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 row, :style => heading
sheet.add_row row1 sheet.add_row row1
sheet.add_row row2, :style => example sheet.add_row row2, :style => example
@ -207,6 +218,17 @@ wb.add_worksheet(name: "EventNewsModule") do |sheet|
row << t.join(";") row << t.join(";")
row << anns.place_translations["en"] row << anns.place_translations["en"]
row << anns.place_translations["zh_tw"] 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 sheet.add_row row
end end