add show_today_data_first for index

This commit is contained in:
邱博亞 2024-09-30 21:57:01 +08:00
parent 57cf170e1c
commit 9b48e6abfc
4 changed files with 63 additions and 53 deletions

View File

@ -204,37 +204,67 @@ module EventNewsHelper
page_number = 1 if page_number == 0 page_number = 1 if page_number == 0
page_data_count = data_count || OrbitHelper.page_data_count.to_i page_data_count = data_count || OrbitHelper.page_data_count.to_i
feeds_anns = [] feeds_anns = []
page = OrbitHelper.page rescue nil
page = Page.where(url:params['url']).first if page.nil?
if @type == "show_widget" if @type == "show_widget"
tags = @tags tags = @tags
categories = @categories categories = @categories
else else
page = OrbitHelper.page rescue nil
page = Page.where(url:params['url']).first if page.nil?
tags = page.tags tags = page.tags
tags = params[:tags] if params[:tags].present? tags = params[:tags] if params[:tags].present?
categories = params['category']=='all' ? (page.categories || []) : (Array(params['category']) rescue (page.categories || [])) categories = params['category']=='all' ? (page.categories || []) : (Array(params['category']) rescue (page.categories || []))
if params['category'].present? && tags.blank? if params['category'].present? && tags.blank?
tags = ["all"] tags = ["all"]
end end
end
if !params["source"].present? @enable_search_flag = false
if @type == "show_widget" module_app = ModuleApp.where(key: 'event_news_mod').first
if params[:uids].blank? @show_option_items = nil
event_news = EventNews.where(:title.nin => ["",nil],:is_preview.in=>[false,nil]) @show_today_data_first = false
.can_display_and_sorted.is_approved if module_app && page.respond_to?(:select_option_items)
.filter_by_categories(categories,false).filter_by_tags(tags).to_a @show_option_items = module_app.show_option_items
else if !(@show_option_items.nil?)
member_prfile = MemberProfile.any_in(:uid=>params[:uids]) page.select_option_items.each do |select_option_item|
user_ids = member_prfile.map{|m| m.user.id rescue nil}.select{|id| !id.nil?} value = YAML.load(select_option_item.value)[I18n.locale]
event_news = EventNews.where(:title.nin => ["",nil],:is_preview.in=>[false,nil],:create_user_id.in=>user_ids) case select_option_item.field_name
.can_display_and_sorted.is_approved when @show_option_items.keys[1].to_s
.filter_by_categories(categories,false).filter_by_tags(tags).to_a if value == t('event_news.yes')
@enable_search_flag = true
end
when @show_option_items.keys[2].to_s
if value == t('event_news.yes')
@show_today_data_first = true
end
end
end
end end
else
event_news = EventNews.where(:title.nin => ["",nil],:is_preview.in=>[false,nil])
.can_display_and_sorted.is_approved
.filter_by_categories(categories,false).filter_by_tags(tags).to_a
end end
if categories.include? 'all'
@categories = module_app.categories
else
cat_maps = Category.where(:id.in => categories).collect{|cat| [cat.id.to_s, cat]}.to_h
@categories = categories.map{|v| cat_maps[v.to_s]}.compact
end
end
event_news = []
if !params["source"].present?
event_news = @show_today_data_first ?
EventNews.can_display_and_sorted_according_today :
EventNews.can_display_and_sorted
event_news = event_news
.where(:title.nin => ["",nil])
.filter_by_categories(categories,false).filter_by_tags(tags)
if @type == "show_widget"
if !params[:uids].blank?
member_profile = MemberProfile.any_in(:uid=>params[:uids])
user_ids = member_profile.map{|m| m.user.id rescue nil}.select{|id| !id.nil?}
event_news = event_news.where(:create_user_id.in=>user_ids)
end
end
event_news = event_news.to_a
if !(defined? SiteFeed).nil? if !(defined? SiteFeed).nil?
if @type != "show_widget" if @type != "show_widget"
feeds_anns = get_feed_event_news("index",nil,nil,page_number*page_data_count) feeds_anns = get_feed_event_news("index",nil,nil,page_number*page_data_count)
@ -243,7 +273,6 @@ module EventNewsHelper
end end
end end
else else
event_news = []
if @type != "show_widget" if @type != "show_widget"
feeds_anns = get_feed_event_news("index",params["source"],nil,page_number*page_data_count) feeds_anns = get_feed_event_news("index",params["source"],nil,page_number*page_data_count)
else else

View File

@ -107,7 +107,7 @@ class EventNews
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, ->{ scope :can_display_and_sorted, ->{
where(:is_hidden.ne=>true,:is_preview.ne => true) is_approved_and_show
.valid_time_range .valid_time_range
.order( .order(
EventNewsHelper.is_postdate_sort_first ? EventNewsHelper.is_postdate_sort_first ?
@ -116,7 +116,7 @@ class EventNews
) )
} }
scope :can_display_and_sorted_according_today, ->{ scope :can_display_and_sorted_according_today, ->{
where(:is_hidden.ne=>true,:is_preview.ne => true) is_approved_and_show
.order(event_date: :asc).valid_time_range.order({postdate: :asc, id: :asc}).where(:event_date.gte => Date.today.to_time) .order(event_date: :asc).valid_time_range.order({postdate: :asc, id: :asc}).where(:event_date.gte => Date.today.to_time)
} }
scope :valid_time_range, ->{ scope :valid_time_range, ->{

View File

@ -1,21 +1,7 @@
<% params = OrbitHelper.params <%
page = Page.where(url:params['url']).first params = OrbitHelper.params
enable_search_flag = false
if page.respond_to?(:select_option_items)
ModuleApp.all.select{|tmp| tmp.key.to_s=='event_news_mod'}.each do |modile_app|
@show_option_items = modile_app.show_option_items rescue nil
end
page.select_option_items.each do |select_option_item|
if !(@show_option_items.nil?) && select_option_item.field_name == @show_option_items.keys[1].to_s
value = YAML.load(select_option_item.value)
if value[I18n.locale] == t('event_news.yes')
enable_search_flag = true
end
end
end
end
%> %>
<% if enable_search_flag %> <% if @enable_search_flag %>
<style type="text/css"> <style type="text/css">
#category_select_box{ #category_select_box{
margin: 0; margin: 0;
@ -57,16 +43,11 @@
} }
</style> </style>
<form> <form>
<% cats = Array(page.categories) <%
if cats.include? 'all'
cats = ModuleApp.where(key: 'event_news').first.categories
else
cats = cats.map{|v| Category.where(id: v).first}.compact
end
all_cat = [[t('event_news.all'),'all']] all_cat = [[t('event_news.all'),'all']]
%> %>
<div class="search_widget" style="display: flex;flex-wrap: wrap;font-size: 1.1em;"> <div class="search_widget" style="display: flex;flex-wrap: wrap;font-size: 1.1em;">
<%= select_tag('category',options_for_select(all_cat.concat(cats.map{|v| [v.title,v.id.to_s]}),:selected => params['category'].to_s),:id=>"category_select_box",:prompt => t('event_news.select_prompt')) %> <%= select_tag('category',options_for_select(all_cat.concat(@categories.map{|v| [v.title,v.id.to_s]}),:selected => params['category'].to_s),:id=>"category_select_box",:prompt => t('event_news.select_prompt')) %>
<input class="search_box" type="text" name="keywords" value="<%= params['keywords'].to_s.gsub(/\"/,'') %>" placeholder="<%= t('event_news.keywords') %>"> <input class="search_box" type="text" name="keywords" value="<%= params['keywords'].to_s.gsub(/\"/,'') %>" placeholder="<%= t('event_news.keywords') %>">
<div style="display: flex;flex-wrap: wrap;"> <div style="display: flex;flex-wrap: wrap;">
<div class="default_picker"> <div class="default_picker">

View File

@ -19,17 +19,17 @@ module EventNewsMod
key_item1 = {} key_item1 = {}
key_item2 = {} key_item2 = {}
key_item3 = {} key_item3 = {}
key_item4 = {}
value_item1 = {} value_item1 = {}
value_item2 = {} value_item2 = {}
value_item3 = {} value_item3 = {}
value2_item1 = {} value_item4 = {}
value2_item2 = {}
key1_options = ['small_size','medium_size','orignal_size'] key1_options = ['small_size','medium_size','orignal_size']
key2_options = ['not_enable_tabs','enable_tabs_with_categories_include_all','enable_tabs_with_categories'] 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'] key3_options = ['default','upper_left','lower_left','upper_right','lower_right']
key4_options = ['the_same_as_data_count','display_all_in_other_tabs'] key4_options = ['the_same_as_data_count','display_all_in_other_tabs']
#After fix I18n.load_path, translation can work there #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} yes_no_options = ['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_options.each_with_index do |k,i|
key1_attr[i] = {} key1_attr[i] = {}
end end
@ -68,17 +68,17 @@ module EventNewsMod
value_item1[k] = v[0]['event_news']['not_show'] value_item1[k] = v[0]['event_news']['not_show']
value_item2[k] = v[0]['event_news']['show_bottom'] value_item2[k] = v[0]['event_news']['show_bottom']
value_item3[k] = v[0]['event_news']['show_top'] value_item3[k] = v[0]['event_news']['show_top']
value2_item1[k] = v[0]['event_news']['no']
value2_item2[k] = v[0]['event_news']['yes']
end end
key_item4 = key5
data[key1] = key1_attr data[key1] = key1_attr
data[key2] = key2_attr data[key2] = key2_attr
data[key3] = key3_attr data[key3] = key3_attr
data[key4] = key4_attr data[key4] = key4_attr
data[key5] = key5_attr data[key5] = yes_no_options
data_item[key_item1] = [value_item1,value_item2,value_item3] data_item[key_item1] = [value_item1,value_item2,value_item3]
data_item[key_item2] = [value2_item1,value2_item2] data_item[key_item2] = yes_no_options
data_item[key_item3] = [value_item2,value_item3] data_item[key_item3] = [value_item2,value_item3]
data_item[key_item4] = yes_no_options
if ENV['worker_num']=='0' && File.basename($0) != 'rake' && !Rails.const_defined?('Console') if ENV['worker_num']=='0' && File.basename($0) != 'rake' && !Rails.const_defined?('Console')
require File.expand_path('../../../app/models/event_news_cache', __FILE__) require File.expand_path('../../../app/models/event_news_cache', __FILE__)
if defined?(EventNewsCache) if defined?(EventNewsCache)