This commit is contained in:
BoHung Chiu 2022-10-22 16:23:15 +08:00
parent ff58ec537e
commit 910a8278d3
2 changed files with 28 additions and 50 deletions

View File

@ -13,8 +13,7 @@ wb.add_worksheet(name: "EventNewsModule") do |sheet|
row << t("category")
row1 << "select"
t = ""
categories = @module_app.categories.asc(:created_at).to_a
categories_ids_map = categories.to_enum.with_index.map{|v,i| [v.id,i]}.to_h
categories = @module_app.categories.asc(:created_at)
categories.each_with_index do |cat,i|
t = t + "#{i}" + " -> " + cat.title + ", "
end
@ -28,8 +27,7 @@ wb.add_worksheet(name: "EventNewsModule") do |sheet|
row << t("tags")
row1 << "select"
t = ""
tags = @module_app.tags.asc(:created_at).to_a
tag_ids_map = tags.to_enum.with_index.map{|v,i| [v.id,i]}.to_h
tags = @module_app.tags.asc(:created_at)
tags.each_with_index do |tag,i|
t = t + "#{i}" + " -> " + tag.name + ", "
end
@ -167,27 +165,13 @@ wb.add_worksheet(name: "EventNewsModule") do |sheet|
sheet.add_row row, :style => heading
sheet.add_row row1
sheet.add_row row2, :style => example
tag_anns_map = Tagging.collection.aggregate([
{"$match" => {"taggable_id"=>{"$in"=>@event_news.pluck(:id)}}},
{"$group" => {"_id"=>"$taggable_id","children"=>{"$push"=>"$tag_id"}}}
]).map{|v| [v['_id'],v['children']]}.to_h
event_carousel_image_map = EventCarouselImage.collection.aggregate([
{"$sort" => {"created_at" => 1}},
{"$group" => {"_id"=>"$event_news_id","children"=>{"$push"=>"$$ROOT"}}}
]).map{|v| [v['_id'],v['children']]}.to_h
event_news_files_map = EventNewsFile.collection.aggregate([
{"$sort" => {"created_at" => 1}},
{"$group" => {"_id"=>"$event_news_id","children"=>{"$push"=>"$$ROOT"}}}
]).map{|v| [v['_id'],v['children']]}.to_h
event_news_links_map = EventNewsLink.collection.aggregate([
{"$sort" => {"created_at" => 1}},
{"$group" => {"_id"=>"$event_news_id","children"=>{"$push"=>"$$ROOT"}}}
]).map{|v| [v['_id'],v['children']]}.to_h
@event_news.each do |anns|
row = []
row << categories_ids_map[anns.category_id]
t = tag_anns_map[anns.id].to_a.map do |tag_id|
tag_ids_map[tag_id]
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 "")
@ -212,44 +196,38 @@ wb.add_worksheet(name: "EventNewsModule") do |sheet|
row << anns.notes_translations["en"]
row << anns.notes_translations["zh_tw"]
links = event_news_links_map[anns.id].to_a
t = links.collect{|l|l['url']}
links = anns.event_news_links.asc(:created_at)
t = links.collect{|l|l.url}
row << t.join(";")
t = links.collect{|l|l['title']["en"] rescue ''}
t = links.collect{|l|l.title_translations["en"]}
row << t.join(";")
t = links.collect{|l|l['title']["zh_tw"] rescue ''}
t = links.collect{|l|l.title_translations["zh_tw"]}
row << t.join(";")
files = event_news_files_map[anns.id].to_a
t = files.collect{|f| f['file'] ? nil : ("http://" + request.host_with_port + "/uploads/event_news_file/file/#{f['_id']}/#{f['file']}" rescue nil)}
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['file'] ? nil : l['description']["en"] rescue ''}
t.delete(nil)
t = files.collect{|l|l.description_translations["en"]}
row << t.join(";")
t = files.collect{|l| l['file'] ? nil : l['description']["zh_tw"] rescue ''}
t.delete(nil)
t = files.collect{|l|l.description_translations["zh_tw"]}
row << t.join(";")
t = files.collect{|l| l['file'] ? nil : l['title']["en"] rescue ''}
t.delete(nil)
t = files.collect{|l|l.title_translations["en"]}
row << t.join(";")
t = files.collect{|l| l['file'] ? nil : l['title']["zh_tw"] rescue ''}
t.delete(nil)
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 = event_carousel_image_map[anns.id].to_a
t = carousel_images.collect{|f| f['file'] ? nil : ("http://" + request.host_with_port + "/uploads/event_carousel_image/file/#{f['_id']}/#{f['file']}" rescue nil)}
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['file'] ? nil : l['description']["en"] rescue ''}
t.delete(nil)
t = carousel_images.collect{|l|l.description_translations["en"]}
row << t.join(";")
t = carousel_images.collect{|l| l['file'] ? nil : l['description']["zh_tw"] rescue ''}
t.delete(nil)
t = carousel_images.collect{|l|l.description_translations["zh_tw"]}
row << t.join(";")
sheet.add_row row
end

View File

@ -1,8 +1,8 @@
<% params = OrbitHelper.params
page = Page.where(url:params['url']).first
enable_search_flag = false
if page.methods.include? 'select_option_items'.to_sym
ModuleApp.all.select{|tmp| tmp.key.to_s=='event_news'}.each do |modile_app|
if page.respond_to?(:select_option_items)
ModuleApp.all.select{|tmp| tmp.key.to_s=='event_news_mod'}.each do |modile_app|
@show_option_items = modile_app.show_option_items rescue nil
end
page.select_option_items.each do |select_option_item|
@ -77,7 +77,7 @@
<input class="search_box" type="text" name="etime" value="<%= params['etime'].to_s.gsub(/\"/,'') %>" placeholder="<%= t('event_news.etime') %>" data-format="yyyy/mm/dd">
</div>
</div>
<input type="hidden" name="authenticity_token" value="<%= (0...46).map { ('a'..'z').to_a[rand(26)] }.join %>">
<input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>">
<input class="search_box" type="submit" value="<%= t('event_news.search') %>">
</div>
</form>