fix announcment sorting

This commit is contained in:
邱博亞 2024-11-19 08:30:04 +08:00
parent 5ed776b0ca
commit cf1888272e
1 changed files with 12 additions and 4 deletions

View File

@ -229,14 +229,16 @@ class AnnouncementsController < ApplicationController
end end
if @tab_option == 0 if @tab_option == 0
anns = get_anncs_for_pack_data(cats,tags,nil,is_random) anns = get_anncs_for_pack_data(cats,tags,nil,is_random)
later_process = false
else else
later_process = true
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,'',is_random) anns = anns + get_anncs_for_pack_data([cat],tags,'',is_random, later_process)
end end
else else
tags.each do |tag| tags.each do |tag|
anns = anns + get_anncs_for_pack_data(cats,[tag],tag,is_random) anns = anns + get_anncs_for_pack_data(cats,[tag],tag,is_random, later_process)
end end
use_tag = true use_tag = true
end end
@ -250,6 +252,7 @@ class AnnouncementsController < ApplicationController
cats = ["all"] + cats cats = ["all"] + cats
end end
anns = sort_announcements(anns) anns = sort_announcements(anns)
process_anns(anns)
end end
cats = cats.uniq cats = cats.uniq
tags = tags.uniq tags = tags.uniq
@ -545,7 +548,10 @@ class AnnouncementsController < ApplicationController
end end
end end
end end
def get_anncs_for_pack_data(cats,tags,set_tags=nil,is_random = false) def process_anns(anns)
anns.each{|a| a["postdate"] = a["postdate"].in_time_zone(Time.zone.utc_offset / 3600).strftime('%Y-%m-%d %H:%M') if a["postdate"] }
end
def get_anncs_for_pack_data(cats,tags,set_tags=nil,is_random = false,later_process=false)
if @annc_depts.nil? if @annc_depts.nil?
@annc_depts = [] @annc_depts = []
@tmp_enable_annc_dept = (enable_annc_dept rescue false) @tmp_enable_annc_dept = (enable_annc_dept rescue false)
@ -624,7 +630,9 @@ class AnnouncementsController < ApplicationController
anns = top_anns + rest_anns 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') if a["postdate"] } unless later_process
process_anns(anns)
end
anns anns
end end