From cf1888272e308b04a4dfac6ac67f3fc1245f60bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=9A=E4=BA=9E?= Date: Tue, 19 Nov 2024 08:30:04 +0800 Subject: [PATCH] fix announcment sorting --- app/controllers/announcements_controller.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index 6e12e86..237cdd7 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -229,14 +229,16 @@ class AnnouncementsController < ApplicationController end if @tab_option == 0 anns = get_anncs_for_pack_data(cats,tags,nil,is_random) + later_process = false else + later_process = true if cats.count != 1 || tags == ["all"] 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 else 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 use_tag = true end @@ -250,6 +252,7 @@ class AnnouncementsController < ApplicationController cats = ["all"] + cats end anns = sort_announcements(anns) + process_anns(anns) end cats = cats.uniq tags = tags.uniq @@ -545,7 +548,10 @@ class AnnouncementsController < ApplicationController 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? @annc_depts = [] @tmp_enable_annc_dept = (enable_annc_dept rescue false) @@ -624,7 +630,9 @@ class AnnouncementsController < ApplicationController anns = top_anns + rest_anns 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 end