Modify "can_display" to add "postdate" and "deadline"
This commit is contained in:
parent
68a379f8a4
commit
19bf2f2be5
|
@ -9,9 +9,12 @@ module OrbitModel
|
|||
field :is_pending, :type => Boolean, :default => true
|
||||
field :is_rejected, :type => Boolean, :default => false
|
||||
field :not_checked_reason
|
||||
class_variable_defined?(:@@can_display) ? \
|
||||
class_variable_set(:@@can_display, class_variable_get(:@@can_display).merge({is_checked: true, is_rejected: false, is_pending: false})) : \
|
||||
class_variable_set(:@@can_display, {is_checked: true, is_rejected: false, is_pending: false})
|
||||
query = {type: 'where', conditions: {is_checked: true, is_rejected: false, is_pending: false}}
|
||||
if class_variable_defined?(:@@can_display)
|
||||
class_variable_set(:@@can_display, (class_variable_get(:@@can_display) << query))
|
||||
else
|
||||
class_variable_set(:@@can_display, [query])
|
||||
end
|
||||
send :include, InstanceMethods
|
||||
end
|
||||
end
|
||||
|
@ -54,9 +57,14 @@ module OrbitModel
|
|||
module ClassMethods
|
||||
|
||||
define_method(:can_display) do
|
||||
where(class_variable_get(:@@can_display))
|
||||
final_query = class_variable_get(:@@can_display).inject('') do |result, query_hash|
|
||||
result << "." if result.present?
|
||||
result << "#{query_hash[:type]}(#{query_hash[:conditions]})"
|
||||
result
|
||||
end
|
||||
eval(final_query)
|
||||
end unless method_defined? :can_display
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -8,9 +8,12 @@ module OrbitModel
|
|||
field :is_top, :type => Boolean, :default => false
|
||||
field :is_hot, :type => Boolean, :default => false
|
||||
field :is_hidden, :type => Boolean, :default => false
|
||||
self.class_variable_defined?(:@@can_display) ? \
|
||||
self.class_variable_set(:@@can_display, self.class_variable_get(:@@can_display).merge({is_hidden: false})) : \
|
||||
self.class_variable_set(:@@can_display, {is_hidden: false})
|
||||
query = {type: 'where', conditions: {is_hidden: false}}
|
||||
if class_variable_defined?(:@@can_display)
|
||||
class_variable_set(:@@can_display, (class_variable_get(:@@can_display) << query))
|
||||
else
|
||||
class_variable_set(:@@can_display, [query])
|
||||
end
|
||||
send :include, InstanceMethods
|
||||
end
|
||||
end
|
||||
|
@ -34,7 +37,12 @@ module OrbitModel
|
|||
module ClassMethods
|
||||
|
||||
define_method(:can_display) do
|
||||
where(class_variable_get(:@@can_display))
|
||||
final_query = class_variable_get(:@@can_display).inject('') do |result, query_hash|
|
||||
result << "." if result.present?
|
||||
result << "#{query_hash[:type]}(#{query_hash[:conditions]})"
|
||||
result
|
||||
end
|
||||
eval(final_query)
|
||||
end unless method_defined? :can_display
|
||||
|
||||
end
|
||||
|
|
|
@ -3,10 +3,17 @@ module OrbitModel
|
|||
module TimeFrame
|
||||
|
||||
def self.included(base)
|
||||
base.extend ClassMethods
|
||||
base.class_eval do
|
||||
field :postdate , :type => DateTime
|
||||
field :deadline , :type => DateTime
|
||||
before_save :check_deadline
|
||||
query = {type: 'any_of', conditions: "{deadline: nil, :postdate.lte => Time.now} , {:deadline.gte => Time.now, :postdate.lte => Time.now}"}
|
||||
if class_variable_defined?(:@@can_display)
|
||||
class_variable_set(:@@can_display, (class_variable_get(:@@can_display) << query))
|
||||
else
|
||||
class_variable_set(:@@can_display, [query])
|
||||
end
|
||||
send :include, InstanceMethods
|
||||
end
|
||||
end
|
||||
|
@ -27,6 +34,19 @@ module OrbitModel
|
|||
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
define_method(:can_display) do
|
||||
final_query = class_variable_get(:@@can_display).inject('') do |result, query_hash|
|
||||
result << "." if result.present?
|
||||
result << "#{query_hash[:type]}(#{query_hash[:conditions]})"
|
||||
result
|
||||
end
|
||||
eval(final_query)
|
||||
end unless method_defined? :can_display
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -43,15 +43,15 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController
|
|||
else
|
||||
date_now = Time.now
|
||||
if !params[:category_id].blank? && !params[:tag_id].blank?
|
||||
@bulletins = Bulletin.available_for_lang(I18n.locale).can_display.where(:category_id => params[:category_id], :tagged_ids => params[:tag_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(@page_num)
|
||||
@bulletins = Bulletin.available_for_lang(I18n.locale).can_display.where(:category_id => params[:category_id], :tagged_ids => params[:tag_id]).desc( :is_top, :postdate).page( params[:page_main]).per(@page_num)
|
||||
@current_category = BulletinCategory.from_id(params[:category_id]) rescue nil
|
||||
elsif !params[:category_id].blank?
|
||||
@bulletins = Bulletin.all.available_for_lang(I18n.locale).can_display.where(:category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(@page_num)
|
||||
@bulletins = Bulletin.all.available_for_lang(I18n.locale).can_display.where(:category_id => params[:category_id]).desc( :is_top, :postdate).page( params[:page_main]).per(@page_num)
|
||||
@current_category = BulletinCategory.from_id(params[:category_id]) rescue nil
|
||||
elsif !params[:tag_id].blank?
|
||||
@bulletins = Bulletin.available_for_lang(I18n.locale).can_display.where(:tagged_ids => params[:tag_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(@page_num)
|
||||
@bulletins = Bulletin.available_for_lang(I18n.locale).can_display.where(:tagged_ids => params[:tag_id]).desc( :is_top, :postdate).page( params[:page_main]).per(@page_num)
|
||||
else
|
||||
@bulletins = Bulletin.all.available_for_lang(I18n.locale).can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(@page_num)
|
||||
@bulletins = Bulletin.all.available_for_lang(I18n.locale).can_display.desc( :is_top, :postdate).page( params[:page_main]).per(@page_num)
|
||||
end
|
||||
delayed_impressionist(@tag) if @tag
|
||||
end
|
||||
|
|
|
@ -32,7 +32,7 @@ module Announcement
|
|||
|
||||
widgets do
|
||||
default_widget do
|
||||
query 'Bulletin.any_of( {deadline: nil,:postdate.lte => Time.now} , {:deadline.gte => Time.now,:postdate.lte => Time.now} )'
|
||||
query 'Bulletin'
|
||||
enable ["typeA", "typeB_style3", "typeC"]
|
||||
image :image
|
||||
field :postdate
|
||||
|
|
Reference in New Issue