fix for not displaying bulletin at fronted when it's parent category is disable
This commit is contained in:
parent
98b274d9dd
commit
ca2c056a07
|
@ -1,4 +1,34 @@
|
||||||
module OrbitCoreLib
|
module OrbitCoreLib
|
||||||
|
module BelongsToCategoryMayDisable
|
||||||
|
def self.included(base)
|
||||||
|
base.instance_eval("belongs_to :#{base::BelongsToCategory.to_s}")
|
||||||
|
base.instance_eval("
|
||||||
|
scope :currently_available_by_category, lambda { |category|
|
||||||
|
check_data = category.to_a.collect{|cate| cate.id}
|
||||||
|
any_in(#{ base::BelongsToCategory.to_s}_id: check_data)
|
||||||
|
}
|
||||||
|
")
|
||||||
|
base.instance_eval("scope :admin_manager_all,find(:all)")
|
||||||
|
# base.instance_eval("scope :all,where(disable: false)")
|
||||||
|
base.instance_eval("
|
||||||
|
scope :all, lambda {
|
||||||
|
category = base::BelongsToCategory.to_s.classify.constantize.all
|
||||||
|
check_data = category.to_a.collect{|cate| cate.id}
|
||||||
|
any_in(#{ base::BelongsToCategory.to_s}_id: check_data)
|
||||||
|
}
|
||||||
|
")
|
||||||
|
base.class_eval("
|
||||||
|
def disable?
|
||||||
|
#{base::BelongsToCategory.to_s}.disable?
|
||||||
|
end
|
||||||
|
")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# end
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
module ObjectDisable
|
module ObjectDisable
|
||||||
def self.included(base)
|
def self.included(base)
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,12 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController
|
||||||
preview_content
|
preview_content
|
||||||
else
|
else
|
||||||
@bulletin = Bulletin.can_display.where(_id: params[:id]).first
|
@bulletin = Bulletin.can_display.where(_id: params[:id]).first
|
||||||
|
unless @bulletin.disable?
|
||||||
impressionist(@bulletin)
|
impressionist(@bulletin)
|
||||||
get_categorys
|
get_categorys
|
||||||
|
else
|
||||||
|
render :nothing => true, :status => 403
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,4 +8,8 @@ class AnnouncementTag < Tag
|
||||||
self.bulletins.where(:is_hidden => false).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc(:is_top, sort)
|
self.bulletins.where(:is_hidden => false).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc(:is_top, sort)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def bulletins
|
||||||
|
Bulletin.all.any_in(:_id => bulletin_ids)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
|
@ -5,6 +5,10 @@ class Bulletin
|
||||||
include Mongoid::Timestamps
|
include Mongoid::Timestamps
|
||||||
include Mongoid::MultiParameterAttributes
|
include Mongoid::MultiParameterAttributes
|
||||||
include Impressionist::Impressionable
|
include Impressionist::Impressionable
|
||||||
|
|
||||||
|
BelongsToCategory = :bulletin_category
|
||||||
|
include OrbitCoreLib::BelongsToCategoryMayDisable
|
||||||
|
|
||||||
# include NccuSearch
|
# include NccuSearch
|
||||||
|
|
||||||
scope :searchable,where(:is_checked=>true,:is_hidden=>false,:is_pending=>false)
|
scope :searchable,where(:is_checked=>true,:is_hidden=>false,:is_pending=>false)
|
||||||
|
@ -39,7 +43,7 @@ class Bulletin
|
||||||
|
|
||||||
mount_uploader :image, ImageUploader
|
mount_uploader :image, ImageUploader
|
||||||
|
|
||||||
belongs_to :bulletin_category
|
|
||||||
# belongs_to :unit_list_for_anc
|
# belongs_to :unit_list_for_anc
|
||||||
|
|
||||||
# embeds_many :bulletin_links, :cascade_callbacks => true
|
# embeds_many :bulletin_links, :cascade_callbacks => true
|
||||||
|
@ -59,6 +63,17 @@ class Bulletin
|
||||||
after_save :save_bulletin_files
|
after_save :save_bulletin_files
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# scope :currently_available, lambda { |category, limit|
|
||||||
|
# # limit ||= 5
|
||||||
|
# # {
|
||||||
|
# # debugger
|
||||||
|
# # a=1
|
||||||
|
# :where => {:bulletin_category_id => bulletin_category_id, :disable => false}#,
|
||||||
|
# # :limit => limit
|
||||||
|
# # }
|
||||||
|
# }
|
||||||
|
|
||||||
def publish_month
|
def publish_month
|
||||||
published_at.strftime("%B %Y")
|
published_at.strftime("%B %Y")
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,10 @@ class AnnouncementTag < Tag
|
||||||
|
|
||||||
def get_visible_bulletins(sort = :name)
|
def get_visible_bulletins(sort = :name)
|
||||||
date_now = Time.now
|
date_now = Time.now
|
||||||
self.bulletins.where(:is_hidden => false).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc(:is_top, sort)
|
self.bulletins.all.where(:is_hidden => false).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc(:is_top, sort)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def bulletins
|
||||||
|
Bulletin.all.any_in(:_id => bulletin_ids)
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -264,7 +264,7 @@ class Panel::News::BackEnd::NewsBulletinsController < OrbitBackendController
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @news_bulletin.update_attributes(params[:news_bulletin])
|
if @news_bulletin.update_attributes(params[:news_bulletin])
|
||||||
# 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_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_news_bulletin_success')) }
|
format.html { redirect_to(panel_news_back_end_news_bulletins_url, :notice => t('news_bulletin.update_success')) }
|
||||||
format.js { render 'toggle_enable' }
|
format.js { render 'toggle_enable' }
|
||||||
format.xml { head :ok }
|
format.xml { head :ok }
|
||||||
else
|
else
|
||||||
|
|
|
@ -49,8 +49,13 @@ class Panel::News::FrontEnd::NewsBulletinsController < OrbitWidgetController
|
||||||
preview_content
|
preview_content
|
||||||
else
|
else
|
||||||
@news_bulletin = NewsBulletin.can_display.where(_id: params[:id]).first
|
@news_bulletin = NewsBulletin.can_display.where(_id: params[:id]).first
|
||||||
|
unless @news_bulletin.disable?
|
||||||
impressionist(@news_bulletin)
|
impressionist(@news_bulletin)
|
||||||
get_categorys
|
get_categorys
|
||||||
|
else
|
||||||
|
render :nothing => true, :status => 403
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -51,11 +51,11 @@ class Panel::News::Widget::NewsBulletinsController < OrbitWidgetController
|
||||||
|
|
||||||
def home_banner
|
def home_banner
|
||||||
if !params[:category_id].blank?
|
if !params[:category_id].blank?
|
||||||
@news_bulletins = NewsBulletin.can_display.where(:news_bulletin_category_id => params[:category_id]).widget_datas.limit(9)
|
@news_bulletins = NewsBulletin.all.can_display.where(:news_bulletin_category_id => params[:category_id]).widget_datas.limit(9)
|
||||||
elsif !params[:tag_id].blank?
|
elsif !params[:tag_id].blank?
|
||||||
@news_bulletins = NewsTag.find(params[:tag_id]).news_bulletins.can_display.widget_datas.limit(9) rescue nil
|
@news_bulletins = NewsTag.find(params[:tag_id]).news_bulletins.can_display.widget_datas.limit(9) rescue nil
|
||||||
else
|
else
|
||||||
@news_bulletins = NewsBulletin.can_display.widget_datas.limit(9)
|
@news_bulletins = NewsBulletin.all.can_display.widget_datas.limit(9)
|
||||||
end
|
end
|
||||||
get_categorys
|
get_categorys
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,9 @@ class NewsBulletin
|
||||||
include Mongoid::Timestamps
|
include Mongoid::Timestamps
|
||||||
include Mongoid::MultiParameterAttributes
|
include Mongoid::MultiParameterAttributes
|
||||||
include Impressionist::Impressionable
|
include Impressionist::Impressionable
|
||||||
|
|
||||||
|
BelongsToCategory = :news_bulletin_category
|
||||||
|
include OrbitCoreLib::BelongsToCategoryMayDisable
|
||||||
# include Tire::Model::Search
|
# include Tire::Model::Search
|
||||||
# include Tire::Model::Callbacks
|
# include Tire::Model::Callbacks
|
||||||
# include Redis::Objects
|
# include Redis::Objects
|
||||||
|
@ -43,7 +46,6 @@ class NewsBulletin
|
||||||
|
|
||||||
mount_uploader :image, ImageUploader
|
mount_uploader :image, ImageUploader
|
||||||
|
|
||||||
belongs_to :news_bulletin_category
|
|
||||||
belongs_to :unit_list_for_anc
|
belongs_to :unit_list_for_anc
|
||||||
|
|
||||||
# embeds_many :news_bulletin_links, :cascade_callbacks => true
|
# embeds_many :news_bulletin_links, :cascade_callbacks => true
|
||||||
|
|
|
@ -8,4 +8,8 @@ class NewsTag < Tag
|
||||||
self.news_bulletins.where(:is_hidden => false).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc(:is_top, sort)
|
self.news_bulletins.where(:is_hidden => false).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc(:is_top, sort)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def news_bulletins
|
||||||
|
NewsBulletin.all.any_in(:_id => news_bulletin_ids)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
Reference in New Issue