diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index 43966e0..6e12e86 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -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 diff --git a/app/helpers/announcements_helper.rb b/app/helpers/announcements_helper.rb index d7a1750..f2bd5fd 100644 --- a/app/helpers/announcements_helper.rb +++ b/app/helpers/announcements_helper.rb @@ -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