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_data_count = data_count || OrbitHelper.page_data_count.to_i
feeds_anns = []
page = OrbitHelper.page rescue nil
page = Page.where(url:params['url']).first if page.nil?
if @type == "show_widget"
tags = @tags
categories = @categories
else
page = OrbitHelper.page rescue nil
page = Page.where(url:params['url']).first if page.nil?
tags = page.tags
tags = params[:tags] if params[:tags].present?
categories = params['category']=='all' ? (page.categories || []) : (Array(params['category']) rescue (page.categories || []))
if params['category'].present? && tags.blank?
tags = ["all"]
end
end
if !params["source"].present?
if @type == "show_widget"
if params[:uids].blank?
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
else
member_prfile = MemberProfile.any_in(:uid=>params[:uids])
user_ids = member_prfile.map{|m| m.user.id rescue nil}.select{|id| !id.nil?}
event_news = EventNews.where(:title.nin => ["",nil],:is_preview.in=>[false,nil],:create_user_id.in=>user_ids)
.can_display_and_sorted.is_approved
.filter_by_categories(categories,false).filter_by_tags(tags).to_a
@enable_search_flag = false
module_app = ModuleApp.where(key: 'event_news_mod').first
@show_option_items = nil
@show_today_data_first = false
if module_app && page.respond_to?(:select_option_items)
@show_option_items = module_app.show_option_items
if !(@show_option_items.nil?)
page.select_option_items.each do |select_option_item|
value = YAML.load(select_option_item.value)[I18n.locale]
case select_option_item.field_name
when @show_option_items.keys[1].to_s
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
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
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 @type != "show_widget"
feeds_anns = get_feed_event_news("index",nil,nil,page_number*page_data_count)
@ -243,7 +273,6 @@ module EventNewsHelper
end
end
else
event_news = []
if @type != "show_widget"
feeds_anns = get_feed_event_news("index",params["source"],nil,page_number*page_data_count)
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 :can_display_and_sorted, ->{
where(:is_hidden.ne=>true,:is_preview.ne => true)
is_approved_and_show
.valid_time_range
.order(
EventNewsHelper.is_postdate_sort_first ?
@ -116,7 +116,7 @@ class EventNews
)
}
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)
}
scope :valid_time_range, ->{

View File

@ -1,21 +1,7 @@
<% params = OrbitHelper.params
page = Page.where(url:params['url']).first
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
<%
params = OrbitHelper.params
%>
<% if enable_search_flag %>
<% if @enable_search_flag %>
<style type="text/css">
#category_select_box{
margin: 0;
@ -57,16 +43,11 @@
}
</style>
<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']]
%>
<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') %>">
<div style="display: flex;flex-wrap: wrap;">
<div class="default_picker">

View File

@ -19,17 +19,17 @@ module EventNewsMod
key_item1 = {}
key_item2 = {}
key_item3 = {}
key_item4 = {}
value_item1 = {}
value_item2 = {}
value_item3 = {}
value2_item1 = {}
value2_item2 = {}
value_item4 = {}
key1_options = ['small_size','medium_size','orignal_size']
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}
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_attr[i] = {}
end
@ -68,17 +68,17 @@ module EventNewsMod
value_item1[k] = v[0]['event_news']['not_show']
value_item2[k] = v[0]['event_news']['show_bottom']
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
key_item4 = key5
data[key1] = key1_attr
data[key2] = key2_attr
data[key3] = key3_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_item2] = [value2_item1,value2_item2]
data_item[key_item2] = yes_no_options
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')
require File.expand_path('../../../app/models/event_news_cache', __FILE__)
if defined?(EventNewsCache)