partial fix feed sorting

This commit is contained in:
邱博亞 2024-10-02 10:12:45 +08:00
parent 9b48e6abfc
commit caa6fb56c5
1 changed files with 40 additions and 14 deletions

View File

@ -218,22 +218,22 @@ module EventNewsHelper
tags = ["all"] tags = ["all"]
end end
@enable_search_flag = false
module_app = ModuleApp.where(key: 'event_news_mod').first module_app = ModuleApp.where(key: 'event_news_mod').first
@enable_search_flag = false
@show_option_items = nil @show_option_items = nil
@show_today_data_first = false @show_today_data_first = false
if module_app && page.respond_to?(:select_option_items) if module_app && page.respond_to?(:select_option_items)
@show_option_items = module_app.show_option_items @show_option_items = module_app.show_option_items
if !(@show_option_items.nil?) if !@show_option_items.nil?
page.select_option_items.each do |select_option_item| page.select_option_items.each do |select_option_item|
value = YAML.load(select_option_item.value)[I18n.locale] value = YAML.load(select_option_item.value)[I18n.locale]
case select_option_item.field_name case select_option_item.field_name
when @show_option_items.keys[1].to_s when @show_option_items.keys[1].to_s
if value == t('event_news.yes') if value == I18n.t('yes_')
@enable_search_flag = true @enable_search_flag = true
end end
when @show_option_items.keys[2].to_s when @show_option_items.keys[3].to_s
if value == t('event_news.yes') if value == I18n.t('yes_')
@show_today_data_first = true @show_today_data_first = true
end end
end end
@ -248,7 +248,7 @@ module EventNewsHelper
@categories = categories.map{|v| cat_maps[v.to_s]}.compact @categories = categories.map{|v| cat_maps[v.to_s]}.compact
end end
end end
event_news = [] event_news_list = []
if !params["source"].present? if !params["source"].present?
event_news = @show_today_data_first ? event_news = @show_today_data_first ?
EventNews.can_display_and_sorted_according_today : EventNews.can_display_and_sorted_according_today :
@ -264,7 +264,7 @@ module EventNewsHelper
event_news = event_news.where(:create_user_id.in=>user_ids) event_news = event_news.where(:create_user_id.in=>user_ids)
end end
end end
event_news = event_news.to_a event_news_list = 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)
@ -280,17 +280,16 @@ module EventNewsHelper
end end
end end
if !feeds_anns.blank? if !feeds_anns.blank?
if event_news.count != 0 if event_news_list.count != 0
top_anns = event_news.select{|v| v.is_top} + feeds_anns.select{|v| v['is_top']} top_anns = event_news_list.select{|v| v.is_top} + feeds_anns.select{|v| v['is_top']}
rest_all_anns = feeds_anns.select{|v| v['is_top'] != true} + event_news.select{|v| !v.is_top} rest_all_anns = feeds_anns.select{|v| v['is_top'] != true} + event_news_list.select{|v| !v.is_top}
rest_anns = rest_all_anns.sort_by { |a| tmp=a["postdate"].blank?;[tmp ? 0 : 1, tmp ? nil : a["postdate"].to_time] }.reverse all_sorted = sort_event_news(top_anns) + sort_event_news(rest_all_anns)
all_sorted = top_anns.sort_by { |a| tmp=a["postdate"].blank?;[tmp ? 0 : 1, tmp ? nil : a["postdate"].to_time] }.reverse + rest_anns
else else
all_sorted = feeds_anns.select{|v| v['is_top']}.sort_by { |a| tmp=a["postdate"].blank?;[tmp ? 0 : 1, tmp ? nil : a["postdate"].to_time] }.reverse + feeds_anns.select{|v| v['is_top'] != true}.sort_by { |a| tmp=a["postdate"].blank?;[tmp ? 0 : 1, tmp ? nil : a["postdate"].to_time] }.reverse all_sorted = sort_event_news(feeds_anns.select{|v| v['is_top']}) + sort_event_news(feeds_anns.select{|v| v['is_top'] != true})
end end
all_filter = filter_by_keywords(all_sorted,params[:keywords],params[:stime],params[:etime]) all_filter = filter_by_keywords(all_sorted,params[:keywords],params[:stime],params[:etime])
else else
all_filter = filter_by_keywords(event_news,params[:keywords],params[:stime],params[:etime]) all_filter = filter_by_keywords(event_news_list,params[:keywords],params[:stime],params[:etime])
end end
if page_data_count != 0 if page_data_count != 0
sorted = all_filter[(page_number-1)*page_data_count...page_number*page_data_count] sorted = all_filter[(page_number-1)*page_data_count...page_number*page_data_count]
@ -301,6 +300,33 @@ module EventNewsHelper
total_pages = page_data_count == 0 ? 1 : (annc_count.to_f / page_data_count).ceil total_pages = page_data_count == 0 ? 1 : (annc_count.to_f / page_data_count).ceil
[sorted,total_pages] [sorted,total_pages]
end end
def sort_event_news(event_news_list)
if @show_today_data_first || !EventNewsHelper.is_postdate_sort_first
event_news_list = event_news_list.sort_by { |event_news|
tmp1 = event_news["event_date"].blank?
tmp2 = event_news["postdate"].blank?
[
tmp1 ? 0 : 1, tmp1 ? nil : event_news["event_date"].to_time,
tmp2 ? 0 : 1, tmp2 ? nil : event_news["postdate"].to_time
]
}
if !@show_today_data_first
event_news_list = event_news_list.reverse
end
else
event_news_list = event_news_list.sort_by { |event_news|
tmp1 = event_news["event_date"].blank?
tmp2 = event_news["postdate"].blank?
[
tmp2 ? 0 : 1, tmp2 ? nil : event_news["postdate"].to_time,
tmp1 ? 0 : 1, tmp1 ? nil : event_news["event_date"].to_time
]
}.reverse
end
return event_news_list
end
def render_view_for_event_news(overridehtml=nil) def render_view_for_event_news(overridehtml=nil)
@key = Site.first.template @key = Site.first.template
def render_link_to_edit(html, url_to_edit) def render_link_to_edit(html, url_to_edit)