fix approval at news and announcement for abnormal flags that causing search result fault.

This commit is contained in:
Matthew K. Fu JuYuan committed 2012-08-03 12:45:47 +08:00
1 parent 69901403cd
commit d7ad029d4b
14 files changed
+85 -149

No files matched your search

@@ -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
@@ -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
@@ -10,12 +10,12 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController
def index
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}
+17 -61
View File
@@ -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|
@@ -18,8 +18,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| %>
<tr>
<td><%= (post.bulletin_category.title rescue nil ) if !params[:search_query].blank? %></td>
@@ -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
@@ -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')) }
@@ -10,12 +10,13 @@ class Panel::News::FrontEnd::NewsBulletinsController < OrbitWidgetController
def index
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)
+18 -18
View File
@@ -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
@@ -10,7 +10,8 @@
<% if @news_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=>@news_bulletins.count) %>
<%= t("search.result_get",:search_word => params[:search_query],:item_num=>@news_bulletins.count) unless (@bulletins.count == 30)%>
<%= t("search.too_many",:search_word => params[:search_query],:exceed_num=>@bulletins.count) if (@bulletins.count ==30) %>
<% end %>
<table class="table table-bordered">
<tbody>