bulletin search
This commit is contained in:
		
							parent
							
								
									7d077a92a5
								
							
						
					
					
						commit
						caf0426bd4
					
				|  | @ -13,6 +13,18 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController | ||||||
|     render :index |     render :index | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|  |   def search_result | ||||||
|  |       @search = Bulletin.solr_search do  | ||||||
|  |         fulltext params[:search_query] | ||||||
|  |         with(:frontend_search,true) | ||||||
|  |         with(:available_lang).any_of([I18n.locale.to_s]) | ||||||
|  |       end | ||||||
|  |       search_result =  @search.results.collect{|result| result.id} | ||||||
|  | 
 | ||||||
|  |       @bulletins = Bulletin.all.available_for_lang(I18n.locale).can_display.any_in(_id:search_result).page( params[:page_main]).per(@page_num) | ||||||
|  |       render 'index' | ||||||
|  |   end | ||||||
|  | 
 | ||||||
|   def index |   def index | ||||||
|     @item = Page.find(params[:page_id]) rescue nil |     @item = Page.find(params[:page_id]) rescue nil | ||||||
|     if @item |     if @item | ||||||
|  |  | ||||||
|  | @ -86,7 +86,7 @@ class Panel::Announcement::Widget::BulletinsController < OrbitWidgetController | ||||||
|   end |   end | ||||||
|    |    | ||||||
|   def bulletins_search_block |   def bulletins_search_block | ||||||
|      |     @part = PagePart.find params[:part_id] | ||||||
|   end |   end | ||||||
|    |    | ||||||
|   protected |   protected | ||||||
|  |  | ||||||
|  | @ -4,269 +4,26 @@ | ||||||
| 
 | 
 | ||||||
| <h1 class="h1"><%= @page.title rescue nil %></h1> | <h1 class="h1"><%= @page.title rescue nil %></h1> | ||||||
| 
 | 
 | ||||||
| <% if !@item.frontend_field.blank? %> |  | ||||||
| <% if @frontend_style == '1' %> |  | ||||||
| 
 |  | ||||||
| 	<div class="news news1"> |  | ||||||
| 		<table class="newstb" border="0" cellpadding="0" cellspacing="0" > |  | ||||||
| 		<thead> |  | ||||||
| 			<tr> |  | ||||||
| 				<% @item.frontend_field.each do |ff|  %> |  | ||||||
| 				<th><span class="<%= ff[1] %>"><%= t("announcement.bulletin.#{ff[0]}") if !ff[0].blank? %></span></th> |  | ||||||
| 				<% end %> |  | ||||||
| 			</tr> |  | ||||||
| 		</thead> |  | ||||||
| 		<% @bulletins.each do |post| %> |  | ||||||
| 			<tr class="<%= cycle('odd', '')%>"> |  | ||||||
| 			<% @item.frontend_field.each do |ff|  %> |  | ||||||
| 				<td> |  | ||||||
| 				<span class="<%= ff[1] %>"> |  | ||||||
| 				<% if ff[1] == 'title' %> |  | ||||||
| 					<%= link_to post.send("#{ff[0]}"), panel_announcement_front_end_bulletin_path(post, :category_id => post.send("#{post.class.to_s.underscore}_category_id")) %> |  | ||||||
| 				<% elsif ff[1] == 'date' %> |  | ||||||
| 					<%= display_date(post.send(ff[0])) %> |  | ||||||
| 				<% elsif ff[1] == 'category' %> |  | ||||||
| 					<%= post.send(ff[0]).title rescue nil %> |  | ||||||
| 				<% elsif ff[1] == 'img' %> |  | ||||||
| 					<div class="img app-pic"><%= image_tag(post.send(wf[0]).url) %></div> |  | ||||||
| 				<% elsif ff[1] == 'text' %> |  | ||||||
| 					<%#= post.send("#{ff[0]}[#{I18n.locale}]").html_safe %> |  | ||||||
| 					<%= post.send("#{ff[0]}").html_safe %> |  | ||||||
| 				<% elsif ff[1] == 'status' %> |  | ||||||
| 					<% if post.is_top? %> |  | ||||||
| 						<span class="top"><%= t(:top) %></span> |  | ||||||
| 					<% end %> |  | ||||||
| 					<% if post.is_hot? %> |  | ||||||
| 						<span class="hot"><%= t(:hot) %></span> |  | ||||||
| 					<% end %> |  | ||||||
| 				<% elsif ff[1] == 'link' %> |  | ||||||
| 				<% elsif ff[1] == 'file' %> |  | ||||||
| 				<% elsif ff[1] == 'tag' %> |  | ||||||
| 				<% elsif ff[1] == 'viewcount' %> |  | ||||||
| 					<%= dislpay_view_count(post) %> |  | ||||||
| 				<% elsif ff[1] == 'poster' %> |  | ||||||
| 					<%= User.from_id(post.update_user_id).name rescue ''%> |  | ||||||
| 				<% end %> |  | ||||||
| 				</span> |  | ||||||
| 				</td> |  | ||||||
| 			<% end %> |  | ||||||
| 			</tr> |  | ||||||
| 		<% end %> |  | ||||||
| 		</table> |  | ||||||
| 	</div> |  | ||||||
| 
 |  | ||||||
| <% elsif @frontend_style == '2' %> |  | ||||||
| 
 |  | ||||||
| 	<div class="news news2">	 |  | ||||||
| 		<ul class="newslist"> |  | ||||||
| 		<% @bulletins.each do |post| %> |  | ||||||
| 			<li class="<%= cycle('odd', '')%>"> |  | ||||||
| 				<div class="img app-pic"><%= image_tag(post.image.url) %></div> |  | ||||||
| 				 |  | ||||||
| 				<% @item.frontend_field.each do |ff|  %> |  | ||||||
| 				<span class="<%= ff[1] %>"> |  | ||||||
| 				<% if ff[1] == 'title' %> |  | ||||||
| 					<%= link_to post.title, panel_announcement_front_end_bulletin_path(post, :category_id => post.bulletin_category_id) %> |  | ||||||
| 				<% elsif ff[1] == 'date' %> |  | ||||||
| 					<%= display_date(post.send(ff[0])) %> |  | ||||||
| 				<% elsif ff[1] == 'category' %> |  | ||||||
| 					<%= post.send("#{post.class.to_s.underscore}_#{ff[0]}").title rescue nil %> |  | ||||||
| 				<% elsif ff[1] == 'text' %> |  | ||||||
| 					<%#= post.send("#{ff[0]}[#{I18n.locale}]").html_safe %> |  | ||||||
| 					<%= post.send("#{ff[0]}").html_safe %> |  | ||||||
| 				<% elsif ff[1] == 'status' %> |  | ||||||
| 					<% if post.is_top? %> |  | ||||||
| 						<span class="top"><%= t(:top) %></span> |  | ||||||
| 					<% end %> |  | ||||||
| 					<% if post.is_hot? %> |  | ||||||
| 						<span class="hot"><%= t(:hot) %></span> |  | ||||||
| 					<% end %> |  | ||||||
| 				<% elsif ff[1] == 'link' %> |  | ||||||
| 				<% elsif ff[1] == 'file' %> |  | ||||||
| 				<% elsif ff[1] == 'tag' %> |  | ||||||
| 				<% elsif ff[1] == 'viewcount' %> |  | ||||||
| 					<%= dislpay_view_count(post) %> |  | ||||||
| 				<% elsif ff[1] == 'poster' %> |  | ||||||
| 					<%= User.from_id(post.update_user_id).name rescue ''%> |  | ||||||
| 				<% end %> |  | ||||||
| 				</span> |  | ||||||
| 				<% end %> |  | ||||||
| 			</li> |  | ||||||
| 		<% end %> |  | ||||||
| 		</ul> |  | ||||||
| 	</div> |  | ||||||
| 
 |  | ||||||
| <% elsif @frontend_style == '3' %> |  | ||||||
| 
 |  | ||||||
| 	<div class="news news3">	 |  | ||||||
| 		<ul class="newslist"> |  | ||||||
| 		 |  | ||||||
| 		<% @bulletins.each do |post| %> |  | ||||||
| 			<li class="<%= cycle('odd', '')%>"> |  | ||||||
| 				<div class="img app-pic"><%= image_tag(post.image.url) %></div> |  | ||||||
| 				<div class="wrap"> |  | ||||||
| 					<% @item.frontend_field.each do |ff|  %> |  | ||||||
| 					<span class="<%= ff[1] %>"> |  | ||||||
| 					<% if ff[1] == 'title' %> |  | ||||||
| 						<%= link_to post.send("#{ff[0]}"), panel_announcement_front_end_bulletin_path(post, :category_id => post.send("#{post.class.to_s.underscore}_category_id")) %> |  | ||||||
| 					<% elsif ff[1] == 'date' %> |  | ||||||
| 						<%= display_date(post.send(ff[0])) %> |  | ||||||
| 					<% elsif ff[1] == 'category' %> |  | ||||||
| 						<%= post.send("#{post.class.to_s.underscore}_#{ff[0]}").title rescue nil %> |  | ||||||
| 					<% elsif ff[1] == 'text' %> |  | ||||||
| 						<%#= post.send("#{ff[0]}[#{I18n.locale}]").html_safe %> |  | ||||||
| 						<%= post.send("#{ff[0]}").html_safe %> |  | ||||||
| 					<% elsif ff[1] == 'status' %> |  | ||||||
| 						<% if post.is_top? %> |  | ||||||
| 							<span class="top"><%= t(:top) %></span> |  | ||||||
| 						<% end %> |  | ||||||
| 						<% if post.is_hot? %> |  | ||||||
| 							<span class="hot"><%= t(:hot) %></span> |  | ||||||
| 						<% end %> |  | ||||||
| 					<% elsif ff[1] == 'link' %> |  | ||||||
| 					<% elsif ff[1] == 'file' %> |  | ||||||
| 					<% elsif ff[1] == 'tag' %> |  | ||||||
| 					<% elsif ff[1] == 'viewcount' %> |  | ||||||
| 						<%= dislpay_view_count(post) %> |  | ||||||
| 					<% elsif ff[1] == 'poster' %> |  | ||||||
| 						<%= User.from_id(post.update_user_id).name rescue ''%> |  | ||||||
| 					<% end %> |  | ||||||
| 					</span> |  | ||||||
| 					<% end %> |  | ||||||
| 				</div> |  | ||||||
| 			</li> |  | ||||||
| 			<% end %> |  | ||||||
| 		</ul> |  | ||||||
| 		 |  | ||||||
| 	</div> |  | ||||||
| 
 |  | ||||||
| <% elsif @frontend_style == '4' %> |  | ||||||
| 
 |  | ||||||
| 	<div class="news news4">	 |  | ||||||
| 		<ul class="newslist"> |  | ||||||
| 		 |  | ||||||
| 		<% @bulletins.each do |post| %> |  | ||||||
| 			<li class="<%= cycle('odd', '')%>"> |  | ||||||
| 				<div class="img app-pic"><%= image_tag(post.image.url) %></div> |  | ||||||
| 				<div class="wrap"> |  | ||||||
| 					<% @item.frontend_field.each do |ff|  %> |  | ||||||
| 					<span class="<%= ff[1] %>"> |  | ||||||
| 					<% if ff[1] == 'title' %> |  | ||||||
| 						<%= link_to post.send("#{ff[0]}"), panel_announcement_front_end_bulletin_path(post, :category_id => post.send("#{post.class.to_s.underscore}_category_id")) %> |  | ||||||
| 					<% elsif ff[1] == 'date' %> |  | ||||||
| 						<%= display_date(post.send(ff[0])) %> |  | ||||||
| 					<% elsif ff[1] == 'category' %> |  | ||||||
| 						<%= post.send("#{post.class.to_s.underscore}_#{ff[0]}").title rescue nil %> |  | ||||||
| 					<% elsif ff[1] == 'text' %> |  | ||||||
| 						<%#= post.send("#{ff[0]}[#{I18n.locale}]").html_safe %> |  | ||||||
| 						<%= post.send("#{ff[0]}").html_safe %> |  | ||||||
| 					<% elsif ff[1] == 'status' %> |  | ||||||
| 						<% if post.is_top? %> |  | ||||||
| 							<span class="top"><%= t(:top) %></span> |  | ||||||
| 						<% end %> |  | ||||||
| 						<% if post.is_hot? %> |  | ||||||
| 							<span class="hot"><%= t(:hot) %></span> |  | ||||||
| 						<% end %> |  | ||||||
| 					<% elsif ff[1] == 'link' %> |  | ||||||
| 					<% elsif ff[1] == 'file' %> |  | ||||||
| 					<% elsif ff[1] == 'tag' %> |  | ||||||
| 					<% elsif ff[1] == 'viewcount' %> |  | ||||||
| 						<%= dislpay_view_count(post) %> |  | ||||||
| 					<% elsif ff[1] == 'poster' %> |  | ||||||
| 						<%= User.from_id(post.update_user_id).name rescue ''%> |  | ||||||
| 					<% end %> |  | ||||||
| 					</span> |  | ||||||
| 					<% end %> |  | ||||||
| 				</div> |  | ||||||
| 			</li> |  | ||||||
| 			<% end %> |  | ||||||
| 		</ul> |  | ||||||
| 		 |  | ||||||
| 	</div> |  | ||||||
| 
 |  | ||||||
| <% elsif @frontend_style == '5' %> |  | ||||||
| 
 |  | ||||||
| 	<div class="news news5"> |  | ||||||
| 		<div class="img app-pic"><%= image_tag(@bulletins.first.image.url) %></div> |  | ||||||
| 		<ul class="newslist"> |  | ||||||
| 			<% @bulletins.each do |post| %> |  | ||||||
| 			<li class="<%= cycle('odd', '')%>"> |  | ||||||
| 				<% @item.frontend_field.each do |ff|  %> |  | ||||||
| 				<span class="<%= ff[1] %>"> |  | ||||||
| 				<% if ff[1] == 'title' %> |  | ||||||
| 					<%= link_to post.send("#{ff[0]}"), panel_announcement_front_end_bulletin_path(post, :category_id => post.send("#{post.class.to_s.underscore}_category_id")) %> |  | ||||||
| 				<% elsif ff[1] == 'date' %> |  | ||||||
| 					<%= display_date(post.send(ff[0])) %> |  | ||||||
| 				<% elsif ff[1] == 'category' %> |  | ||||||
| 					<%= post.send("#{post.class.to_s.underscore}_#{ff[0]}").title rescue nil %> |  | ||||||
| 				<% elsif ff[1] == 'text' %> |  | ||||||
| 					<%#= post.send("#{ff[0]}[#{I18n.locale}]").html_safe %> |  | ||||||
| 					<%= post.send("#{ff[0]}").html_safe %> |  | ||||||
| 				<% elsif ff[1] == 'status' %> |  | ||||||
| 					<% if post.is_top? %> |  | ||||||
| 						<span class="top"><%= t(:top) %></span> |  | ||||||
| 					<% end %> |  | ||||||
| 					<% if post.is_hot? %> |  | ||||||
| 						<span class="hot"><%= t(:hot) %></span> |  | ||||||
| 					<% end %> |  | ||||||
| 				<% elsif ff[1] == 'link' %> |  | ||||||
| 				<% elsif ff[1] == 'file' %> |  | ||||||
| 				<% elsif ff[1] == 'tag' %> |  | ||||||
| 				<% elsif ff[1] == 'viewcount' %> |  | ||||||
| 					<%= dislpay_view_count(post) %> |  | ||||||
| 				<% elsif ff[1] == 'poster' %> |  | ||||||
| 					<%= User.from_id(post.update_user_id).name rescue ''%> |  | ||||||
| 				<% end %> |  | ||||||
| 				</span> |  | ||||||
| 				<% end %> |  | ||||||
| 			</li> |  | ||||||
| 			<% end %> |  | ||||||
| 		</ul> |  | ||||||
| 	</div> |  | ||||||
| 
 |  | ||||||
| 	<table class="table table-bordered"> | 	<table class="table table-bordered"> | ||||||
| 	  <tr> | 	  <tr> | ||||||
| 	      <%= content_tag (:th) do %> | 	      <%= content_tag (:th) do %> | ||||||
| 	        <%= t(:category) %> | 			<%= t('announcement.bulletin.category') %> | ||||||
| 	      <% end  if (!params[:search_query].blank? or params[:category_id].blank?)-%> | 		<% end  if (!params[:search_query].blank? or params[:category_id].blank?)-%> | ||||||
| 		<th><%= t(:title) %></th> |  | ||||||
| 		<th><%= t(:postdate) %></th> |  | ||||||
| 	  </tr> |  | ||||||
| 	    <% if !params[:name].blank?%> |  | ||||||
| 	      <%= t("search.unit_get",:unit_name => params[:name],:item_num=>@bulletins.count) %> |  | ||||||
| 	    <% end %> |  | ||||||
| 
 |  | ||||||
| 	    <% if @bulletins.blank? and !params[:search_query].blank? %> |  | ||||||
| 	      <%=render :partial => 'shared/search_not_found'  %> |  | ||||||
| 	      <% elsif  !params[:search_query].blank?  %> |  | ||||||
| 	        <%= t("search.result_get",:search_word => params[:search_query],:item_num=>@bulletins.count) unless (@bulletins.count == 30) %> |  | ||||||
| 	        <%= t("search.too_many",:search_word => params[:search_query],:exceed_num=>@bulletins.count) if (@bulletins.count ==30) %> |  | ||||||
| 	     <% end %> |  | ||||||
| 
 |  | ||||||
| 	<% @bulletins.each do |post| %> |  | ||||||
| 	  <tr class=<%= cycle('odd', '') %>> |  | ||||||
| 	      <%= content_tag(:th) do%> |  | ||||||
| 		   <td><%= (post.bulletin_category.title rescue nil ) %></td> |  | ||||||
| 	     <% end if(!params[:search_query].blank?  or params[:category_id].blank?) %> |  | ||||||
| 			<td><%= link_to post.title, panel_announcement_front_end_bulletin_path(post, :category_id => post.bulletin_category_id) %> |  | ||||||
| 			<%#= link_to post.title, panel_announcement_back_end_bulletin_path(post) %> |  | ||||||
| 			</td> |  | ||||||
| 			<td class="date"><%= display_date_time(post.postdate) %></td> |  | ||||||
| 	  </tr> |  | ||||||
| 	   |  | ||||||
| 	<% end %> |  | ||||||
| 	</table> |  | ||||||
| 
 |  | ||||||
| <% end %> |  | ||||||
| <% else %> |  | ||||||
| 
 |  | ||||||
| 	<table class="table table-bordered"> |  | ||||||
| 	  <tr> |  | ||||||
| 		<th><%= t('announcement.bulletin.category') %></th> |  | ||||||
| 		<th><%= t('announcement.bulletin.title') %></th> | 		<th><%= t('announcement.bulletin.title') %></th> | ||||||
| 		<th><%= t('announcement.bulletin.postdate') %></th> | 		<th><%= t('announcement.bulletin.postdate') %></th> | ||||||
| 	  </tr> | 	  </tr> | ||||||
| 
 | 
 | ||||||
|  |     <% if !params[:name].blank?%> | ||||||
|  |       <%= t("search.unit_get",:unit_name => params[:name],:item_num=>@bulletins.count) %> | ||||||
|  |     <% end %> | ||||||
|  | 
 | ||||||
|  |     <% if @bulletins.blank? and !params[:search_query].blank? %> | ||||||
|  |       <%=render :partial => 'shared/search_not_found'  %> | ||||||
|  |       <% elsif  !params[:search_query].blank?  %> | ||||||
|  |         <%= t("search.result_get",:search_word => params[:search_query],:item_num=>@bulletins.count) unless (@bulletins.count == 30) %> | ||||||
|  |         <%= t("search.too_many",:search_word => params[:search_query],:exceed_num=>@bulletins.count) if (@bulletins.count ==30) %> | ||||||
|  |      <% end %> | ||||||
|  | 
 | ||||||
| 	<% @bulletins.each do |post| %> | 	<% @bulletins.each do |post| %> | ||||||
| 	  <tr> | 	  <tr> | ||||||
| 		<td><%= post.bulletin_category.title rescue nil %></td> | 		<td><%= post.bulletin_category.title rescue nil %></td> | ||||||
|  | @ -280,7 +37,5 @@ | ||||||
| 
 | 
 | ||||||
| 	</table> | 	</table> | ||||||
| 
 | 
 | ||||||
| <% end %> |  | ||||||
| 
 |  | ||||||
| <%= paginate @bulletins, :param_name => :page_main, :params => {:inner => 'false'} %> | <%= paginate @bulletins, :param_name => :page_main, :params => {:inner => 'false'} %> | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,8 +1,8 @@ | ||||||
| <%= form_tag panel_announcement_front_end_bulletins_path, method: :get do %> | <%= form_tag panel_announcement_front_end_announcement_search_path, method: :get do %> | ||||||
| 	<%= hidden_field_tag :category_id, params[:category_id] %> | 	<%= hidden_field_tag :category_id, params[:category_id] %> | ||||||
| 	<%= hidden_field_tag :tag_id, params[:tag_id] %> | 	<%= hidden_field_tag :tag_id, params[:tag_id] %> | ||||||
|   <p> |   <p> | ||||||
|     <%= text_field_tag :search_query, params[:search_query],{:value => (params[:search_query].blank?? '' : params[:search_query]),:placeholder => t("announcement.search") }%> |     <%= text_field_tag :search_query, params[:search_query],{:value => (params[:search_query].blank?? '' : params[:search_query]),:placeholder => t("announcement.search") }%> | ||||||
|     <%= submit_tag "Search", name: nil %> |     <%= submit_tag t("search_"), name: nil %> | ||||||
|   </p> |   </p> | ||||||
| <% end %> | <% end %> | ||||||
|  | @ -35,3 +35,4 @@ en: | ||||||
|     widget: |     widget: | ||||||
|       bulletins_and_web_links: Bulletins and Web Resources |       bulletins_and_web_links: Bulletins and Web Resources | ||||||
|       index: Index |       index: Index | ||||||
|  |       search: Search | ||||||
|  | @ -35,3 +35,4 @@ zh_tw: | ||||||
|     widget: |     widget: | ||||||
|       bulletins_and_web_links: 索引 |       bulletins_and_web_links: 索引 | ||||||
|       index: 索引 |       index: 索引 | ||||||
|  |       search: 搜尋 | ||||||
|  | @ -46,6 +46,7 @@ Rails.application.routes.draw do | ||||||
|       end |       end | ||||||
|       namespace :front_end do |       namespace :front_end do | ||||||
|         match "index_by_unit" => "bulletins#index_bulletins_by_unit",:as => :index_bulletins_by_unit |         match "index_by_unit" => "bulletins#index_bulletins_by_unit",:as => :index_bulletins_by_unit | ||||||
|  |         match "search_result" => "bulletins#search_result",:as=>:announcement_search | ||||||
|         resources :bulletins # do |         resources :bulletins # do | ||||||
|         #           match "preview" => "bulletins#preview_content",:as => :get_preview_content |         #           match "preview" => "bulletins#preview_content",:as => :get_preview_content | ||||||
|         #         end |         #         end | ||||||
|  |  | ||||||
|  | @ -39,6 +39,11 @@ module Announcement | ||||||
|         widget_i18n "announcement.widget.index" |         widget_i18n "announcement.widget.index" | ||||||
|         style ["1","2"] |         style ["1","2"] | ||||||
|       end |       end | ||||||
|  | 
 | ||||||
|  |       customize_widget "bulletins_search_block" do | ||||||
|  |         widget_i18n "announcement.widget.search" | ||||||
|  |       end | ||||||
|  | 
 | ||||||
|       # item "index","announcement.widget.index",:default_template=>true,:fields=>["title","category","postdate"] |       # item "index","announcement.widget.index",:default_template=>true,:fields=>["title","category","postdate"] | ||||||
|       # item "bulletins_and_web_links","announcement.widget.bulletins_and_web_links" |       # item "bulletins_and_web_links","announcement.widget.bulletins_and_web_links" | ||||||
|     end |     end | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue