fix announcment sorting
This commit is contained in:
parent
ae1fa38314
commit
5ed776b0ca
|
@ -613,13 +613,13 @@ class AnnouncementsController < ApplicationController
|
|||
end
|
||||
if devide_flag
|
||||
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)
|
||||
rest_count = widget_data_count - top_anns.count
|
||||
if rest_count <= 0
|
||||
anns = top_anns.take(widget_data_count)
|
||||
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)
|
||||
anns = top_anns + rest_anns
|
||||
end
|
||||
|
|
|
@ -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)
|
||||
end
|
||||
if !feeds_anns.blank?
|
||||
top_anns = announcements.select{|v| v.is_top} + feeds_anns.select{|v| v['is_top']}
|
||||
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)
|
||||
all_filter = sort_announcements(announcements + feeds_anns)
|
||||
else
|
||||
all_filter = announcements
|
||||
end
|
||||
|
@ -180,19 +177,19 @@ module AnnouncementsHelper
|
|||
def sort_announcements(announcements)
|
||||
if enable_manually_sort
|
||||
announcements = announcements.sort_by { |announcement|
|
||||
tmp1 = announcement["postdate"].blank?
|
||||
[
|
||||
-announcement['sort_number'].to_i,
|
||||
tmp1 ? 0 : 1, tmp1 ? nil : announcement["postdate"].to_time
|
||||
(announcement['is_top'] ? 0 : 1),
|
||||
announcement['sort_number'].to_i,
|
||||
-announcement["postdate"].to_i
|
||||
]
|
||||
}.reverse
|
||||
}
|
||||
else
|
||||
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
|
||||
return announcements
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue