added postdate search filter in announcement

This commit is contained in:
Harry Bomrah 2018-01-18 20:40:56 +08:00
parent cf5c45cb34
commit 370f3fd325
1 changed files with 21 additions and 6 deletions

View File

@ -9,7 +9,6 @@ class AnnouncementsController < ApplicationController
if !params['tags'].blank? 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 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 else
if !params["source"].present? 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 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") feeds_anns = get_feed_announcements("index")
@ -34,18 +33,34 @@ class AnnouncementsController < ApplicationController
if params["keywords"].present? if params["keywords"].present?
sorted = sorted.find_all{|anns| sorted = sorted.find_all{|anns|
if anns["source-site"].present? if anns["source-site"].present?
/#{params[:keywords].to_s}/i.match anns["title"] /#{params[:keywords].to_s}/i.match anns["title"]
else else
/#{params[:keywords].to_s}/i.match anns.title /#{params[:keywords].to_s}/i.match anns.title
end 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 end
sorted = Kaminari.paginate_array(sorted).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count) rescue [] sorted = Kaminari.paginate_array(sorted).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count) rescue []
else else
announcements = top_anns + announcements 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} announcements = announcements.find_all{|anns| /#{params[:keywords].to_s}/i.match anns.title}
end 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 [] sorted = Kaminari.paginate_array(announcements).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count) rescue []
end end
total_pages = sorted.total_pages total_pages = sorted.total_pages