fix announcment sorting

This commit is contained in:
邱博亞 2024-11-16 11:25:13 +08:00
parent ae1fa38314
commit 5ed776b0ca
2 changed files with 10 additions and 13 deletions

View File

@ -613,13 +613,13 @@ class AnnouncementsController < ApplicationController
end end
if devide_flag if devide_flag
feeds_anns, _ = get_feed_announcements("widget",nil,cats,widget_data_count - top_anns.count) feeds_anns, _ = get_feed_announcements("widget",nil,cats,widget_data_count - top_anns.count)
top_anns += feeds_anns.select{|v| v['is_top'] == true} top_anns += feeds_anns.select{|v| v['is_top']}
top_anns = sort_announcements(top_anns) top_anns = sort_announcements(top_anns)
rest_count = widget_data_count - top_anns.count rest_count = widget_data_count - top_anns.count
if rest_count <= 0 if rest_count <= 0
anns = top_anns.take(widget_data_count) anns = top_anns.take(widget_data_count)
else else
rest_all_anns = feeds_anns.select{|v| v['is_top'] != true} + not_top_anns.take(rest_count) rest_all_anns = feeds_anns.select{|v| !v['is_top']} + not_top_anns.take(rest_count)
rest_anns = sort_announcements(rest_all_anns).take(rest_count) rest_anns = sort_announcements(rest_all_anns).take(rest_count)
anns = top_anns + rest_anns anns = top_anns + rest_anns
end end

View File

@ -160,10 +160,7 @@ module AnnouncementsHelper
feeds_anns, feeds_count = get_feed_announcements("index",params["source"],categories,page_number*page_data_count,extra_match_cond) feeds_anns, feeds_count = get_feed_announcements("index",params["source"],categories,page_number*page_data_count,extra_match_cond)
end end
if !feeds_anns.blank? if !feeds_anns.blank?
top_anns = announcements.select{|v| v.is_top} + feeds_anns.select{|v| v['is_top']} all_filter = sort_announcements(announcements + feeds_anns)
rest_all_anns = announcements.select{|v| !v.is_top} + feeds_anns.select{|v| v['is_top'] != true}
all_filter = sort_announcements(top_anns) + sort_announcements(rest_all_anns)
else else
all_filter = announcements all_filter = announcements
end end
@ -180,19 +177,19 @@ module AnnouncementsHelper
def sort_announcements(announcements) def sort_announcements(announcements)
if enable_manually_sort if enable_manually_sort
announcements = announcements.sort_by { |announcement| announcements = announcements.sort_by { |announcement|
tmp1 = announcement["postdate"].blank?
[ [
-announcement['sort_number'].to_i, (announcement['is_top'] ? 0 : 1),
tmp1 ? 0 : 1, tmp1 ? nil : announcement["postdate"].to_time announcement['sort_number'].to_i,
-announcement["postdate"].to_i
] ]
}.reverse }
else else
announcements = announcements.sort_by { |announcement| announcements = announcements.sort_by { |announcement|
tmp1 = announcement["postdate"].blank?
[ [
tmp1 ? 0 : 1, tmp1 ? nil : announcement["postdate"].to_time (announcement['is_top'] ? 0 : 1),
-announcement["postdate"].to_i
] ]
}.reverse }
end end
return announcements return announcements
end end