From 370f3fd325d3b4a390b09ebcfbec2f1045719dad Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Thu, 18 Jan 2018 20:40:56 +0800 Subject: [PATCH] added postdate search filter in announcement --- app/controllers/announcements_controller.rb | 27 ++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index fe121cf..7ce102e 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -9,7 +9,6 @@ class AnnouncementsController < ApplicationController if !params['tags'].blank? announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).and(:title.ne => nil).can_display.is_approved.filter_by_tags(params['tags']).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count).to_a else - if !params["source"].present? announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).and(:title.ne => nil, :is_top.ne => true).can_display.is_approved.filter_by_categories([],false).filter_by_tags.to_a feeds_anns = get_feed_announcements("index") @@ -34,18 +33,34 @@ class AnnouncementsController < ApplicationController if params["keywords"].present? sorted = sorted.find_all{|anns| if anns["source-site"].present? - /#{params[:keywords].to_s}/i.match anns["title"] - else - /#{params[:keywords].to_s}/i.match anns.title - end + /#{params[:keywords].to_s}/i.match anns["title"] + else + /#{params[:keywords].to_s}/i.match anns.title + end + } + end + if params["postdate"].present? + sorted = sorted.find_all{|anns| + if anns["source-site"].present? + /#{params[:postdate].to_s}/i.match anns["postdate"].strftime("%Y-%m") if !anns["postdate"].nil? + else + /#{params[:postdate].to_s}/i.match anns.postdate.strftime("%Y-%m") if !anns.postdate.nil? + end } end sorted = Kaminari.paginate_array(sorted).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count) rescue [] else announcements = top_anns + announcements - if params["keywords"].present? + if params["keywords"].present? announcements = announcements.find_all{|anns| /#{params[:keywords].to_s}/i.match anns.title} end + if params["postdate"].present? + announcements = announcements.find_all{|anns| + if !anns.postdate.nil? + /#{params[:postdate].to_s}/i.match anns.postdate.strftime("%Y-%m") + end + } + end sorted = Kaminari.paginate_array(announcements).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count) rescue [] end total_pages = sorted.total_pages