add show_today_data_first mode

This commit is contained in:
chiu 2021-09-19 22:13:36 +08:00
parent 9e87f40e1c
commit 3ddfe2ea14
6 changed files with 63 additions and 63 deletions

View File

@ -87,7 +87,6 @@ class EventNewsController < ApplicationController
},
"total_pages" => total_pages
}
end
def random_event_news_widget
@ -407,43 +406,52 @@ class EventNewsController < ApplicationController
@tab_option = 0
@read_more_option = 0
@all_setting_option = 0
@image_version = 'thumb'
@show_today_data_first = false
if subpart.methods.include? 'select_options'.to_sym
ModuleApp.all.select{|tmp| tmp.key.to_s=='event_news'}.each do |modile_app|
@show_options = modile_app.show_options rescue nil
end
subpart.select_options.each do |select_option|
if !(@show_options.nil?) && select_option.field_name == @show_options.keys[1].to_s
if !(@show_options.nil?)
value = YAML.load(select_option.value)
tmp = value[:en]
I18n.with_locale(:en) do
tab_options.each_with_index do |option,i|
if tmp == t("event_news.#{option}")
@tab_option = i
break
case select_option.field_name
when @show_options.keys[0].to_s
if tmp == t('event_news.small_size')
@image_version = 'thumb'
elsif tmp == t('event_news.medium_size')
@image_version = 'mobile'
elsif tmp == t('event_news.orignal_size')
@image_version = 'orignal'
end
end
end
end
if !(@show_options.nil?) && select_option.field_name == @show_options.keys[2].to_s
value = YAML.load(select_option.value)
tmp = value[:en]
I18n.with_locale(:en) do
read_more_options.each_with_index do |option,i|
if tmp == t("announcement.#{option}")
@read_more_option = i
break
when @show_options.keys[1].to_s
tab_options.each_with_index do |option,i|
if tmp == t("event_news.#{option}")
@tab_option = i
break
end
end
end
end
end
if !(@show_options.nil?) && select_option.field_name == @show_options.keys[3].to_s
value = YAML.load(select_option.value)
tmp = value[:en]
I18n.with_locale(:en) do
all_setting_options.each_with_index do |option,i|
if tmp == t("announcement.#{option}")
@all_setting_option = i
break
when @show_options.keys[2].to_s
read_more_options.each_with_index do |option,i|
if tmp == t("event_news.#{option}")
@read_more_option = i
break
end
end
when @show_options.keys[3].to_s
all_setting_options.each_with_index do |option,i|
if tmp == t("event_news.#{option}")
@all_setting_option = i
break
end
end
when @show_options.keys[4].to_s
if tmp == t('no_')
@show_today_data_first = false
else
@show_today_data_first = true
end
end
end
@ -458,7 +466,6 @@ class EventNewsController < ApplicationController
subpart = OrbitHelper.get_current_widget
widget_data_count = OrbitHelper.widget_data_count
event_news_cache = EventNewsCache.where(parent_id: subpart.id.to_s + cats.to_s + tags.to_s + widget_data_count.to_s,locale: I18n.locale.to_s)
set_image_version_for_widget()
devide_flag = (!(defined? SiteFeed).nil?)
event_news_cache.where(:invalid_date.lte => Time.now).destroy
count = event_news_cache.count
@ -469,16 +476,24 @@ class EventNewsController < ApplicationController
EventNews.remove_expired_status
uid = OrbitHelper.params[:uid] rescue ""
event_news_for_locale = EventNews.where(:title.nin => ["",nil], :uid.ne => uid).is_approved_and_show.filter_cats_and_tags(cats,tags)
sorted_event_news = event_news_for_locale.can_display_and_sorted
if @show_today_data_first
sorted_event_news = event_news_for_locale.can_display_and_sorted_according_today
else
sorted_event_news = event_news_for_locale.can_display_and_sorted
end
if !is_random
sorted_event_news = sorted_event_news.limit(widget_data_count)
first_deadline = sorted_event_news.pluck(:deadline).compact.sort[0]
sorted_event_news = sorted_event_news.limit(widget_data_count).to_a
first_deadline = sorted_event_news.collect{|v| v[:deadline]}.compact.sort[0]
first_postdate = event_news_for_locale.open_in_future.limit(1).pluck(:postdate)[0]
invalid_date = [first_postdate,first_deadline].compact.sort[0]
if @show_today_data_first
sorted_event_news = sorted_event_news.reverse
invalid_date = [first_postdate,first_deadline,Date.today.to_time].compact.sort[0]
else
invalid_date = [first_postdate,first_deadline].compact.sort[0]
end
if devide_flag
now_event_news = sorted_event_news.to_a
top_event_news = now_event_news.select{|v| v.is_top}.map{|v| data_to_human_type(v,set_tags)}
not_top_event_news = now_event_news.select{|v| !v.is_top}.map{|v| data_to_human_type(v,set_tags)}
top_event_news = sorted_event_news.select{|v| v.is_top}.map{|v| data_to_human_type(v,set_tags)}
not_top_event_news = sorted_event_news.select{|v| !v.is_top}.map{|v| data_to_human_type(v,set_tags)}
EventNewsCache.create(parent_id: subpart.id.to_s + cats.to_s + tags.to_s + widget_data_count.to_s,locale: I18n.locale.to_s,filter_result: {top: top_event_news,not_top: not_top_event_news},invalid_date: invalid_date)
else
event_news = sorted_event_news.map{|v| data_to_human_type(v,set_tags)}

View File

@ -20,30 +20,6 @@ module EventNewsHelper
end
'#'+comp.join
end
def set_image_version_for_widget
subpart = OrbitHelper.get_current_widget
@image_version = 'thumb'
if subpart.methods.include? 'select_options'.to_sym
ModuleApp.all.select{|tmp| tmp.key.to_s=='event_news'}.each do |modile_app|
@show_options = modile_app.show_options rescue nil
end
subpart.select_options.each do |select_option|
if !(@show_options.nil?) && select_option.field_name == @show_options.keys.first.to_s
value = YAML.load(select_option.value)
tmp = value[:en]
I18n.with_locale(:en) do
if tmp == t('event_news.small_size')
@image_version = 'thumb'
elsif tmp == t('event_news.medium_size')
@image_version = 'mobile'
elsif tmp == t('event_news.orignal_size')
@image_version = 'orignal'
end
end
end
end
end
end
def data_to_human_type(a,set_tag_ids=nil)
statuses = a.statuses_with_classname.collect do |status|
{

View File

@ -81,14 +81,16 @@ class EventNews
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 :can_display_and_sorted, ->{where(:is_hidden.ne=>true,:is_preview.ne => true).any_of({:postdate.lte=>Time.now, :deadline.gte=>Time.now},{:postdate.lte=>Time.now, :deadline=>nil},{:postdate=>nil}).order(is_top: :desc,postdate: :desc,id: :desc)}
scope :can_display_and_sorted, ->{where(:is_hidden.ne=>true,:is_preview.ne => true).any_of({:postdate.lte=>Time.now, :deadline.gte=>Time.now},{:postdate.lte=>Time.now, :deadline=>nil},{:postdate=>nil}).order(is_top: :desc,postdate: :desc, event_date: :desc,id: :desc)}
scope :can_display_and_sorted_according_today, ->{where(:is_hidden.ne=>true,:is_preview.ne => true).any_of({:postdate.lte=>Time.now, :deadline.gte=>Time.now},{:postdate.lte=>Time.now, :deadline=>nil},{:postdate=>nil}).order(is_top: :desc,postdate: :desc, event_date: :asc,id: :desc).where(:event_date.gte => Date.today.to_time)}
scope :is_approved, ->{where(:approved => 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)}
before_create :set_expire
before_save :check_limit
index({postdate: 1}, { unique: false, background: true })
index({is_top: -1,postdate: -1, _id: -1}, { unique: false, background: true })
index({is_top: -1,postdate: -1, event_date: -1, _id: -1}, { unique: false, background: true })
index({is_top: -1,postdate: -1, event_date: 1, _id: -1}, { unique: false, background: true })
def get_org_model
if self.is_preview
org_model = nil

View File

@ -2,6 +2,7 @@ en:
module_name:
event_news: Event News
event_news:
show_today_data_first: Show today data first
custom_fields_title: Custom Fields Title
custom_carousel_image_width_hint: "If blank, width will be default value."
carousel_image_width: Carousel Image Width

View File

@ -2,6 +2,7 @@ zh_tw:
module_name:
event_news: 活動公告
event_news:
show_today_data_first: 優先顯示當日資料
custom_fields_title: 欄位名稱設定
custom_carousel_image_width_hint: "未填寫,則使用預設寬度"
carousel_image_width: 輪播圖片寬度

View File

@ -9,6 +9,7 @@ module EventNewsMod
key2 = {}
key3 = {}
key4 = {}
key5 = {}
key1_attr = []
key2_attr = []
key3_attr = []
@ -26,6 +27,8 @@ module EventNewsMod
key2_options = ['not_enable_tabs','enable_tabs_with_categories_include_all','enable_tabs_with_categories']
key3_options = ['default','upper_left','lower_left','upper_right','lower_right']
key4_options = ['the_same_as_data_count','display_all_in_other_tabs']
#After fix I18n.load_path, translation can work there
key5_attr = ['no_','yes_'].map{|v| I18n.available_locales.map{|k| I18n.with_locale(k){[k,I18n.t(v)]}}.to_h}
key1_options.each_with_index do |k,i|
key1_attr[i] = {}
end
@ -45,6 +48,7 @@ module EventNewsMod
key2[k] = v[0]['event_news']['tabs_options']
key3[k] = v[0]['event_news']['read_more_position_options']
key4[k] = v[0]['event_news']['all_tabs_setting']
key5[k] = v[0]['event_news']['show_today_data_first']
key1_options.each_with_index do |kk,i|
key1_attr[i][k] = v[0]['event_news'][kk]
end
@ -70,6 +74,7 @@ module EventNewsMod
data[key2] = key2_attr
data[key3] = key3_attr
data[key4] = key4_attr
data[key5] = key5_attr
data_item[key_item1] = [value_item1,value_item2,value_item3]
data_item[key_item2] = [value2_item1,value2_item2]
data_item[key_item3] = [value_item2,value_item3]
@ -84,7 +89,7 @@ module EventNewsMod
end
end
rescue => e
puts ['error in event_news',e]
puts ['error in event_news',e,e.backtrace]
end
OrbitApp.registration "event_news", :type => "ModuleApp" do
module_label "event_news.event_news"