fix error for feed

This commit is contained in:
chiu 2021-09-08 12:42:25 +08:00
parent d2b9b86d35
commit 33bd85331f
2 changed files with 10 additions and 10 deletions

View File

@ -164,7 +164,7 @@ class AnnouncementsController < ApplicationController
else else
cats = ["all"] + cats cats = ["all"] + cats
end end
anns = anns.sort{|v1,v2| v2["postdate"]<=>v1["postdate"]} anns = anns.sort_by { |a| [a["postdate"].blank? ? 1 : 0, a["postdate"].to_time] }
end end
cats = cats.uniq cats = cats.uniq
tags = tags.uniq tags = tags.uniq
@ -500,16 +500,16 @@ 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")
top_anns = top_anns + feeds_anns.select{|v| v['is_top']}
top_anns = top_anns.sort_by { |a| [a["postdate"].blank? ? 1 : 0, a["postdate"].to_time] }
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 anns = top_anns.take(widget_data_count)
else else
feeds_anns = get_feed_announcements("widget")
top_anns = top_anns + feeds_anns.select{|v| v['is_top']}
top_anns = top_anns.sort{|v1,v2| v2["postdate"]<=>v1["postdate"]}
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'] != true} + not_top_anns.take(rest_count)
rest_anns = rest_all_anns.sort{|v1,v2| v2["postdate"]<=>v1["postdate"]}.take(rest_count) rest_anns = rest_all_anns.sort_by { |a| [a["postdate"].blank? ? 1 : 0, a["postdate"].to_time] }.take(rest_count)
anns = (top_anns + rest_anns).take(widget_data_count) anns = top_anns + rest_anns
end end
end end
anns.each{|a| a["postdate"] = a["postdate"].in_time_zone(Time.zone.utc_offset / 3600).strftime('%Y-%m-%d %H:%M') rescue nil } anns.each{|a| a["postdate"] = a["postdate"].in_time_zone(Time.zone.utc_offset / 3600).strftime('%Y-%m-%d %H:%M') rescue nil }

View File

@ -243,10 +243,10 @@ module AnnouncementsHelper
if announcements.count != 0 if announcements.count != 0
top_anns = announcements.select{|v| v.is_top} + feeds_anns.select{|v| v['is_top']} top_anns = announcements.select{|v| v.is_top} + feeds_anns.select{|v| v['is_top']}
rest_all_anns = feeds_anns.select{|v| v['is_top'] != true} + announcements.select{|v| !v.is_top} rest_all_anns = feeds_anns.select{|v| v['is_top'] != true} + announcements.select{|v| !v.is_top}
rest_anns = rest_all_anns.sort{|v1,v2| v2["postdate"]<=>v1["postdate"]} rest_anns = rest_all_anns.sort_by { |a| [a["postdate"].blank? ? 1 : 0, a["postdate"].to_time] }
all_sorted = top_anns.sort{|v1,v2| v2["postdate"]<=>v1["postdate"]} + rest_anns all_sorted = top_anns.sort_by { |a| [a["postdate"].blank? ? 1 : 0, a["postdate"].to_time] } + rest_anns
else else
all_sorted = feeds_anns.select{|v| v['is_top']}.sort{|v1,v2| v2["postdate"]<=>v1["postdate"]} + feeds_anns.select{|v| v['is_top'] != true}.sort{|v1,v2| v2["postdate"]<=>v1["postdate"]} all_sorted = feeds_anns.select{|v| v['is_top']}.sort_by { |a| [a["postdate"].blank? ? 1 : 0, a["postdate"].to_time] } + feeds_anns.select{|v| v['is_top'] != true}.sort_by { |a| [a["postdate"].blank? ? 1 : 0, a["postdate"].to_time] }
end end
all_filter = filter_by_keywords(all_sorted,params[:keywords],params[:stime],params[:etime]) all_filter = filter_by_keywords(all_sorted,params[:keywords],params[:stime],params[:etime])
else else