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") row << t("category")
row1 << "select" row1 << "select"
t = "" t = ""
categories = @module_app.categories.asc(:created_at).to_a categories = @module_app.categories.asc(:created_at)
categories_ids_map = categories.to_enum.with_index.map{|v,i| [v.id,i]}.to_h
categories.each_with_index do |cat,i| categories.each_with_index do |cat,i|
t = t + "#{i}" + " -> " + cat.title + ", " t = t + "#{i}" + " -> " + cat.title + ", "
end end
@ -28,8 +27,7 @@ wb.add_worksheet(name: "EventNewsModule") do |sheet|
row << t("tags") row << t("tags")
row1 << "select" row1 << "select"
t = "" t = ""
tags = @module_app.tags.asc(:created_at).to_a tags = @module_app.tags.asc(:created_at)
tag_ids_map = tags.to_enum.with_index.map{|v,i| [v.id,i]}.to_h
tags.each_with_index do |tag,i| tags.each_with_index do |tag,i|
t = t + "#{i}" + " -> " + tag.name + ", " t = t + "#{i}" + " -> " + tag.name + ", "
end end
@ -167,27 +165,13 @@ wb.add_worksheet(name: "EventNewsModule") do |sheet|
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
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| @event_news.each do |anns|
row = [] row = []
row << categories_ids_map[anns.category_id] row << categories.to_a.index(anns.category)
t = tag_anns_map[anns.id].to_a.map do |tag_id| t = []
tag_ids_map[tag_id] anns.tags.each do |tag|
t << tags.to_a.index(tag)
end end
row << t.join(",") row << t.join(",")
row << (anns.event_date.strftime("%Y/%m/%d %H:%M") rescue "") 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["en"]
row << anns.notes_translations["zh_tw"] row << anns.notes_translations["zh_tw"]
links = event_news_links_map[anns.id].to_a links = anns.event_news_links.asc(:created_at)
t = links.collect{|l|l['url']} t = links.collect{|l|l.url}
row << t.join(";") row << t.join(";")
t = links.collect{|l|l['title']["en"] rescue ''} t = links.collect{|l|l.title_translations["en"]}
row << t.join(";") row << t.join(";")
t = links.collect{|l|l['title']["zh_tw"] rescue ''} t = links.collect{|l|l.title_translations["zh_tw"]}
row << t.join(";") row << t.join(";")
files = event_news_files_map[anns.id].to_a files = anns.event_news_files.asc(:created_at)
t = files.collect{|f| f['file'] ? nil : ("http://" + request.host_with_port + "/uploads/event_news_file/file/#{f['_id']}/#{f['file']}" rescue nil)} t = files.collect{|f|("http://" + request.host_with_port + f.file.url rescue nil)}
t.delete(nil) t.delete(nil)
row << t.join(";") row << t.join(";")
t = files.collect{|l| l['file'] ? nil : l['description']["en"] rescue ''} t = files.collect{|l|l.description_translations["en"]}
t.delete(nil)
row << t.join(";") row << t.join(";")
t = files.collect{|l| l['file'] ? nil : l['description']["zh_tw"] rescue ''} t = files.collect{|l|l.description_translations["zh_tw"]}
t.delete(nil)
row << t.join(";") row << t.join(";")
t = files.collect{|l| l['file'] ? nil : l['title']["en"] rescue ''} t = files.collect{|l|l.title_translations["en"]}
t.delete(nil)
row << t.join(";") row << t.join(";")
t = files.collect{|l| l['file'] ? nil : l['title']["zh_tw"] rescue ''} t = files.collect{|l|l.title_translations["zh_tw"]}
t.delete(nil)
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 "") row << (anns.event_end_date.strftime("%Y/%m/%d %H:%M") rescue "")
carousel_images = event_carousel_image_map[anns.id].to_a carousel_images = anns.event_carousel_images.asc(:created_at)
t = carousel_images.collect{|f| f['file'] ? nil : ("http://" + request.host_with_port + "/uploads/event_carousel_image/file/#{f['_id']}/#{f['file']}" rescue nil)} t = carousel_images.collect{|f|("http://" + request.host_with_port + f.file.url rescue nil)}
t.delete(nil) t.delete(nil)
row << t.join(";") row << t.join(";")
t = carousel_images.collect{|l| l['file'] ? nil : l['description']["en"] rescue ''} t = carousel_images.collect{|l|l.description_translations["en"]}
t.delete(nil)
row << t.join(";") row << t.join(";")
t = carousel_images.collect{|l| l['file'] ? nil : l['description']["zh_tw"] rescue ''} t = carousel_images.collect{|l|l.description_translations["zh_tw"]}
t.delete(nil)
row << t.join(";") row << t.join(";")
sheet.add_row row sheet.add_row row
end end

View File

@ -1,8 +1,8 @@
<% params = OrbitHelper.params <% params = OrbitHelper.params
page = Page.where(url:params['url']).first page = Page.where(url:params['url']).first
enable_search_flag = false enable_search_flag = false
if page.methods.include? 'select_option_items'.to_sym if page.respond_to?(:select_option_items)
ModuleApp.all.select{|tmp| tmp.key.to_s=='event_news'}.each do |modile_app| 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 @show_option_items = modile_app.show_option_items rescue nil
end end
page.select_option_items.each do |select_option_item| 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"> <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>
</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') %>"> <input class="search_box" type="submit" value="<%= t('event_news.search') %>">
</div> </div>
</form> </form>