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 = []
use_tag = false
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
if cats.count != 1 || tags == ["all"]
cats.each do |cat|
anns = anns + get_anncs_for_pack_data([cat],tags)
anns = anns + get_anncs_for_pack_data([cat],tags,'')
end
else
tags.each do |tag|
anns = anns + get_anncs_for_pack_data(cats,[tag])
anns = anns + get_anncs_for_pack_data(cats,[tag],tag)
end
use_tag = true
end
@ -214,7 +214,7 @@ class AnnouncementsController < ApplicationController
nil
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|
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 != ""
@ -454,7 +454,7 @@ class AnnouncementsController < ApplicationController
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
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)
@ -473,20 +473,20 @@ class AnnouncementsController < ApplicationController
end
if devide_flag
now_anns = sorted_anns.to_a
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)}
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,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})
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)
end
else
if devide_flag
anns = sorted_anns.sample(widget_data_count)
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)}
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,set_tags)}
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
elsif devide_flag

View File

@ -44,7 +44,7 @@ module AnnouncementsHelper
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|
{
"status" => status["name"],
@ -76,7 +76,7 @@ module AnnouncementsHelper
"subtitle" => a.subtitle,
"statuses" => statuses,
"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,
"author" => author,
"link_to_show" => link_to_show,