fix sorting error (sort with event_date first, them postdate)
This commit is contained in:
parent
fd4555a8d0
commit
772bfb4979
|
@ -24,9 +24,7 @@ class Admin::EventNewsController < OrbitAdminController
|
||||||
def update_sort_setting
|
def update_sort_setting
|
||||||
setting = @event_news_setting
|
setting = @event_news_setting
|
||||||
setting.update_attributes(settings_params)
|
setting.update_attributes(settings_params)
|
||||||
if defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash
|
update_enable_manually_sort(setting)
|
||||||
OrbitHelper::SharedHash['event_news_mod'][:enable_manually_sort] = setting.enable_manually_sort
|
|
||||||
end
|
|
||||||
redirect_to edit_sort_admin_event_news_index_path
|
redirect_to edit_sort_admin_event_news_index_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -198,6 +196,7 @@ class Admin::EventNewsController < OrbitAdminController
|
||||||
def createsettings
|
def createsettings
|
||||||
setting = EventNewsSetting.new(settings_params)
|
setting = EventNewsSetting.new(settings_params)
|
||||||
setting.save
|
setting.save
|
||||||
|
update_is_postdate_sort_first(setting)
|
||||||
redirect_to admin_event_news_settings_path
|
redirect_to admin_event_news_settings_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -206,9 +205,10 @@ class Admin::EventNewsController < OrbitAdminController
|
||||||
ids = params['event_news_setting']['anns_status_settings'].to_a.collect do |i,v|
|
ids = params['event_news_setting']['anns_status_settings'].to_a.collect do |i,v|
|
||||||
v['_id']
|
v['_id']
|
||||||
end.compact
|
end.compact
|
||||||
AnnsStatusSetting.where(:id.nin=>ids).destroy
|
EventNewsStatusSetting.where(:id.nin=>ids).destroy
|
||||||
setting.update_attributes(settings_params)
|
setting.update_attributes(settings_params)
|
||||||
setting.save
|
setting.save
|
||||||
|
update_is_postdate_sort_first(setting)
|
||||||
redirect_to admin_event_news_settings_path
|
redirect_to admin_event_news_settings_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -575,4 +575,16 @@ class Admin::EventNewsController < OrbitAdminController
|
||||||
def settings_params
|
def settings_params
|
||||||
params.require(:event_news_setting).permit!
|
params.require(:event_news_setting).permit!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_enable_manually_sort(setting)
|
||||||
|
if defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash
|
||||||
|
OrbitHelper::SharedHash['event_news_mod'][:enable_manually_sort] = setting.enable_manually_sort
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_is_postdate_sort_first(setting)
|
||||||
|
if defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash
|
||||||
|
OrbitHelper::SharedHash['event_news_mod'][:is_postdate_sort_first] = setting.is_postdate_sort_first
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,17 +3,8 @@ class EventNewsModsController < ApplicationController
|
||||||
def initialize
|
def initialize
|
||||||
super
|
super
|
||||||
@app_title = 'event_news_mod'
|
@app_title = 'event_news_mod'
|
||||||
@manually_sort = manually_sort
|
|
||||||
EventNews.instance_variable_set('@manually_sort',@manually_sort)
|
|
||||||
#self.request = OrbitHelper.request
|
#self.request = OrbitHelper.request
|
||||||
end
|
end
|
||||||
def manually_sort
|
|
||||||
if defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash
|
|
||||||
OrbitHelper::SharedHash['event_news_mod'][:enable_manually_sort] rescue EventNewsSetting.first.enable_manually_sort
|
|
||||||
else
|
|
||||||
EventNewsSetting.first.enable_manually_sort rescue false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
def index
|
def index
|
||||||
EventNews.remove_expired_status
|
EventNews.remove_expired_status
|
||||||
sorted,total_pages = get_sorted_event_news
|
sorted,total_pages = get_sorted_event_news
|
||||||
|
|
|
@ -539,4 +539,18 @@ module EventNewsHelper
|
||||||
</div>
|
</div>
|
||||||
</div>").html_safe
|
</div>").html_safe
|
||||||
end
|
end
|
||||||
|
def self.enable_manually_sort
|
||||||
|
if defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash
|
||||||
|
OrbitHelper::SharedHash['event_news_mod'][:enable_manually_sort]
|
||||||
|
else
|
||||||
|
EventNewsSetting.first.enable_manually_sort rescue false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
def self.is_postdate_sort_first
|
||||||
|
if defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash
|
||||||
|
OrbitHelper::SharedHash['event_news_mod'][:is_postdate_sort_first]
|
||||||
|
else
|
||||||
|
EventNewsSetting.first.is_postdate_sort_first rescue false
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -106,9 +106,24 @@ class EventNews
|
||||||
before_destroy :destroy_email
|
before_destroy :destroy_email
|
||||||
|
|
||||||
scope :open_in_future, ->{where(:is_hidden.ne=>true,:is_preview.ne => true,:postdate.gt=>Time.now).order(postdate: :asc)}
|
scope :open_in_future, ->{where(:is_hidden.ne=>true,:is_preview.ne => true,:postdate.gt=>Time.now).order(postdate: :asc)}
|
||||||
scope :can_display_and_sorted, ->{where(:is_hidden.ne=>true,:is_preview.ne => true).valid_time_range.order(event_date: :desc)}
|
scope :can_display_and_sorted, ->{where(:is_hidden.ne=>true,:is_preview.ne => true).valid_time_range}
|
||||||
scope :can_display_and_sorted_according_today, ->{where(:is_hidden.ne=>true,:is_preview.ne => true).order(event_date: :asc).valid_time_range.where(:event_date.gte => Date.today.to_time)}
|
scope :can_display_and_sorted_according_today, ->{where(:is_hidden.ne=>true,:is_preview.ne => true).valid_time_range.where(:event_date.gte => Date.today.to_time)}
|
||||||
scope :valid_time_range, ->{and_any_of([{"postdate"=>{"$lte"=> Time.now}, "deadline"=>{"$gte"=> Time.now}}, {"postdate"=>{"$lte"=> Time.now}, "deadline"=>nil}]).order((@manually_sort ? {is_top: :desc,sort_number: :asc,postdate: :desc,id: :desc} : {is_top: :desc,postdate: :desc,id: :desc}))}
|
scope :valid_time_range, ->{
|
||||||
|
and_any_of([
|
||||||
|
{"postdate"=>{"$lte"=> Time.now}, "deadline"=>{"$gte"=> Time.now}},
|
||||||
|
{"postdate"=>{"$lte"=> Time.now}, "deadline"=>nil}
|
||||||
|
])
|
||||||
|
.order(
|
||||||
|
(EventNewsHelper.enable_manually_sort ?
|
||||||
|
{is_top: :desc, sort_number: :asc} :
|
||||||
|
{is_top: :desc}
|
||||||
|
).merge(
|
||||||
|
EventNewsHelper.is_postdate_sort_first ?
|
||||||
|
{postdate: :desc, event_date: :desc, id: :desc} :
|
||||||
|
{event_date: :desc, postdate: :desc, id: :desc}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
scope :is_approved, ->{where(:approved => true)}
|
scope :is_approved, ->{where(:approved => true)}
|
||||||
scope :is_approved_and_show, ->{where(:approved => true,:is_hidden.ne=>true,:is_preview.ne => true)}
|
scope :is_approved_and_show, ->{where(:approved => true,:is_hidden.ne=>true,:is_preview.ne => true)}
|
||||||
scope :filter_cats_and_tags, ->(cats,tags) {filter_by_widget_categories(cats,false).filter_by_tags(tags)}
|
scope :filter_cats_and_tags, ->(cats,tags) {filter_by_widget_categories(cats,false).filter_by_tags(tags)}
|
||||||
|
|
|
@ -12,6 +12,7 @@ class EventNewsSetting
|
||||||
field :including_time, type: Boolean, default: true
|
field :including_time, type: Boolean, default: true
|
||||||
field :hour_clock_24, type: Boolean, default: true
|
field :hour_clock_24, type: Boolean, default: true
|
||||||
field :enable_manually_sort, type: Boolean, default: false
|
field :enable_manually_sort, type: Boolean, default: false
|
||||||
|
field :is_postdate_sort_first, type: Boolean, default: false
|
||||||
has_many :event_news_status_settings, :autosave => true, :dependent => :destroy
|
has_many :event_news_status_settings, :autosave => true, :dependent => :destroy
|
||||||
accepts_nested_attributes_for :event_news_status_settings, :allow_destroy => true
|
accepts_nested_attributes_for :event_news_status_settings, :allow_destroy => true
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,9 @@
|
||||||
cursor: default;
|
cursor: default;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
legend {
|
||||||
|
background: white;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
<% content_for :page_specific_javascript do %>
|
<% content_for :page_specific_javascript do %>
|
||||||
<%= javascript_include_tag "lib/bootstrap-fileupload" %>
|
<%= javascript_include_tag "lib/bootstrap-fileupload" %>
|
||||||
|
|
|
@ -79,6 +79,9 @@
|
||||||
.td-delete{
|
.td-delete{
|
||||||
width: 10%;
|
width: 10%;
|
||||||
}
|
}
|
||||||
|
legend {
|
||||||
|
background: white;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
<%
|
<%
|
||||||
sub_managers = @module_app.sub_managers
|
sub_managers = @module_app.sub_managers
|
||||||
|
@ -166,6 +169,12 @@
|
||||||
<%= f.check_box :is_display_edit_only %>
|
<%= f.check_box :is_display_edit_only %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="control-group">
|
||||||
|
<%= f.label :is_postdate_sort_first, t("event_news.is_postdate_sort_first"), :class => "control-label muted" %>
|
||||||
|
<div class="controls">
|
||||||
|
<%= f.check_box :is_postdate_sort_first %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<%= f.label :top_limit, t("event_news.top_limit"), :class => "control-label muted" %>
|
<%= f.label :top_limit, t("event_news.top_limit"), :class => "control-label muted" %>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
|
|
|
@ -169,6 +169,7 @@ en:
|
||||||
display_subtitle: Display Subtitle in Content Page
|
display_subtitle: Display Subtitle in Content Page
|
||||||
display_img: Display Cover Image in Content Page
|
display_img: Display Cover Image in Content Page
|
||||||
is_display_edit_only: Only display editable event news
|
is_display_edit_only: Only display editable event news
|
||||||
|
is_postdate_sort_first: Sort by Post Date first (Sort by Event Date first as Default)
|
||||||
only_manager_can_edit_status: Only manager can edit status of event news
|
only_manager_can_edit_status: Only manager can edit status of event news
|
||||||
layout_type: Layout type
|
layout_type: Layout type
|
||||||
event_news_setting_for_iframe: Event News settings for iframe
|
event_news_setting_for_iframe: Event News settings for iframe
|
||||||
|
|
|
@ -172,6 +172,7 @@ zh_tw:
|
||||||
display_subtitle: 內容頁顯示副標題
|
display_subtitle: 內容頁顯示副標題
|
||||||
display_img: 內容頁顯示封面圖片
|
display_img: 內容頁顯示封面圖片
|
||||||
is_display_edit_only: 只顯示可更新的活動公告
|
is_display_edit_only: 只顯示可更新的活動公告
|
||||||
|
is_postdate_sort_first: 優先使用公告日期排序(預設優先使用事件日期)
|
||||||
only_manager_can_edit_status: 只有管理者可更新活動公告狀態
|
only_manager_can_edit_status: 只有管理者可更新活動公告狀態
|
||||||
layout_type: 頁面樣式
|
layout_type: 頁面樣式
|
||||||
event_news_setting_for_iframe: 活動公告iframe設定
|
event_news_setting_for_iframe: 活動公告iframe設定
|
||||||
|
|
|
@ -163,7 +163,7 @@ Gem::Specification.new do |s|
|
||||||
s.license = "MIT"
|
s.license = "MIT"
|
||||||
s.metadata = {
|
s.metadata = {
|
||||||
"_require" => "#{File.expand_path("../app/models/event_news_setting", __FILE__)}",
|
"_require" => "#{File.expand_path("../app/models/event_news_setting", __FILE__)}",
|
||||||
"global_hash" => "{enable_manually_sort: (EventNewsSetting.first.enable_manually_sort rescue false)}"
|
"global_hash" => "{enable_manually_sort: (EventNewsSetting.first.enable_manually_sort rescue false), is_postdate_sort_first: (EventNewsSetting.first.is_postdate_sort_first rescue false)}"
|
||||||
}
|
}
|
||||||
|
|
||||||
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
|
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
|
||||||
|
|
Loading…
Reference in New Issue