parent
caa6fb56c5
commit
b59593aa39
|
@ -585,6 +585,12 @@ class Admin::EventNewsController < OrbitAdminController
|
||||||
def update_is_postdate_sort_first(setting)
|
def update_is_postdate_sort_first(setting)
|
||||||
if defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash
|
if defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash
|
||||||
OrbitHelper::SharedHash['event_news_mod'][:is_postdate_sort_first] = setting.is_postdate_sort_first
|
OrbitHelper::SharedHash['event_news_mod'][:is_postdate_sort_first] = setting.is_postdate_sort_first
|
||||||
|
feeds_time_field = (EventNewsHelper.is_postdate_sort_first ? ['postdate', 'event_date'] : ['event_date', 'postdate'])
|
||||||
|
@module_app.feeds_time_field = feeds_time_field
|
||||||
|
@module_app.save
|
||||||
|
if defined?(Feeds)
|
||||||
|
Feeds::Migrate.sync_module_apps
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -51,9 +51,9 @@ class EventNewsFeedsController < ApplicationController
|
||||||
if !@bf.nil?
|
if !@bf.nil?
|
||||||
tags = @bf.tag_ids
|
tags = @bf.tag_ids
|
||||||
if !tags.empty?
|
if !tags.empty?
|
||||||
@event_news = EventNews.can_display_and_sorted.is_approved.filter_by_tags(tags)
|
@event_news = EventNews.can_display_and_sorted.filter_by_tags(tags)
|
||||||
else
|
else
|
||||||
@event_news = EventNews.can_display_and_sorted.is_approved
|
@event_news = EventNews.can_display_and_sorted
|
||||||
end
|
end
|
||||||
categories = @bf.category_ids
|
categories = @bf.category_ids
|
||||||
if !categories.empty?
|
if !categories.empty?
|
||||||
|
|
|
@ -24,8 +24,8 @@ class EventNewsModsController < ApplicationController
|
||||||
desc = (desc.blank? ? "EventNews image" : desc)
|
desc = (desc.blank? ? "EventNews image" : desc)
|
||||||
link_to_show = a.is_external_link ? a.external_link : OrbitHelper.url_to_show(a.to_param)
|
link_to_show = a.is_external_link ? a.external_link : OrbitHelper.url_to_show(a.to_param)
|
||||||
target = a.is_external_link ? "_blank" : "_self"
|
target = a.is_external_link ? "_blank" : "_self"
|
||||||
doc = Nokogiri::HTML(a.title)
|
title = a.title_plain_text
|
||||||
title = doc.text.empty? ? 'no content' : doc.text
|
title = 'no content' if title.blank?
|
||||||
event_time = a.event_time_formated_for_frontend
|
event_time = a.event_time_formated_for_frontend
|
||||||
event_time_formated = a.event_time_formated
|
event_time_formated = a.event_time_formated
|
||||||
{
|
{
|
||||||
|
@ -142,6 +142,8 @@ class EventNewsModsController < ApplicationController
|
||||||
get_tabs_option
|
get_tabs_option
|
||||||
event_news = []
|
event_news = []
|
||||||
use_tag = false
|
use_tag = false
|
||||||
|
tags = tags.collect{|tag| tag.to_s}
|
||||||
|
cats = cats.collect{|cat| cat.to_s}
|
||||||
if @tab_option == 0
|
if @tab_option == 0
|
||||||
event_news = get_event_news_for_pack_data(cats,tags,nil,is_random)
|
event_news = get_event_news_for_pack_data(cats,tags,nil,is_random)
|
||||||
else
|
else
|
||||||
|
@ -164,26 +166,18 @@ class EventNewsModsController < ApplicationController
|
||||||
else
|
else
|
||||||
cats = ["all"] + cats
|
cats = ["all"] + cats
|
||||||
end
|
end
|
||||||
event_news = event_news.sort_by { |a| tmp=a["event_date"].blank?;[tmp ? 0 : 1, tmp ? nil : a["event_date"].to_time] }.reverse
|
event_news = sort_event_news(event_news)
|
||||||
end
|
end
|
||||||
cats = cats.uniq
|
cats = cats.uniq
|
||||||
tags = tags.uniq
|
tags = tags.uniq
|
||||||
tags_translations = tags.map{|tag_id|
|
tags_translations = {'all' => I18n.t(:all)}
|
||||||
if tag_id == "all"
|
Tag.where(:id.in => tags).pluck(:id, :title).each{|id, title_translations|
|
||||||
t = I18n.t(:all)
|
tags_translations[id.to_s] = title_translations[I18n.locale]
|
||||||
else
|
}
|
||||||
t = Tag.find(tag_id).name rescue ""
|
cats_translations = {'all' => I18n.t(:all)}
|
||||||
end
|
Category.where(:id.in => cats).pluck(:id, :title).each{|id, title_translations|
|
||||||
[tag_id,t]
|
cats_translations[id.to_s] = title_translations[I18n.locale]
|
||||||
}.to_h
|
}
|
||||||
cats_translations = cats.map{|cat_id|
|
|
||||||
if cat_id == "all"
|
|
||||||
t = I18n.t(:all)
|
|
||||||
else
|
|
||||||
t = Category.find(cat_id).title rescue ""
|
|
||||||
end
|
|
||||||
[cat_id,t]
|
|
||||||
}.to_h
|
|
||||||
cats_relations = cats_translations.map{|cat_id,t|
|
cats_relations = cats_translations.map{|cat_id,t|
|
||||||
if cat_id == "all"
|
if cat_id == "all"
|
||||||
t = "all"
|
t = "all"
|
||||||
|
@ -420,9 +414,11 @@ class EventNewsModsController < ApplicationController
|
||||||
@all_setting_option = 0
|
@all_setting_option = 0
|
||||||
@image_version = 'thumb'
|
@image_version = 'thumb'
|
||||||
@show_today_data_first = false
|
@show_today_data_first = false
|
||||||
|
@show_options = nil
|
||||||
if subpart.methods.include? 'select_options'.to_sym
|
if subpart.methods.include? 'select_options'.to_sym
|
||||||
ModuleApp.all.select{|tmp| tmp.key.to_s=='event_news_mod'}.each do |modile_app|
|
module_app = ModuleApp.where(key: 'event_news_mod').first
|
||||||
@show_options = modile_app.show_options rescue nil
|
if module_app
|
||||||
|
@show_options = module_app.show_options
|
||||||
end
|
end
|
||||||
subpart.select_options.each do |select_option|
|
subpart.select_options.each do |select_option|
|
||||||
if !(@show_options.nil?)
|
if !(@show_options.nil?)
|
||||||
|
@ -528,15 +524,15 @@ class EventNewsModsController < ApplicationController
|
||||||
event_news = event_news_cache.first.filter_result
|
event_news = event_news_cache.first.filter_result
|
||||||
end
|
end
|
||||||
if devide_flag
|
if devide_flag
|
||||||
feeds_event_news = get_feed_event_news("widget",nil,cats,widget_data_count - top_event_news.count)
|
feeds_event_news, _ = get_feed_event_news("widget",nil,cats,widget_data_count - top_event_news.count)
|
||||||
top_event_news = top_event_news + feeds_event_news.select{|v| v['is_top'] == true}
|
top_event_news += feeds_event_news.select{|v| v['is_top'] == true}
|
||||||
top_event_news = top_event_news.sort_by { |a| tmp=a["postdate"].blank?;[tmp ? 0 : 1, tmp ? nil : a["postdate"].to_time] }.reverse
|
top_event_news = sort_event_news(top_event_news)
|
||||||
rest_count = widget_data_count - top_event_news.count
|
rest_count = widget_data_count - top_event_news.count
|
||||||
if rest_count <= 0
|
if rest_count <= 0
|
||||||
event_news = top_event_news.take(widget_data_count)
|
event_news = top_event_news.take(widget_data_count)
|
||||||
else
|
else
|
||||||
rest_all_event_news = feeds_event_news.select{|v| v['is_top'] != true} + not_top_event_news.take(rest_count)
|
rest_all_event_news = feeds_event_news.select{|v| v['is_top'] != true} + not_top_event_news.take(rest_count)
|
||||||
rest_event_news = rest_all_event_news.sort_by { |a| tmp=a["postdate"].blank?;[tmp ? 0 : 1, tmp ? nil : a["postdate"].to_time] }.reverse.take(rest_count)
|
rest_event_news = sort_event_news(rest_all_event_news).take(rest_count)
|
||||||
event_news = top_event_news + rest_event_news
|
event_news = top_event_news + rest_event_news
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -835,8 +831,8 @@ class EventNewsModsController < ApplicationController
|
||||||
desc = (desc.blank? ? "EventNews image" : desc)
|
desc = (desc.blank? ? "EventNews image" : desc)
|
||||||
link_to_show = (a.is_external_link ? a.external_link : OrbitHelper.url_to_show(a.to_param)) rescue ""
|
link_to_show = (a.is_external_link ? a.external_link : OrbitHelper.url_to_show(a.to_param)) rescue ""
|
||||||
target = a.is_external_link ? "_blank" : "_self"
|
target = a.is_external_link ? "_blank" : "_self"
|
||||||
doc = Nokogiri::HTML(a.title)
|
title = a.title_plain_text
|
||||||
title = doc.text.empty? ? 'no content' : doc.text
|
title = 'no content' if title.blank?
|
||||||
event_time = a.event_time_formated_for_frontend
|
event_time = a.event_time_formated_for_frontend
|
||||||
event_time_formated = a.event_time_formated
|
event_time_formated = a.event_time_formated
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,25 +1,4 @@
|
||||||
module EventNewsHelper
|
module EventNewsHelper
|
||||||
def self.complementaryColor(my_hex)
|
|
||||||
if my_hex[0] == '#'
|
|
||||||
my_hex = my_hex[1..-1]
|
|
||||||
end
|
|
||||||
rgb = my_hex.split(//).each_slice(my_hex.length/3).map{|v| v.join}
|
|
||||||
comp = rgb.map{|a| (255 - a.to_i(16)).to_s(16).rjust(2,'0')}
|
|
||||||
'#'+comp.join
|
|
||||||
end
|
|
||||||
def self.lighten_color(my_hex,percent)
|
|
||||||
if my_hex[0] == '#'
|
|
||||||
my_hex = my_hex[1..-1]
|
|
||||||
end
|
|
||||||
rgb = my_hex.split(//).each_slice(my_hex.length/3).map{|v| v.join}
|
|
||||||
comp = rgb.collect do |a|
|
|
||||||
tmp = a.to_i(16)*(1+percent/100.0)
|
|
||||||
tmp = 255 if tmp>255
|
|
||||||
tmp = 0 if tmp < 0
|
|
||||||
tmp.to_i.to_s(16).rjust(2,'0')
|
|
||||||
end
|
|
||||||
'#'+comp.join
|
|
||||||
end
|
|
||||||
def data_to_human_type(a,set_tag_ids=nil)
|
def data_to_human_type(a,set_tag_ids=nil)
|
||||||
statuses = a.statuses_with_classname.collect do |status|
|
statuses = a.statuses_with_classname.collect do |status|
|
||||||
{
|
{
|
||||||
|
@ -75,7 +54,7 @@ module EventNewsHelper
|
||||||
"img_description" => desc
|
"img_description" => desc
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
def get_feed_annc(type,site_source,locale,categories=nil,max_len=nil)
|
def get_feed_annc(type,site_source,locale,categories=nil,max_len=nil,sort_maps=nil,extra_match_cond=nil)
|
||||||
ma_key = 'event_news_mod'
|
ma_key = 'event_news_mod'
|
||||||
if categories.nil?
|
if categories.nil?
|
||||||
if type == "index"
|
if type == "index"
|
||||||
|
@ -87,116 +66,58 @@ module EventNewsHelper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
categories = ["all"] if categories.length==0
|
categories = ["all"] if categories.length==0
|
||||||
data = SiteFeedAnnc.get_feed_cache(ma_key,categories,site_source,locale,type=='widget',max_len)
|
data = SiteFeedAnnc.get_feed_cache(
|
||||||
|
ma_key,
|
||||||
|
categories,
|
||||||
|
site_source,
|
||||||
|
locale,
|
||||||
|
type=='widget',
|
||||||
|
max_len,
|
||||||
|
sort_maps,
|
||||||
|
extra_match_cond
|
||||||
|
)
|
||||||
data
|
data
|
||||||
end
|
end
|
||||||
def get_feed_event_news(type,site_source=nil,categories=nil,max_len=nil)
|
def get_feed_event_news(type,site_source=nil,categories=nil,max_len=nil,extra_match_cond=[])
|
||||||
locale = OrbitHelper.get_site_locale.to_s
|
locale = OrbitHelper.get_site_locale.to_s
|
||||||
|
feeds = []
|
||||||
|
feeds_count = 0
|
||||||
if !(defined? SiteFeedAnnc).nil?
|
if !(defined? SiteFeedAnnc).nil?
|
||||||
fans = get_feed_annc(type,site_source,locale,categories,max_len)
|
sort_maps = nil
|
||||||
else
|
if @show_today_data_first
|
||||||
feed_anns = OrbitHelper.get_feed_for_module(type)
|
sort_maps = {event_date: :asc, is_top: :desc, postdate: :asc, id: :asc}
|
||||||
fans = []
|
else
|
||||||
feed_anns.each do |fa|
|
sort_maps = {is_top: :desc}
|
||||||
next if !site_source.nil? && site_source != fa["source-site-title"]
|
if EventNewsHelper.is_postdate_sort_first
|
||||||
status = {
|
sort_maps = sort_maps.merge({postdate: :desc, event_date: :desc, id: :desc})
|
||||||
"status" => "<a href='#{fa["source-site"]}' target='_blank' class='feed-source'>#{fa["source-site-title"]}</a>",
|
|
||||||
"status-class" => "status-source"
|
|
||||||
}
|
|
||||||
|
|
||||||
files = fa["event_news_files"].collect{|bf| { "file_url" => bf["file_url"], "file_title" => fa["file_title_translations"][locale] }} rescue []
|
|
||||||
links = fa["event_news_links"].map{|link| { "link_url" => link["link_url"], "link_title" => link["link_title_translations"][locale] } } rescue []
|
|
||||||
event_time_formated = a.event_time_formated
|
|
||||||
s = DateTime.parse(fa["event_date"]) rescue nil
|
|
||||||
e = DateTime.parse(fa["event_end_date"]) rescue nil
|
|
||||||
date_parse_format = fa["all_day"] ? '%Y-%m-%d' : '%Y-%m-%d %H:%M'
|
|
||||||
if s.blank? && e.blank?
|
|
||||||
event_time_formated = ""
|
|
||||||
elsif s.blank?
|
|
||||||
event_time_formated = s.strftime(date_parse_format)
|
|
||||||
elsif e.blank?
|
|
||||||
event_time_formated = "~ " + e.strftime(date_parse_format)
|
|
||||||
else
|
else
|
||||||
if s.to_date == e.to_date
|
sort_maps = sort_maps.merge({event_date: :desc, postdate: :desc, id: :desc})
|
||||||
date_str = s.strftime('%Y-%m-%d')
|
|
||||||
s_time = s.strftime('%H:%M')
|
|
||||||
e_time = e.strftime('%H:%M')
|
|
||||||
event_time_formated = "#{date_str} #{s_time} ~ #{e_time}"
|
|
||||||
else
|
|
||||||
event_time_formated = s.strftime(date_parse_format) + " ~ " + e.strftime(date_parse_format)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
x = {
|
|
||||||
"event_news_links" => links,
|
|
||||||
"event_news_files" => files,
|
|
||||||
"event_carousel_images" => fa["event_carousel_images"].to_a,
|
|
||||||
"title" => fa["title_translations"][locale],
|
|
||||||
"speaker-css" => (fa["speaker_translations"][locale].blank? ? "display: none;" : ""),
|
|
||||||
"host-css" => (fa["host_translations"][locale].blank? ? "display: none;" : ""),
|
|
||||||
"place-css" => (fa["place_translations"][locale].blank? ? "display: none;" : ""),
|
|
||||||
"event-time-css" => (event_time_formated.blank? ? "display: none;" : ""),
|
|
||||||
"notes-css" => (fa["notes_translations"][locale].blank? ? "display: none;" : ""),
|
|
||||||
"event-time-formated" => event_time_formated,
|
|
||||||
"speaker" => (fa["speaker_translations"][locale].to_s rescue ""),
|
|
||||||
"place" => (fa["place_translations"][locale].to_s rescue ""),
|
|
||||||
"host" => (fa["host_translations"][locale].to_s rescue ""),
|
|
||||||
"notes" => (fa["notes_translations"][locale].to_s rescue ""),
|
|
||||||
"subtitle" => fa["subtitle_translations"][locale],
|
|
||||||
"statuses" => [status],
|
|
||||||
"category" => fa["category"],
|
|
||||||
"postdate" => (DateTime.parse(fa["event_date"]) rescue DateTime.now),
|
|
||||||
"event_date" => (DateTime.parse(fa["event_date"]) rescue DateTime.now),
|
|
||||||
"author" => fa["author"],
|
|
||||||
"source-site" => "<a href='#{fa["source-site"]}' target='_blank' class='feed-source'>#{fa["source-site-title"]}</a>",
|
|
||||||
"source-site-title" => fa["source-site-title"],
|
|
||||||
"source-site-link" => fa["source-site"],
|
|
||||||
"link_to_show" => OrbitHelper.url_to_show(fa["params"]),
|
|
||||||
"target" => "_self",
|
|
||||||
"img_src" => fa["image"]["thumb"] || "/assets/event_news-default.jpg",
|
|
||||||
"img_description" => fa["image_description_translations"][locale],
|
|
||||||
"more" => t("event_news.more"),
|
|
||||||
"view_count" => ""
|
|
||||||
}
|
|
||||||
if (!x["title"].empty? rescue false)
|
|
||||||
fans << x
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
match_cond = {
|
||||||
fans
|
"is_hidden" => {"$ne" => true},
|
||||||
end
|
"$and" => [
|
||||||
def filter_by_keywords(sorted,keywords,stime,etime)
|
{"postdate" => {"$lte"=> Time.now}},
|
||||||
kflag = keywords.blank?
|
{
|
||||||
sflag = stime.blank?
|
"$or" => [
|
||||||
eflag = etime.blank?
|
{"deadline" => {"$gte"=> Time.now}},
|
||||||
stime = stime.to_s.split('/')
|
{"deadline" => nil}
|
||||||
stime = Time.zone.local(*stime) rescue nil
|
]
|
||||||
etime = etime.to_s.split('/')
|
}
|
||||||
etime = Time.zone.local(*etime) rescue nil
|
],
|
||||||
if !kflag || !sflag || !eflag
|
"title" => {"$gt"=>""}
|
||||||
sorted.select{|anns|
|
|
||||||
if kflag
|
|
||||||
flag = true
|
|
||||||
else
|
|
||||||
if anns["source-site"].present?
|
|
||||||
title = Nokogiri::HTML(anns["title"].to_s).text
|
|
||||||
else
|
|
||||||
title = Nokogiri::HTML(anns.title.to_s).text
|
|
||||||
end
|
|
||||||
flag = title.include?(keywords.to_s)
|
|
||||||
end
|
|
||||||
if sflag && !eflag
|
|
||||||
flag = flag && (anns.event_date<=etime)
|
|
||||||
elsif !sflag && eflag
|
|
||||||
flag = flag && (anns.event_date>=stime)
|
|
||||||
elsif !sflag && !eflag
|
|
||||||
flag = flag && (anns.event_date>=stime) && (anns.event_date<=etime)
|
|
||||||
end
|
|
||||||
flag
|
|
||||||
}
|
}
|
||||||
else
|
if !extra_match_cond.empty?
|
||||||
sorted
|
match_cond["$and"] += extra_match_cond
|
||||||
|
end
|
||||||
|
if @show_today_data_first
|
||||||
|
match_cond["event_date"] = {"$gte" => Date.today.to_time}
|
||||||
|
end
|
||||||
|
feeds, feeds_count = get_feed_annc(type,site_source,locale,categories,max_len,sort_maps,match_cond)
|
||||||
end
|
end
|
||||||
|
return feeds, feeds_count
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_sorted_event_news(data_count=nil)
|
def get_sorted_event_news(data_count=nil)
|
||||||
params = OrbitHelper.params
|
params = OrbitHelper.params
|
||||||
locale = OrbitHelper.get_site_locale.to_s
|
locale = OrbitHelper.get_site_locale.to_s
|
||||||
|
@ -208,9 +129,7 @@ module EventNewsHelper
|
||||||
tags = @tags
|
tags = @tags
|
||||||
categories = @categories
|
categories = @categories
|
||||||
else
|
else
|
||||||
page = OrbitHelper.page rescue nil
|
page = OrbitHelper.page
|
||||||
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 || []))
|
||||||
|
@ -241,22 +160,47 @@ module EventNewsHelper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if categories.include? 'all'
|
if @enable_search_flag
|
||||||
@categories = module_app.categories
|
if categories.include? 'all'
|
||||||
else
|
@categories = module_app.categories
|
||||||
cat_maps = Category.where(:id.in => categories).collect{|cat| [cat.id.to_s, cat]}.to_h
|
else
|
||||||
@categories = categories.map{|v| cat_maps[v.to_s]}.compact
|
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
|
end
|
||||||
end
|
end
|
||||||
event_news_list = []
|
event_news_list = []
|
||||||
|
event_news = []
|
||||||
|
feeds_count = 0
|
||||||
|
extra_match_cond = []
|
||||||
|
if !params[:keywords].blank?
|
||||||
|
extra_match_cond << {
|
||||||
|
"title_plain_text" => OrbitHelper.get_keyword_regex(params[:keywords])
|
||||||
|
}
|
||||||
|
end
|
||||||
|
if !params[:stime].blank?
|
||||||
|
stime = OrbitHelper.get_time_from_str(params[:stime])
|
||||||
|
extra_match_cond << {
|
||||||
|
"event_date" => {"$gte" => stime}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
if !params[:etime].blank?
|
||||||
|
etime = OrbitHelper.get_time_from_str(params[:etime]) + 1.days
|
||||||
|
extra_match_cond << {
|
||||||
|
"event_date" => {"$lt" => etime}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
if !extra_match_cond.empty?
|
||||||
|
event_news = event_news.and(extra_match_cond)
|
||||||
|
end
|
||||||
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 :
|
||||||
EventNews.can_display_and_sorted
|
EventNews.can_display_and_sorted
|
||||||
|
|
||||||
event_news = event_news
|
event_news = event_news
|
||||||
|
.filter_by_categories(categories, false).filter_by_tags(tags)
|
||||||
.where(:title.nin => ["",nil])
|
.where(:title.nin => ["",nil])
|
||||||
.filter_by_categories(categories,false).filter_by_tags(tags)
|
|
||||||
if @type == "show_widget"
|
if @type == "show_widget"
|
||||||
if !params[:uids].blank?
|
if !params[:uids].blank?
|
||||||
member_profile = MemberProfile.any_in(:uid=>params[:uids])
|
member_profile = MemberProfile.any_in(:uid=>params[:uids])
|
||||||
|
@ -264,58 +208,70 @@ 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.limit(page_number*page_data_count)
|
||||||
event_news_list = event_news.to_a
|
event_news_list = event_news.to_a
|
||||||
if !(defined? SiteFeed).nil?
|
if !(defined? SiteFeed).nil? && @type != "show_widget"
|
||||||
if @type != "show_widget"
|
feeds_anns, feeds_count = get_feed_event_news("index",nil,nil,page_number*page_data_count, extra_match_cond)
|
||||||
feeds_anns = get_feed_event_news("index",nil,nil,page_number*page_data_count)
|
|
||||||
else
|
|
||||||
feeds_anns = []
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if @type != "show_widget"
|
|
||||||
feeds_anns = get_feed_event_news("index",params["source"],nil,page_number*page_data_count)
|
|
||||||
else
|
|
||||||
feeds_anns = []
|
|
||||||
end
|
end
|
||||||
|
elsif @type != "show_widget"
|
||||||
|
feeds_anns, feeds_count = get_feed_event_news("index",params["source"],nil,page_number*page_data_count, extra_match_cond)
|
||||||
end
|
end
|
||||||
if !feeds_anns.blank?
|
if !feeds_anns.blank?
|
||||||
if event_news_list.count != 0
|
top_anns = event_news_list.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 = event_news_list.select{|v| !v.is_top} + feeds_anns.select{|v| v['is_top'] != true}
|
||||||
rest_all_anns = feeds_anns.select{|v| v['is_top'] != true} + event_news_list.select{|v| !v.is_top}
|
all_filter = sort_event_news(top_anns) + sort_event_news(rest_all_anns)
|
||||||
all_sorted = sort_event_news(top_anns) + sort_event_news(rest_all_anns)
|
|
||||||
else
|
|
||||||
all_sorted = sort_event_news(feeds_anns.select{|v| v['is_top']}) + sort_event_news(feeds_anns.select{|v| v['is_top'] != true})
|
|
||||||
end
|
|
||||||
all_filter = filter_by_keywords(all_sorted,params[:keywords],params[:stime],params[:etime])
|
|
||||||
else
|
else
|
||||||
all_filter = filter_by_keywords(event_news_list,params[:keywords],params[:stime],params[:etime])
|
all_filter = event_news_list
|
||||||
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]
|
||||||
else
|
else
|
||||||
sorted = all_filter
|
sorted = all_filter
|
||||||
end
|
end
|
||||||
annc_count = all_filter.count
|
annc_count = event_news.count + feeds_count
|
||||||
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)
|
def sort_event_news(event_news_list)
|
||||||
|
enable_manually_sort = enable_manually_sort
|
||||||
if @show_today_data_first || !EventNewsHelper.is_postdate_sort_first
|
if @show_today_data_first || !EventNewsHelper.is_postdate_sort_first
|
||||||
event_news_list = event_news_list.sort_by { |event_news|
|
if enable_manually_sort
|
||||||
tmp1 = event_news["event_date"].blank?
|
event_news_list = event_news_list.sort_by { |event_news|
|
||||||
tmp2 = event_news["postdate"].blank?
|
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
|
(@show_today_data_first ? a['sort_number'].to_i : -a['sort_number'].to_i),
|
||||||
]
|
tmp1 ? 0 : 1, tmp1 ? nil : event_news["event_date"].to_time,
|
||||||
}
|
tmp2 ? 0 : 1, tmp2 ? nil : event_news["postdate"].to_time
|
||||||
|
]
|
||||||
|
}
|
||||||
|
else
|
||||||
|
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
|
||||||
|
]
|
||||||
|
}
|
||||||
|
end
|
||||||
if !@show_today_data_first
|
if !@show_today_data_first
|
||||||
event_news_list = event_news_list.reverse
|
event_news_list = event_news_list.reverse
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
event_news_list = event_news_list.sort_by { |event_news|
|
if enable_manually_sort
|
||||||
|
event_news_list = event_news_list.sort_by { |event_news|
|
||||||
|
tmp1 = event_news["event_date"].blank?
|
||||||
|
tmp2 = event_news["postdate"].blank?
|
||||||
|
[
|
||||||
|
-a['sort_number'].to_i,
|
||||||
|
tmp2 ? 0 : 1, tmp2 ? nil : event_news["postdate"].to_time,
|
||||||
|
tmp1 ? 0 : 1, tmp1 ? nil : event_news["event_date"].to_time
|
||||||
|
]
|
||||||
|
}.reverse
|
||||||
|
else
|
||||||
|
event_news_list = event_news_list.sort_by { |event_news|
|
||||||
tmp1 = event_news["event_date"].blank?
|
tmp1 = event_news["event_date"].blank?
|
||||||
tmp2 = event_news["postdate"].blank?
|
tmp2 = event_news["postdate"].blank?
|
||||||
[
|
[
|
||||||
|
@ -323,6 +279,7 @@ module EventNewsHelper
|
||||||
tmp1 ? 0 : 1, tmp1 ? nil : event_news["event_date"].to_time
|
tmp1 ? 0 : 1, tmp1 ? nil : event_news["event_date"].to_time
|
||||||
]
|
]
|
||||||
}.reverse
|
}.reverse
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return event_news_list
|
return event_news_list
|
||||||
end
|
end
|
||||||
|
@ -594,18 +551,41 @@ module EventNewsHelper
|
||||||
</div>
|
</div>
|
||||||
</div>").html_safe
|
</div>").html_safe
|
||||||
end
|
end
|
||||||
def self.enable_manually_sort
|
class << self
|
||||||
if defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash
|
def complementaryColor(my_hex)
|
||||||
OrbitHelper::SharedHash['event_news_mod'][:enable_manually_sort]
|
if my_hex[0] == '#'
|
||||||
else
|
my_hex = my_hex[1..-1]
|
||||||
EventNewsSetting.first.enable_manually_sort rescue false
|
end
|
||||||
|
rgb = my_hex.split(//).each_slice(my_hex.length/3).map{|v| v.join}
|
||||||
|
comp = rgb.map{|a| (255 - a.to_i(16)).to_s(16).rjust(2,'0')}
|
||||||
|
'#'+comp.join
|
||||||
end
|
end
|
||||||
end
|
def lighten_color(my_hex,percent)
|
||||||
def self.is_postdate_sort_first
|
if my_hex[0] == '#'
|
||||||
if defined?(OrbitHelper::SharedHash) && OrbitHelper::SharedHash
|
my_hex = my_hex[1..-1]
|
||||||
OrbitHelper::SharedHash['event_news_mod'][:is_postdate_sort_first]
|
end
|
||||||
else
|
rgb = my_hex.split(//).each_slice(my_hex.length/3).map{|v| v.join}
|
||||||
EventNewsSetting.first.is_postdate_sort_first rescue false
|
comp = rgb.collect do |a|
|
||||||
|
tmp = a.to_i(16)*(1+percent/100.0)
|
||||||
|
tmp = 255 if tmp>255
|
||||||
|
tmp = 0 if tmp < 0
|
||||||
|
tmp.to_i.to_s(16).rjust(2,'0')
|
||||||
|
end
|
||||||
|
'#'+comp.join
|
||||||
|
end
|
||||||
|
def 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 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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,8 +8,8 @@ class EventNews
|
||||||
include OrbitTag::Taggable
|
include OrbitTag::Taggable
|
||||||
include OrbitCategory::Categorizable
|
include OrbitCategory::Categorizable
|
||||||
include Slug
|
include Slug
|
||||||
require 'event_news_model/cache'
|
require 'event_news_mod/cache'
|
||||||
include EventNewsModel::Cache
|
include EventNewsMod::Cache
|
||||||
attr_accessor :org_tag_ids, :org_category_id
|
attr_accessor :org_tag_ids, :org_category_id
|
||||||
def tags=(ids)
|
def tags=(ids)
|
||||||
self.org_tag_ids = self.tag_ids
|
self.org_tag_ids = self.tag_ids
|
||||||
|
@ -39,8 +39,8 @@ class EventNews
|
||||||
end
|
end
|
||||||
super(index,value)
|
super(index,value)
|
||||||
end
|
end
|
||||||
SubPart.class_eval { include EventNewsModel::Cache }
|
SubPart.class_eval { include EventNewsMod::Cache }
|
||||||
Page.class_eval { include EventNewsModel::Cache }
|
Page.class_eval { include EventNewsMod::Cache }
|
||||||
before_destroy do
|
before_destroy do
|
||||||
EventNewsCache.all.destroy
|
EventNewsCache.all.destroy
|
||||||
end
|
end
|
||||||
|
@ -63,6 +63,7 @@ class EventNews
|
||||||
field :event_id
|
field :event_id
|
||||||
field :place, type: String, localize: true
|
field :place, type: String, localize: true
|
||||||
field :title, as: :slug_title, type: String, localize: true
|
field :title, as: :slug_title, type: String, localize: true
|
||||||
|
field :title_plain_text, type: String, localize: true
|
||||||
field :speaker, type: String, localize: true
|
field :speaker, type: String, localize: true
|
||||||
field :host, type: String, localize: true
|
field :host, type: String, localize: true
|
||||||
field :subtitle, localize: true
|
field :subtitle, localize: true
|
||||||
|
@ -142,6 +143,7 @@ class EventNews
|
||||||
if self.is_top_changed? && !self.is_top
|
if self.is_top_changed? && !self.is_top
|
||||||
self.sort_number = nil
|
self.sort_number = nil
|
||||||
end
|
end
|
||||||
|
self.migrate_title_plain_text
|
||||||
end
|
end
|
||||||
index({postdate: 1}, { unique: false, background: true })
|
index({postdate: 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 })
|
||||||
|
@ -466,7 +468,7 @@ class EventNews
|
||||||
a["notes_translations"] = self.notes_translations
|
a["notes_translations"] = self.notes_translations
|
||||||
a["text_translations"] = {}
|
a["text_translations"] = {}
|
||||||
text_translations = self.text_translations
|
text_translations = self.text_translations
|
||||||
self.text_translations.each do |l, text|
|
text_translations.each do |l, text|
|
||||||
a["text_translations"][l] = self.class.smart_convertor(text,base_url)
|
a["text_translations"][l] = self.class.smart_convertor(text,base_url)
|
||||||
end
|
end
|
||||||
a["event_date"] = self.event_date
|
a["event_date"] = self.event_date
|
||||||
|
@ -503,7 +505,7 @@ class EventNews
|
||||||
self.event_news_links.each do |bl|
|
self.event_news_links.each do |bl|
|
||||||
b = {}
|
b = {}
|
||||||
b["link_url"] = bl.url
|
b["link_url"] = bl.url
|
||||||
b["link_title_translations"] = bl.title_translations.map{|k,v| [k, (v.blank? ? b["url"] : v)]}.to_h
|
b["link_title_translations"] = bl.title_translations.map{|k,v| [k, (v.blank? ? b["link_url"] : v)]}.to_h
|
||||||
a["event_news_links"] << b
|
a["event_news_links"] << b
|
||||||
end
|
end
|
||||||
self.event_news_files.each do |bf|
|
self.event_news_files.each do |bf|
|
||||||
|
@ -511,7 +513,7 @@ class EventNews
|
||||||
b = {}
|
b = {}
|
||||||
b["description_translations"] = bf.description_translations
|
b["description_translations"] = bf.description_translations
|
||||||
b["file_url"] = base_url + bf.file.url
|
b["file_url"] = base_url + bf.file.url
|
||||||
b["file_title_translations"] = bf.title_translations.map{|k,v| [k, (v.blank? ? File.basename(b["url"]) : v)]}.to_h
|
b["file_title_translations"] = bf.title_translations.map{|k,v| [k, (v.blank? ? File.basename(b["file_url"]) : v)]}.to_h
|
||||||
a["event_news_files"] << b
|
a["event_news_files"] << b
|
||||||
end
|
end
|
||||||
return a
|
return a
|
||||||
|
@ -558,6 +560,11 @@ class EventNews
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def migrate_title_plain_text
|
||||||
|
self.title_plain_text_translations = OrbitHelper.get_plain_text_translations(self.title_translations)
|
||||||
|
end
|
||||||
|
|
||||||
def self.notify_all_feed(force_update=false)
|
def self.notify_all_feed(force_update=false)
|
||||||
related_feeds = EventNewsFeed.where(:remote_urls.nin=>[nil, []]).to_a
|
related_feeds = EventNewsFeed.where(:remote_urls.nin=>[nil, []]).to_a
|
||||||
related_feeds.each do |feed|
|
related_feeds.each do |feed|
|
||||||
|
|
|
@ -13,6 +13,9 @@ class EventNewsSetting
|
||||||
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
|
field :is_postdate_sort_first, type: Boolean, default: false
|
||||||
|
|
||||||
|
field :migrate_flag, type: Array, default: []
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,4 @@
|
||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
if ENV['worker_num']=='0' && File.basename($0) != 'rake' && !Rails.const_defined?('Console')
|
|
||||||
Thread.new do
|
|
||||||
EventNewsFeedCache.regenerate_all
|
|
||||||
end
|
|
||||||
end
|
|
||||||
locales = Site.first.in_use_locales rescue I18n.available_locales
|
locales = Site.first.in_use_locales rescue I18n.available_locales
|
||||||
|
|
||||||
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
|
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
require "event_news_mod/engine"
|
require "event_news_mod/engine"
|
||||||
|
require "event_news_mod/cache"
|
||||||
|
require "event_news_mod/migrate"
|
||||||
module EventNewsMod
|
module EventNewsMod
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
module EventNewsModel
|
module EventNewsMod
|
||||||
module Cache
|
module Cache
|
||||||
require 'active_support/concern'
|
require 'active_support/concern'
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
|
@ -92,6 +92,17 @@ module EventNewsMod
|
||||||
rescue => e
|
rescue => e
|
||||||
puts ['error in event_news',e,e.backtrace]
|
puts ['error in event_news',e,e.backtrace]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if ENV['worker_num']=='0' && File.basename($0) != 'rake' && !Rails.const_defined?('Console')
|
||||||
|
Thread.new do
|
||||||
|
begin
|
||||||
|
Migrate.call
|
||||||
|
rescue => e
|
||||||
|
puts ['event_news_mod',e, e.backtrace]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
OrbitApp.registration "event_news_mod", :type => "ModuleApp" do
|
OrbitApp.registration "event_news_mod", :type => "ModuleApp" do
|
||||||
db = ::Mongoid::Sessions.default
|
db = ::Mongoid::Sessions.default
|
||||||
collection = db[:module_apps]
|
collection = db[:module_apps]
|
||||||
|
@ -117,6 +128,7 @@ module EventNewsMod
|
||||||
authorizable
|
authorizable
|
||||||
frontend_enabled
|
frontend_enabled
|
||||||
feeds_url "/xhr/event_news/feeds"
|
feeds_url "/xhr/event_news/feeds"
|
||||||
|
feeds_time_field (EventNewsHelper.is_postdate_sort_first ? ['postdate', 'event_date'] : ['event_date', 'postdate'])
|
||||||
data_count 1..30
|
data_count 1..30
|
||||||
begin
|
begin
|
||||||
show_options data
|
show_options data
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
module EventNewsMod
|
||||||
|
module Migrate
|
||||||
|
def self.call
|
||||||
|
puts ['event news migrate start']
|
||||||
|
gem_root = EventNewsMod::Engine.root
|
||||||
|
require File.join(gem_root, 'app/models/event_news_setting')
|
||||||
|
require File.join(gem_root, 'app/models/event_news')
|
||||||
|
require File.join(gem_root, 'app/models/event_news_feed')
|
||||||
|
require File.join(gem_root, 'app/models/event_news_feed_cache')
|
||||||
|
|
||||||
|
setting = EventNewsSetting.first
|
||||||
|
|
||||||
|
if !setting.migrate_flag.include?("v1")
|
||||||
|
EventNews.all.pluck(:id, :title).each do |id, title_translations|
|
||||||
|
if title_translations.nil?
|
||||||
|
next
|
||||||
|
end
|
||||||
|
EventNews.where(id: id).view.update_many({
|
||||||
|
"$set" => {
|
||||||
|
title_plain_text: OrbitHelper.get_plain_text_translations(title_translations)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
setting.migrate_flag << "v1"
|
||||||
|
setting.save
|
||||||
|
end
|
||||||
|
|
||||||
|
EventNewsFeedCache.regenerate_all
|
||||||
|
|
||||||
|
puts ['event news migrate end']
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue