This commit is contained in:
BoHung Chiu 2021-04-09 17:45:58 +08:00
parent f6fc71ac72
commit d0331d58c1
2 changed files with 13 additions and 13 deletions

View File

@ -139,15 +139,15 @@ class AnnouncementsController < ApplicationController
anns = [] anns = []
use_tag = false use_tag = false
if @tab_option == 0 if @tab_option == 0
anns = get_anncs_for_pack_data(cats,tags,is_random) anns = get_anncs_for_pack_data(cats,tags,nil,is_random)
else else
if cats.count != 1 || tags == ["all"] if cats.count != 1 || tags == ["all"]
cats.each do |cat| cats.each do |cat|
anns = anns + get_anncs_for_pack_data([cat],tags) anns = anns + get_anncs_for_pack_data([cat],tags,'')
end end
else else
tags.each do |tag| tags.each do |tag|
anns = anns + get_anncs_for_pack_data(cats,[tag]) anns = anns + get_anncs_for_pack_data(cats,[tag],tag)
end end
use_tag = true use_tag = true
end end
@ -214,7 +214,7 @@ class AnnouncementsController < ApplicationController
nil nil
end end
end end
"<li class=\"filter_tab#{i == 0 ? ' active' : ''}\" data-count_limit=\"#{max_all_count}\" data-read_more_text=\"#{read_more_text}\" data-read_more=\"#{read_more_url}\" data-tags=\"#{tag}\">#{tags_translations[tag]}</li>" "<li class=\"filter_tab#{i == 0 ? ' active' : ''}\" #{(tag == 'all' && @all_setting_option == 0) ? "data-count_limit=\"#{max_all_count}\"" : ''} data-read_more_text=\"#{read_more_text}\" data-read_more=\"#{read_more_url}\" data-tags=\"#{tag}\">#{tags_translations[tag]}</li>"
}.join("") : cats.map.with_index{|cat,i| }.join("") : cats.map.with_index{|cat,i|
read_more_url = "/#{I18n.locale.to_s + page.url}" rescue "" read_more_url = "/#{I18n.locale.to_s + page.url}" rescue ""
read_more_url = read_more_url + "?" + {"category"=>(cat == 'all' ? all_cats : cat)}.to_param if read_more_url != "" read_more_url = read_more_url + "?" + {"category"=>(cat == 'all' ? all_cats : cat)}.to_param if read_more_url != ""
@ -454,7 +454,7 @@ class AnnouncementsController < ApplicationController
end end
end end
end end
def get_anncs_for_pack_data(cats,tags,is_random = false) def get_anncs_for_pack_data(cats,tags,set_tags=nil,is_random = false)
subpart = OrbitHelper.get_current_widget subpart = OrbitHelper.get_current_widget
widget_data_count = OrbitHelper.widget_data_count widget_data_count = OrbitHelper.widget_data_count
anns_cache = AnnsCache.where(parent_id: subpart.id.to_s + cats.to_s + tags.to_s + widget_data_count.to_s,locale: I18n.locale.to_s) anns_cache = AnnsCache.where(parent_id: subpart.id.to_s + cats.to_s + tags.to_s + widget_data_count.to_s,locale: I18n.locale.to_s)
@ -473,20 +473,20 @@ class AnnouncementsController < ApplicationController
end end
if devide_flag if devide_flag
now_anns = sorted_anns.to_a now_anns = sorted_anns.to_a
top_anns = now_anns.select{|v| v.is_top}.map{|v| data_to_human_type(v)} top_anns = now_anns.select{|v| v.is_top}.map{|v| data_to_human_type(v,set_tags)}
not_top_anns = now_anns.select{|v| !v.is_top}.map{|v| data_to_human_type(v)} not_top_anns = now_anns.select{|v| !v.is_top}.map{|v| data_to_human_type(v,set_tags)}
AnnsCache.create(parent_id: subpart.id.to_s + cats.to_s + tags.to_s + widget_data_count.to_s,locale: I18n.locale.to_s,filter_result: {top: top_anns,not_top: not_top_anns}) AnnsCache.create(parent_id: subpart.id.to_s + cats.to_s + tags.to_s + widget_data_count.to_s,locale: I18n.locale.to_s,filter_result: {top: top_anns,not_top: not_top_anns})
else else
anns = sorted_anns.map{|v| data_to_human_type(v)} anns = sorted_anns.map{|v| data_to_human_type(v,set_tags)}
AnnsCache.create(parent_id: subpart.id.to_s + cats.to_s + tags.to_s + widget_data_count.to_s,locale: I18n.locale.to_s,filter_result: anns) AnnsCache.create(parent_id: subpart.id.to_s + cats.to_s + tags.to_s + widget_data_count.to_s,locale: I18n.locale.to_s,filter_result: anns)
end end
else else
if devide_flag if devide_flag
anns = sorted_anns.sample(widget_data_count) anns = sorted_anns.sample(widget_data_count)
top_anns = anns.select{|v| v.is_top}.map{|v| data_to_human_type(v)} top_anns = anns.select{|v| v.is_top}.map{|v| data_to_human_type(v,set_tags)}
not_top_anns = anns.select{|v| !v.is_top}.map{|v| data_to_human_type(v)} not_top_anns = anns.select{|v| !v.is_top}.map{|v| data_to_human_type(v,set_tags)}
else else
anns = sorted_anns.sample(widget_data_count).map{|v| data_to_human_type(v)} anns = sorted_anns.sample(widget_data_count).map{|v| data_to_human_type(v,set_tags)}
end end
end end
elsif devide_flag elsif devide_flag

View File

@ -44,7 +44,7 @@ module AnnouncementsHelper
end end
end end
end end
def data_to_human_type(a) def data_to_human_type(a,set_tag_ids=nil)
statuses = a.statuses_with_classname.collect do |status| statuses = a.statuses_with_classname.collect do |status|
{ {
"status" => status["name"], "status" => status["name"],
@ -76,7 +76,7 @@ module AnnouncementsHelper
"subtitle" => a.subtitle, "subtitle" => a.subtitle,
"statuses" => statuses, "statuses" => statuses,
"category" => a.category.title, "category" => a.category.title,
"tag_ids" => (a.tag_ids.map{|id| id.to_s}.to_s.gsub('"',"'") rescue '[]'), "tag_ids" => (set_tag_ids.nil? ? (a.tag_ids.map{|id| id.to_s}.to_s.gsub('"',"'") rescue '[]') : set_tag_ids),
"postdate" => a.postdate, "postdate" => a.postdate,
"author" => author, "author" => author,
"link_to_show" => link_to_show, "link_to_show" => link_to_show,