add start time and end time block for searchbox

This commit is contained in:
chiu 2020-05-20 21:42:13 +08:00
parent 42dd72f06a
commit f9c368924b
4 changed files with 55 additions and 11 deletions

View File

@ -130,15 +130,34 @@ module AnnouncementsHelper
end end
fans fans
end end
def filter_by_keywords(sorted,keywords) def filter_by_keywords(sorted,keywords,stime,etime)
if !keywords.to_s.empty? kflag = keywords.blank?
sflag = stime.blank?
eflag = etime.blank?
stime = stime.to_s.split('/')
stime = Time.zone.local(*stime) rescue nil
etime = etime.to_s.split('/')
etime = Time.zone.local(*etime) rescue nil
if !kflag || !sflag || !eflag
sorted.select{|anns| sorted.select{|anns|
if kflag
flag = true
else
if anns["source-site"].present? if anns["source-site"].present?
title = Nokogiri::HTML(anns["title"].to_s).text title = Nokogiri::HTML(anns["title"].to_s).text
else else
title = Nokogiri::HTML(anns.title.to_s).text title = Nokogiri::HTML(anns.title.to_s).text
end end
title.include?(keywords.to_s) flag = title.include?(keywords.to_s)
end
if sflag && !eflag
flag = flag && (anns.postdate<=etime)
elsif !sflag && eflag
flag = flag && (anns.postdate>=stime)
elsif !sflag && !eflag
flag = flag && (anns.postdate>=stime) && (anns.postdate<=etime)
end
flag
} }
else else
sorted sorted
@ -201,9 +220,9 @@ module AnnouncementsHelper
else else
all_sorted = feeds_anns.select{|v| v['is_top']}.sort{|v1,v2| v2["postdate"]<=>v1["postdate"]} + feeds_anns.select{|v| v['is_top'] != true}.sort{|v1,v2| v2["postdate"]<=>v1["postdate"]} all_sorted = feeds_anns.select{|v| v['is_top']}.sort{|v1,v2| v2["postdate"]<=>v1["postdate"]} + feeds_anns.select{|v| v['is_top'] != true}.sort{|v1,v2| v2["postdate"]<=>v1["postdate"]}
end end
all_filter = filter_by_keywords(all_sorted,params[:keywords]) all_filter = filter_by_keywords(all_sorted,params[:keywords],params[:stime].params[:etime])
else else
all_filter = filter_by_keywords(announcements,params[:keywords]) all_filter = filter_by_keywords(announcements,params[:keywords],params[:stime],params[:etime])
end end
if page_data_count != 0 if page_data_count != 0
sorted = all_filter[(page_number-1)*page_data_count...page_number*page_data_count] sorted = all_filter[(page_number-1)*page_data_count...page_number*page_data_count]

View File

@ -30,7 +30,8 @@
input.search_box{ input.search_box{
margin: 0; margin: 0;
background: #a2c3df; background: #a2c3df;
color: #9100ff; font-weight: bold;
color: #00008b;
border-radius: 0.7em; border-radius: 0.7em;
outline: 0; outline: 0;
} }
@ -42,6 +43,18 @@
background: #7201ff; background: #7201ff;
color: white; color: white;
} }
input.search_box::-webkit-input-placeholder {
color: #aa58e8;
opacity: 1;
}
input.search_box:-moz-placeholder {
color: #aa58e8;
opacity: 1;
}
input.search_box::-moz-placeholder {
color: #aa58e8;
opacity: 1;
}
</style> </style>
<form> <form>
<% cats = Array(page.categories) <% cats = Array(page.categories)
@ -52,9 +65,16 @@
end end
all_cat = [[t('announcement.all'),'all']] all_cat = [[t('announcement.all'),'all']]
%> %>
<div class="search_widget" style="font-size: 1.2em;"> <div class="search_widget" style="display: flex;flex-wrap: wrap;font-size: 1.1em;">
<%= select_tag('category',options_for_select(all_cat.concat(cats.map{|v| [v.title,v.id.to_s]}),:selected => params['category'].to_s),:id=>"category_select_box",:prompt => t('announcement.select_prompt')) %> <%= select_tag('category',options_for_select(all_cat.concat(cats.map{|v| [v.title,v.id.to_s]}),:selected => params['category'].to_s),:id=>"category_select_box",:prompt => t('announcement.select_prompt')) %>
<input class="search_box" type="text" name="keywords" value="<%= params['keywords'] %>" placeholder="<%= t('announcement.keywords') %>"> <input class="search_box" type="text" name="keywords" value="<%= params['keywords'].to_s.gsub(/\"/,'') %>" placeholder="<%= t('announcement.keywords') %>">
<div class="default_picker">
<input class="search_box" type="text" name="stime" value="<%= params['stime'].to_s.gsub(/\"/,'') %>" placeholder="<%= t('announcement.stime') %>" data-format="yyyy/mm/dd">
</div>
~
<div class="default_picker">
<input class="search_box" type="text" name="etime" value="<%= params['etime'].to_s.gsub(/\"/,'') %>" placeholder="<%= t('announcement.etime') %>" data-format="yyyy/mm/dd">
</div>
<input class="search_box" type="submit" value="<%= t('announcement.search') %>"> <input class="search_box" type="submit" value="<%= t('announcement.search') %>">
</div> </div>
</form> </form>

View File

@ -3,6 +3,8 @@ en:
feed: Feed feed: Feed
import: Import import: Import
announcement: announcement:
stime: start time
etime: end time
select_prompt: --select category-- select_prompt: --select category--
all: All all: All
keywords: Keywords keywords: Keywords
@ -95,6 +97,7 @@ en:
bulletins_and_web_links: Differential Nav. bulletins_and_web_links: Differential Nav.
index: Index index: Index
search: Search search: Search
more: More
email_reminder: Email Reminder email_reminder: Email Reminder
activate_email_reminder: Activate Email Reminder activate_email_reminder: Activate Email Reminder
email_sentdate: Email Time email_sentdate: Email Time

View File

@ -3,6 +3,8 @@ zh_tw:
feed: 供給 feed: 供給
import: 匯入 import: 匯入
announcement: announcement:
stime: 開始時間
etime: 結束時間
select_prompt: --選取類別-- select_prompt: --選取類別--
all: 全部 all: 全部
keywords: 關鍵字 keywords: 關鍵字