This commit is contained in:
chiu 2021-09-15 20:50:30 +08:00
parent e442c0060a
commit 945841a5fb
2 changed files with 19 additions and 15 deletions

View File

@ -138,6 +138,7 @@ class AnnouncementsController < ApplicationController
def pack_data(is_random=false) def pack_data(is_random=false)
cats = OrbitHelper.widget_categories || [] cats = OrbitHelper.widget_categories || []
tags = OrbitHelper.widget_tags || [] tags = OrbitHelper.widget_tags || []
tags = ['all'] if tags.blank?
subpart = OrbitHelper.get_current_widget subpart = OrbitHelper.get_current_widget
get_tabs_option get_tabs_option
anns = [] anns = []
@ -147,11 +148,11 @@ class AnnouncementsController < ApplicationController
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,'',is_random)
end end
else else
tags.each do |tag| tags.each do |tag|
anns = anns + get_anncs_for_pack_data(cats,[tag],tag) anns = anns + get_anncs_for_pack_data(cats,[tag],tag,is_random)
end end
use_tag = true use_tag = true
end end
@ -500,8 +501,8 @@ class AnnouncementsController < ApplicationController
anns = anns_cache.first.filter_result anns = anns_cache.first.filter_result
end end
if devide_flag if devide_flag
feeds_anns = get_feed_announcements("widget") feeds_anns = get_feed_announcements("widget",nil,cats,widget_data_count - top_anns.count)
top_anns = top_anns + feeds_anns.select{|v| v['is_top']} top_anns = top_anns + feeds_anns.select{|v| v['is_top'] == true}
top_anns = top_anns.sort_by { |a| tmp=a["postdate"].blank?;[tmp ? 0 : 1, tmp ? nil : a["postdate"].to_time] }.reverse top_anns = top_anns.sort_by { |a| tmp=a["postdate"].blank?;[tmp ? 0 : 1, tmp ? nil : a["postdate"].to_time] }.reverse
rest_count = widget_data_count - top_anns.count rest_count = widget_data_count - top_anns.count
if rest_count <= 0 if rest_count <= 0

View File

@ -85,15 +85,18 @@ module AnnouncementsHelper
"img_description" => desc "img_description" => desc
} }
end end
def get_feed_annc(type,site_source,locale) def get_feed_annc(type,site_source,locale,categories=nil)
ma_key = 'announcement' ma_key = 'announcement'
if type == "index" if categories.nil?
categories = Array(OrbitHelper.page_categories) if type == "index"
elsif type == "widget" categories = Array(OrbitHelper.page_categories)
categories = Array(OrbitHelper.widget_categories) elsif type == "widget"
else categories = Array(OrbitHelper.widget_categories)
categories = [] else
categories = []
end
end end
categories = ["all"] if categories.length==0
if categories.include?("all") if categories.include?("all")
feeds = SiteFeedAnnc.where(:channel_key => ma_key) feeds = SiteFeedAnnc.where(:channel_key => ma_key)
else else
@ -109,10 +112,10 @@ module AnnouncementsHelper
end end
data data
end end
def get_feed_announcements(type,site_source=nil) def get_feed_announcements(type,site_source=nil,categories=nil,max_len=nil)
locale = OrbitHelper.get_site_locale.to_s locale = OrbitHelper.get_site_locale.to_s
if !(defined? SiteFeedAnnc).nil? if !(defined? SiteFeedAnnc).nil?
fans = get_feed_annc(type,site_source,locale) fans = get_feed_annc(type,site_source,locale,categories)
else else
feed_anns = OrbitHelper.get_feed_for_module(type) feed_anns = OrbitHelper.get_feed_for_module(type)
fans = [] fans = []
@ -226,7 +229,7 @@ module AnnouncementsHelper
end end
if !(defined? SiteFeed).nil? if !(defined? SiteFeed).nil?
if @type != "show_widget" if @type != "show_widget"
feeds_anns = get_feed_announcements("index") feeds_anns = get_feed_announcements("index",nil,nil,page_number*page_data_count)
else else
feeds_anns = [] feeds_anns = []
end end
@ -234,7 +237,7 @@ module AnnouncementsHelper
else else
announcements = [] announcements = []
if @type != "show_widget" if @type != "show_widget"
feeds_anns = get_feed_announcements("index",params["source"]) feeds_anns = get_feed_announcements("index",params["source"],nil,page_number*page_data_count)
else else
feeds_anns = [] feeds_anns = []
end end