add start time and end time block for searchbox
This commit is contained in:
parent
42dd72f06a
commit
f9c368924b
|
@ -130,15 +130,34 @@ module AnnouncementsHelper
|
|||
end
|
||||
fans
|
||||
end
|
||||
def filter_by_keywords(sorted,keywords)
|
||||
if !keywords.to_s.empty?
|
||||
def filter_by_keywords(sorted,keywords,stime,etime)
|
||||
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|
|
||||
if anns["source-site"].present?
|
||||
title = Nokogiri::HTML(anns["title"].to_s).text
|
||||
if kflag
|
||||
flag = true
|
||||
else
|
||||
title = Nokogiri::HTML(anns.title.to_s).text
|
||||
if anns["source-site"].present?
|
||||
title = Nokogiri::HTML(anns["title"].to_s).text
|
||||
else
|
||||
title = Nokogiri::HTML(anns.title.to_s).text
|
||||
end
|
||||
flag = title.include?(keywords.to_s)
|
||||
end
|
||||
title.include?(keywords.to_s)
|
||||
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
|
||||
sorted
|
||||
|
@ -201,9 +220,9 @@ module AnnouncementsHelper
|
|||
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"]}
|
||||
end
|
||||
all_filter = filter_by_keywords(all_sorted,params[:keywords])
|
||||
all_filter = filter_by_keywords(all_sorted,params[:keywords],params[:stime].params[:etime])
|
||||
else
|
||||
all_filter = filter_by_keywords(announcements,params[:keywords])
|
||||
all_filter = filter_by_keywords(announcements,params[:keywords],params[:stime],params[:etime])
|
||||
end
|
||||
if page_data_count != 0
|
||||
sorted = all_filter[(page_number-1)*page_data_count...page_number*page_data_count]
|
||||
|
|
|
@ -30,7 +30,8 @@
|
|||
input.search_box{
|
||||
margin: 0;
|
||||
background: #a2c3df;
|
||||
color: #9100ff;
|
||||
font-weight: bold;
|
||||
color: #00008b;
|
||||
border-radius: 0.7em;
|
||||
outline: 0;
|
||||
}
|
||||
|
@ -42,6 +43,18 @@
|
|||
background: #7201ff;
|
||||
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>
|
||||
<form>
|
||||
<% cats = Array(page.categories)
|
||||
|
@ -52,9 +65,16 @@
|
|||
end
|
||||
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')) %>
|
||||
<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') %>">
|
||||
</div>
|
||||
</form>
|
||||
|
|
|
@ -3,6 +3,8 @@ en:
|
|||
feed: Feed
|
||||
import: Import
|
||||
announcement:
|
||||
stime: start time
|
||||
etime: end time
|
||||
select_prompt: --select category--
|
||||
all: All
|
||||
keywords: Keywords
|
||||
|
@ -95,6 +97,7 @@ en:
|
|||
bulletins_and_web_links: Differential Nav.
|
||||
index: Index
|
||||
search: Search
|
||||
more: More
|
||||
email_reminder: Email Reminder
|
||||
activate_email_reminder: Activate Email Reminder
|
||||
email_sentdate: Email Time
|
||||
|
|
|
@ -3,6 +3,8 @@ zh_tw:
|
|||
feed: 供給
|
||||
import: 匯入
|
||||
announcement:
|
||||
stime: 開始時間
|
||||
etime: 結束時間
|
||||
select_prompt: --選取類別--
|
||||
all: 全部
|
||||
keywords: 關鍵字
|
||||
|
|
Loading…
Reference in New Issue