From 06919e76edf2363ab1dc3a12d6269f6896749ad2 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Fri, 3 Aug 2012 12:45:47 +0800 Subject: [PATCH] fix approval at news and announcement for abnormal flags that causing search result fault. --- config/locales/en.yml | 1 + config/locales/zh_tw.yml | 4 +- lib/tasks/matt_dev.rake | 2 +- lib/tasks/mid_site_sync.rake | 2 +- .../back_end/approvals_controller.rb | 5 +- .../back_end/bulletins_controller.rb | 72 +++++------------ .../front_end/bulletins_controller.rb | 8 +- .../announcement/app/models/bulletin.rb | 78 ++++--------------- .../front_end/bulletins/index.html.erb | 4 +- .../back_end/news_approvals_controller.rb | 5 +- .../back_end/news_bulletins_controller.rb | 9 +++ .../front_end/news_bulletins_controller.rb | 5 +- .../news/app/models/news_bulletin.rb | 36 ++++----- .../front_end/news_bulletins/index.html.erb | 1 - 14 files changed, 83 insertions(+), 149 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 93fbcc10..7a85ddff 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -306,3 +306,4 @@ en: sitesearch: Google Site Search site_setting_help: Please Enter the search argument for Google search. result_get: "Searched about ' %{search_word} ' Found %{item_num} items" + too_many: "Search about ' %{search_word} 'resulted more than %{exceed_num} items maybe try to search with more specific terms?" diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 79251f92..d1a15773 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -442,7 +442,9 @@ zh_tw: site_search: "全站搜尋" sitesearch: Google Site Search site_setting_help: 請輸入送交Google搜尋的參數 - result_get: "搜尋標題有關 ' %{search_word} ' 共搜尋到%{item_num}筆資料" + result_get: "搜尋有關 ' %{search_word} ' 共搜尋到%{item_num}筆資料" + too_many: "搜尋有關 ' %{search_word} ' 尋找到超過 %{exceed_num} 筆資料,請嘗試加入更多關鍵字縮小搜尋範圍,以作更精確的搜尋" + activerecord: errors: template: # ~ 2.3.5 backward compatible diff --git a/lib/tasks/matt_dev.rake b/lib/tasks/matt_dev.rake index 0a9f7104..ce0cd509 100644 --- a/lib/tasks/matt_dev.rake +++ b/lib/tasks/matt_dev.rake @@ -10,7 +10,7 @@ namespace :matt_dev do task :searching_02 => :environment do a= Bulletin.solr_search do #("Bulletin",'我',:conditions =>{:is_checked=>true,:is_hidden=>false}) - fulltext '我' + fulltext '關島' with(:frontend_search,true) #with(:is_hidden,true) end diff --git a/lib/tasks/mid_site_sync.rake b/lib/tasks/mid_site_sync.rake index 707a609b..e009f861 100644 --- a/lib/tasks/mid_site_sync.rake +++ b/lib/tasks/mid_site_sync.rake @@ -9,7 +9,7 @@ namespace :mid_site do admin_role = nil sub_role = nil test_account_ldap_id ='139716' - MiddleSiteConnection.establish + #MiddleSiteConnection.establish task :sync => :environment do info_profile = Info.first(conditions: {:key => 'profile'}) diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/approvals_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/approvals_controller.rb index f787ff28..5dfbb750 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/approvals_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/approvals_controller.rb @@ -10,11 +10,8 @@ class Panel::Announcement::BackEnd::ApprovalsController < OrbitBackendControlle def approve notice = "" @bulletin = Bulletin.find params[:bulletin_id] - - @bulletin.is_checked = params[:bulletin][:is_checked] - @bulletin.not_checked_reason = params[:bulletin][:not_checked_reason] + @bulletin.proc_check(params[:bulletin][:is_checked],params[:bulletin][:not_checked_reason]) @bulletin.de_pending - if @bulletin.save notice = t('bulletin.approve_bulletin_success') else diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb index 2f38dd08..60784f05 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb @@ -14,8 +14,8 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController def index # @bulletins = Bulletin.all # @bulletins = Bulletin.desc("postdate desc") - get_categorys('BulletinCategory',params[:bulletin_category_id]) - get_tags + get_categorys('BulletinCategory',params[:bulletin_category_id]) + get_tags @filter = params[:filter] new_filter = params[:new_filter] @@ -34,12 +34,6 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController @filter = {new_filter[:type] => [new_filter[:id].to_s]} end - # @bulletins = Bulletin.where("bulletin_category_id" => params[:bulletin_category_id]).desc("postdate") if params[:bulletin_category_id] - - # @bulletins = Bulletin.search(params[:search], params[:category_id]) - # @bulletins = Bulletin.all.order_by([params[:sort], params[:direction]]) - - # @bulletins = (params[:sort] || @filter) ? get_sorted_and_filtered_bulletins : Bulletin.all.page(params[:page]).per(10) @bulletin_categories = get_categories_for_index("BulletinCategory") @bulletin_category_ids = @bulletin_categories.collect{|t| t.id.to_s} + [nil] @@ -62,16 +56,7 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController # GET /bulletins/1.xml def show @bulletin = Bulletin.find(params[:id]) - get_tags - # get_categorys - - # @bulletin_categorys = BulletinCategory.where("_id" => params[:id]) - - # if params[:id] - # @bulletins = Bulletin.where("bulletin_category_id" => params[:id]) - # else - # @bulletins = Bulletin.desc("postdate desc") - # end + get_tags respond_to do |format| format.html # show.html.erb @@ -84,13 +69,9 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController def new @bulletin = Bulletin.new(:postdate => DateTime.now) - @link_url = panel_announcement_back_end_bulletins_path - - # @bulletin.bulletin_files.build - # @bulletin.bulletin_files.new - - get_tags - respond_to do |format| + @link_url = panel_announcement_back_end_bulletins_path + get_tags + respond_to do |format| format.html # new.html.erb format.xml { render :xml => @bulletin } end @@ -141,6 +122,9 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController @bulletin.create_user_id = current_user.id @bulletin.update_user_id = current_user.id + if(is_manager? || is_admin?) + @bulletin.de_pending + end respond_to do |format| if @bulletin.save @@ -158,13 +142,10 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController end - def link_quick_add - # debugger - + def link_quick_add @bulletin_link = BulletinLink.new - @link_url = panel_announcement_back_end_bulletins_path - - @bulletin_link.bulletin_id = params[:bulletin_id] + @link_url = panel_announcement_back_end_bulletins_path + @bulletin_link.bulletin_id = params[:bulletin_id] respond_to do |format| format.js @@ -173,29 +154,17 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController end def link_quick_edit - # debugger @bulletin_link = BulletinLink.find(params[:bulletin_id]) - - @link_url = panel_announcement_back_end_bulletin_path(@bulletin_link) - - # @bulletin = Bulletin.find(params[:bulletin_id]) - - # @link_url = panel_announcement_back_end_bulletin_path(@bulletin) - + @link_url = panel_announcement_back_end_bulletin_path(@bulletin_link) respond_to do |format| format.js end - end - def file_quick_add - # debugger - + def file_quick_add @bulletin_file = BulletinFile.new @file_url = panel_announcement_back_end_bulletins_path - @bulletin_file.bulletin_id = params[:bulletin_id] - respond_to do |format| format.js end @@ -203,11 +172,8 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController end def file_quick_edit - # debugger @bulletin_file = BulletinFile.find(params[:bulletin_id]) - @file_url = panel_announcement_back_end_bulletin_path(@bulletin_file) - respond_to do |format| format.js end @@ -215,6 +181,7 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController # PUT /bulletins/1 # PUT /bulletins/1.xml + def update if params[:bulletin_link] @@ -248,7 +215,6 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController else @bulletin = Bulletin.find(params[:id]) - # @bulletin.image.clear if params[:bulletin][:image_del] == '1' # if params[:bulletin][:image_del] == '1' @@ -262,6 +228,11 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController respond_to do |format| if @bulletin.update_attributes(params[:bulletin]) + if(is_manager? || is_admin?) + @bulletin.is_checked = true + @bulletin.is_rejected = false + @bulletin.de_pending! + end # if (params[:bulletin][:is_checked] == "false") # @bulletin.is_rejected = true # @bulletin.save! @@ -276,8 +247,7 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController format.js { render 'toggle_enable' } format.xml { head :ok } else - get_tags - + get_tags format.html { render :action => "edit" } format.xml { render :xml => @bulletin.errors, :status => :unprocessable_entity } end 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 d46cbc9f..ac524859 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 @@ -11,12 +11,12 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController def index @page = Page.find(params[:page_id]) if !params[:search_query].blank? - search_cond = {:is_checked=>true,:is_hidden=>false,:is_pending => false} - search_cond.merge!({:bulletin_category_id => "#{params[:category_id]}" }) if !params[:category_id].blank? - + # search_cond = {:is_checked=>true,:is_hidden=>false,:is_pending => false} + # search_cond.merge!({:bulletin_category_id => "#{params[:category_id]}" }) if !params[:category_id].blank? @search = Bulletin.solr_search do fulltext params[:search_query] - #with(:frontend_search,true) + with(:frontend_search,true) + #order_by(:average_rating) end search_result = @search.results.collect{|result| result.id} diff --git a/vendor/built_in_modules/announcement/app/models/bulletin.rb b/vendor/built_in_modules/announcement/app/models/bulletin.rb index 12a725cb..1cda9cb4 100644 --- a/vendor/built_in_modules/announcement/app/models/bulletin.rb +++ b/vendor/built_in_modules/announcement/app/models/bulletin.rb @@ -60,7 +60,7 @@ class Bulletin validates :title, :at_least_one => true - before_save :check_deadline,:update_status,:update_avliable_language + before_save :check_deadline,:update_avliable_language after_save :save_bulletin_links after_save :save_bulletin_files @@ -70,68 +70,39 @@ class Bulletin title_translations.to_a.collect{|t| t[1]} end text :texts do - text_translations.to_a.collect{|t| t[1]} + text_translations.to_a.collect{|t| Nokogiri::HTML(t[1]).text} end # text :text do # a = (title_translations["zh_tw"] + title_translations["en"]) # a # end boolean :frontend_search do - !is_hidden && !is_pending && is_checked + ( !is_hidden && !is_pending && is_checked && !is_rejected ) end integer :view_count string :bulletin_category_id end - # redis_search_index(:title_field => :s_title, - # :alias_field =>:s_title_en , - # :score_field => :view_count, - # :condition_fields => [:is_checked,:is_hidden,:bulletin_category_id,:is_pending], - # :ext_fields => []) - - # def gen_title_for_search - # # [s_title,s_title_en,s_text_en,s_text_zh_tw].join(' ') - # end + def proc_check(check,not_pass_info = "") + self.is_checked = true + if check =="true" + self.is_rejected = false + elsif check == "false" + self.is_rejected = true + self.not_checked_reason = not_pass_info + end + end - #alias_method - - # def s_title - # self.title_translations["zh_tw"] - # end - - # def s_title_was - # self.title_was["zh_tw"] - # end - - # def s_title_en - # self.title_translations["en"] - # end - - # def s_title_en_was - # self.title_was["en"] - # end - - # def s_text_en - # Nokogiri::HTML(self.text.en).text - # end - # def s_text_zh_tw - # Nokogiri::HTML(self.text.zh_tw).text - # end - - # scope :currently_available, lambda { |category, limit| - # # limit ||= 5 - # # { - # # debugger - # # a=1 - # :where => {:bulletin_category_id => bulletin_category_id, :disable => false}#, - # # :limit => limit - # # } - # } def de_pending self.is_pending = false end + def de_pending! + de_pending + self.save! + end + def publish_month published_at.strftime("%B %Y") end @@ -232,21 +203,6 @@ class Bulletin end end - - def update_status - if !self.is_pending - if !self.is_checked - # self.is_pending = false - self.is_rejected = true - #self.is_checked = false - elsif self.is_checked - # self.is_pending = false - self.is_rejected = false - #self.is_checked = true - end - end - return true - end def update_avliable_language VALID_LOCALES.each do |locale| 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 45554af0..421a347a 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 @@ -14,8 +14,10 @@ <% 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) %> + <%= 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| %> > <%= (post.bulletin_category.title rescue nil ) if !params[:search_query].blank? %> diff --git a/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_approvals_controller.rb b/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_approvals_controller.rb index 0c946ca3..2cd1b684 100644 --- a/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_approvals_controller.rb +++ b/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_approvals_controller.rb @@ -10,11 +10,8 @@ class Panel::News::BackEnd::NewsApprovalsController < OrbitBackendController def approve notice = "" @news_bulletin = NewsBulletin.find params[:news_bulletin_id] - - @news_bulletin.is_checked = params[:news_bulletin][:is_checked] - @news_bulletin.not_checked_reason = params[:news_bulletin][:not_checked_reason] + @news_bulletin.proc_check(params[:news_bulletin][:is_checked],params[:news_bulletin][:not_checked_reason]) @news_bulletin.de_pending - if @news_bulletin.save notice = t('news_bulletin.approve_bulletin_success') else diff --git a/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_bulletins_controller.rb b/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_bulletins_controller.rb index 8ada0a01..fa08cac1 100644 --- a/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_bulletins_controller.rb +++ b/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_bulletins_controller.rb @@ -148,6 +148,10 @@ class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController @news_bulletin.create_user_id = current_user.id @news_bulletin.update_user_id = current_user.id + if(is_manager? || is_admin?) + @news_bulletin.de_pending + end + respond_to do |format| if @news_bulletin.save expire_page(:controller=>'panel/news/widget/news_bulletins' , :action=>'home_banner') @@ -267,6 +271,11 @@ class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController respond_to do |format| if @news_bulletin.update_attributes(params[:news_bulletin]) + if(is_manager? || is_admin?) + @news_bulletin.is_checked = true + @news_bulletin.is_rejected = false + @news_bulletin.de_pending! + end expire_page(:controller=>'panel/news/widget/news_bulletins' , :action=>'home_banner') # format.html { redirect_to(panel_news_back_end_news_bulletin_url(@news_bulletin), :notice => t('news_bulletin.update_news_bulletin_success')) } format.html { redirect_to(panel_news_back_end_news_bulletins_url, :notice => t('news_bulletin.update_success')) } diff --git a/vendor/built_in_modules/news/app/controllers/panel/news/front_end/news_bulletins_controller.rb b/vendor/built_in_modules/news/app/controllers/panel/news/front_end/news_bulletins_controller.rb index bacb0a31..1d3bb407 100644 --- a/vendor/built_in_modules/news/app/controllers/panel/news/front_end/news_bulletins_controller.rb +++ b/vendor/built_in_modules/news/app/controllers/panel/news/front_end/news_bulletins_controller.rb @@ -11,12 +11,13 @@ class Panel::News::FrontEnd::NewsBulletinsController < OrbitWidgetController def index @page = Page.find(params[:page_id]) if !params[:search_query].blank? - search_cond = {:is_checked=>true,:is_hidden=>false,:is_pending=>false,:is_pending=>false} - search_cond.merge!({:news_bulletin_category_id => "#{params[:category_id]}" }) if !params[:category_id].blank? + # search_cond = {:is_checked=>true,:is_hidden=>false,:is_pending=>false,:is_pending=>false} + # search_cond.merge!({:news_bulletin_category_id => "#{params[:category_id]}" }) if !params[:category_id].blank? @search = NewsBulletin.solr_search do fulltext params[:search_query] with(:frontend_search,true) + #order_by(:average_rating) end search_result = @search.results.collect{|result| result.id} @news_bulletins = NewsBulletin.all.available_for_lang(I18n.locale).can_display.any_in(_id:search_result).page( params[:page_main]).per(10) diff --git a/vendor/built_in_modules/news/app/models/news_bulletin.rb b/vendor/built_in_modules/news/app/models/news_bulletin.rb index 8105917c..8d93dfc4 100644 --- a/vendor/built_in_modules/news/app/models/news_bulletin.rb +++ b/vendor/built_in_modules/news/app/models/news_bulletin.rb @@ -61,7 +61,7 @@ class NewsBulletin validates :title, :at_least_one => true - before_save :update_status,:update_avliable_language + before_save :update_avliable_language after_save :save_news_bulletin_links after_save :save_news_bulletin_files @@ -96,12 +96,12 @@ class NewsBulletin title_translations.to_a.collect{|t| t[1]} end text :texts do - text_translations.to_a.collect{|t| t[1]} + text_translations.to_a.collect{|t| Nokogiri::HTML(t[1]).text} end integer :view_count boolean :frontend_search do - !is_hidden && !is_pending && is_checked + ( !is_hidden && !is_pending && is_checked && !is_rejected ) end @@ -156,10 +156,25 @@ class NewsBulletin end + def proc_check(check,not_pass_info = "") + self.is_checked = true + if check =="true" + self.is_rejected = false + elsif check == "false" + self.is_rejected = true + self.not_checked_reason = not_pass_info + end + end + def de_pending self.is_pending = false end + def de_pending! + de_pending + self.save! + end + def is_expired? Date.today > self.deadline ? true : false rescue false #some dates might sat as nil so rescue false @@ -229,19 +244,4 @@ class NewsBulletin end end - def update_status - if !self.is_pending - if !self.is_checked - # self.is_pending = false - self.is_rejected = true - #self.is_checked = false - elsif self.is_checked - # self.is_pending = false - self.is_rejected = false - #self.is_checked = true - end - end - return true - end - end \ No newline at end of file diff --git a/vendor/built_in_modules/news/app/views/panel/news/front_end/news_bulletins/index.html.erb b/vendor/built_in_modules/news/app/views/panel/news/front_end/news_bulletins/index.html.erb index e3ed67ee..c1788d13 100644 --- a/vendor/built_in_modules/news/app/views/panel/news/front_end/news_bulletins/index.html.erb +++ b/vendor/built_in_modules/news/app/views/panel/news/front_end/news_bulletins/index.html.erb @@ -9,7 +9,6 @@ <% elsif !params[:search_query].blank? %> <%= t("search.result_get",:search_word => params[:search_query],:item_num=>@news_bulletins.count) %> <% end %> -