From caf0426bd4ee976f01acb91f7f2b115596abf8d6 Mon Sep 17 00:00:00 2001 From: "Matt K. Fu" Date: Wed, 1 May 2013 12:16:28 +0800 Subject: [PATCH] bulletin search --- .../front_end/bulletins_controller.rb | 12 + .../widget/bulletins_controller.rb | 2 +- .../front_end/bulletins/index.html.erb | 271 +----------------- .../bulletins/bulletins_search_block.html.erb | 4 +- .../announcement/config/locales/en.yml | 3 +- .../announcement/config/locales/zh_tw.yml | 3 +- .../announcement/config/routes.rb | 1 + vendor/built_in_modules/announcement/init.rb | 5 + 8 files changed, 38 insertions(+), 263 deletions(-) diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb index e4bae5e5..9866f67f 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb @@ -13,6 +13,18 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController render :index 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 @item = Page.find(params[:page_id]) rescue nil if @item diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/widget/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/widget/bulletins_controller.rb index c8d32827..a8c016e8 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/widget/bulletins_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/widget/bulletins_controller.rb @@ -86,7 +86,7 @@ class Panel::Announcement::Widget::BulletinsController < OrbitWidgetController end def bulletins_search_block - + @part = PagePart.find params[:part_id] end protected diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/index.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/index.html.erb index fdf4e097..9e2ade22 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/index.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/index.html.erb @@ -4,269 +4,26 @@

<%= @page.title rescue nil %>

-<% if !@item.frontend_field.blank? %> -<% if @frontend_style == '1' %> - -
- - - - <% @item.frontend_field.each do |ff| %> - - <% end %> - - - <% @bulletins.each do |post| %> - - <% @item.frontend_field.each do |ff| %> - - <% end %> - - <% end %> -
<%= t("announcement.bulletin.#{ff[0]}") if !ff[0].blank? %>
- - <% 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' %> -
<%= image_tag(post.send(wf[0]).url) %>
- <% 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? %> - <%= t(:top) %> - <% end %> - <% if post.is_hot? %> - <%= t(:hot) %> - <% 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 %> -
-
-
- -<% elsif @frontend_style == '2' %> - -
- -
- -<% elsif @frontend_style == '3' %> - -
- - -
- -<% elsif @frontend_style == '4' %> - -
- - -
- -<% elsif @frontend_style == '5' %> - -
-
<%= image_tag(@bulletins.first.image.url) %>
- -
- <%= content_tag (:th) do %> - <%= t(:category) %> - <% end if (!params[:search_query].blank? or params[:category_id].blank?)-%> - - - - <% 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| %> - > - <%= content_tag(:th) do%> - - <% end if(!params[:search_query].blank? or params[:category_id].blank?) %> - - - - - <% end %> -
<%= t(:title) %><%= t(:postdate) %>
<%= (post.bulletin_category.title rescue nil ) %><%= 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) %> - <%= display_date_time(post.postdate) %>
- -<% end %> -<% else %> - - - - + <%= t('announcement.bulletin.category') %> + <% end if (!params[:search_query].blank? or params[:category_id].blank?)-%> + <% 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| %> @@ -280,7 +37,5 @@
<%= t('announcement.bulletin.category') %><%= t('announcement.bulletin.title') %> <%= t('announcement.bulletin.postdate') %>
<%= post.bulletin_category.title rescue nil %>
-<% end %> - <%= paginate @bulletins, :param_name => :page_main, :params => {:inner => 'false'} %> diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/bulletins_search_block.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/bulletins_search_block.html.erb index f49bf84a..4e4c5f85 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/bulletins_search_block.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/bulletins_search_block.html.erb @@ -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 :tag_id, params[:tag_id] %>

<%= 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 %>

<% end %> \ No newline at end of file diff --git a/vendor/built_in_modules/announcement/config/locales/en.yml b/vendor/built_in_modules/announcement/config/locales/en.yml index 93a1f180..dd0a6329 100644 --- a/vendor/built_in_modules/announcement/config/locales/en.yml +++ b/vendor/built_in_modules/announcement/config/locales/en.yml @@ -34,4 +34,5 @@ en: url: URL widget: bulletins_and_web_links: Bulletins and Web Resources - index: Index \ No newline at end of file + index: Index + search: Search \ No newline at end of file diff --git a/vendor/built_in_modules/announcement/config/locales/zh_tw.yml b/vendor/built_in_modules/announcement/config/locales/zh_tw.yml index a9382233..84635dbe 100644 --- a/vendor/built_in_modules/announcement/config/locales/zh_tw.yml +++ b/vendor/built_in_modules/announcement/config/locales/zh_tw.yml @@ -34,4 +34,5 @@ zh_tw: url: 連結位置 widget: bulletins_and_web_links: 索引 - index: 索引 \ No newline at end of file + index: 索引 + search: 搜尋 \ No newline at end of file diff --git a/vendor/built_in_modules/announcement/config/routes.rb b/vendor/built_in_modules/announcement/config/routes.rb index 8c11ebd0..adb63703 100644 --- a/vendor/built_in_modules/announcement/config/routes.rb +++ b/vendor/built_in_modules/announcement/config/routes.rb @@ -46,6 +46,7 @@ Rails.application.routes.draw do end namespace :front_end do 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 # match "preview" => "bulletins#preview_content",:as => :get_preview_content # end diff --git a/vendor/built_in_modules/announcement/init.rb b/vendor/built_in_modules/announcement/init.rb index 5aae6057..d17c34bb 100644 --- a/vendor/built_in_modules/announcement/init.rb +++ b/vendor/built_in_modules/announcement/init.rb @@ -39,6 +39,11 @@ module Announcement widget_i18n "announcement.widget.index" style ["1","2"] 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 "bulletins_and_web_links","announcement.widget.bulletins_and_web_links" end