From c04c906eb476cbf788e058fc9788c2fd292836f7 Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 8 Sep 2021 12:48:52 +0800 Subject: [PATCH] fix error --- app/controllers/announcements_controller.rb | 6 +++--- app/helpers/announcements_helper.rb | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index e8cdf98..68a7d75 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -164,7 +164,7 @@ class AnnouncementsController < ApplicationController else cats = ["all"] + cats end - anns = anns.sort_by { |a| [a["postdate"].blank? ? 1 : 0, a["postdate"].to_time] } + anns = anns.sort_by { |a| tmp=a["postdate"].blank?;[tmp ? 1 : 0, tmp ? nil : a["postdate"].to_time] } end cats = cats.uniq tags = tags.uniq @@ -502,13 +502,13 @@ class AnnouncementsController < ApplicationController 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] } + top_anns = top_anns.sort_by { |a| tmp=a["postdate"].blank?;[tmp ? 1 : 0, tmp ? nil : a["postdate"].to_time] } 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_anns = rest_all_anns.sort_by { |a| [a["postdate"].blank? ? 1 : 0, a["postdate"].to_time] }.take(rest_count) + rest_anns = rest_all_anns.sort_by { |a| tmp=a["postdate"].blank?;[tmp ? 1 : 0, tmp ? nil : a["postdate"].to_time] }.take(rest_count) anns = top_anns + rest_anns end end diff --git a/app/helpers/announcements_helper.rb b/app/helpers/announcements_helper.rb index 94bb7c4..6e9a719 100644 --- a/app/helpers/announcements_helper.rb +++ b/app/helpers/announcements_helper.rb @@ -243,10 +243,10 @@ module AnnouncementsHelper if announcements.count != 0 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_anns = rest_all_anns.sort_by { |a| [a["postdate"].blank? ? 1 : 0, a["postdate"].to_time] } - all_sorted = top_anns.sort_by { |a| [a["postdate"].blank? ? 1 : 0, a["postdate"].to_time] } + rest_anns + rest_anns = rest_all_anns.sort_by { |a| tmp=a["postdate"].blank?;[tmp ? 1 : 0, tmp ? nil : a["postdate"].to_time] } + all_sorted = top_anns.sort_by { |a| tmp=a["postdate"].blank?;[tmp ? 1 : 0, tmp ? nil : a["postdate"].to_time] } + rest_anns else - 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] } + all_sorted = feeds_anns.select{|v| v['is_top']}.sort_by { |a| tmp=a["postdate"].blank?;[tmp ? 1 : 0, tmp ? nil : a["postdate"].to_time] } + feeds_anns.select{|v| v['is_top'] != true}.sort_by { |a| tmp=a["postdate"].blank?;[tmp ? 1 : 0, tmp ? nil : a["postdate"].to_time] } end all_filter = filter_by_keywords(all_sorted,params[:keywords],params[:stime],params[:etime]) else