add new feature support for feed
This commit is contained in:
parent
7df1bb7bf7
commit
b2a04aebe5
|
@ -1,3 +1,4 @@
|
||||||
|
# encoding: UTF-8
|
||||||
$:.push File.expand_path("../lib", __FILE__)
|
$:.push File.expand_path("../lib", __FILE__)
|
||||||
|
|
||||||
# Maintain your gem's version:
|
# Maintain your gem's version:
|
||||||
|
@ -31,7 +32,7 @@ all_template.each do |folder|
|
||||||
filename = folder+'assets/stylesheets/template/base/_variables.scss'
|
filename = folder+'assets/stylesheets/template/base/_variables.scss'
|
||||||
texts = File.open(filename,'r:UTF-8') do |f|
|
texts = File.open(filename,'r:UTF-8') do |f|
|
||||||
f.read
|
f.read
|
||||||
end
|
end.force_encoding('UTF-8')
|
||||||
s1 = texts.scan(/{|}/)
|
s1 = texts.scan(/{|}/)
|
||||||
if s1.count % 2 != 0
|
if s1.count % 2 != 0
|
||||||
i = texts.rindex(s1[-1])
|
i = texts.rindex(s1[-1])
|
||||||
|
@ -50,7 +51,7 @@ all_template.each do |folder|
|
||||||
File.open(filename,'w') do |f|
|
File.open(filename,'w') do |f|
|
||||||
f.write texts
|
f.write texts
|
||||||
end
|
end
|
||||||
tp_text = File.read(folder+'assets/stylesheets/template/template.scss') rescue ''
|
tp_text = File.read(folder+'assets/stylesheets/template/template.scss').force_encoding('UTF-8') rescue ''
|
||||||
tp_last_text = tp_text
|
tp_last_text = tp_text
|
||||||
tp_text.scan(/@import.*http.*;/).each do |pat|
|
tp_text.scan(/@import.*http.*;/).each do |pat|
|
||||||
if pat.scan(/@import\W+url/).count==0
|
if pat.scan(/@import\W+url/).count==0
|
||||||
|
|
|
@ -147,9 +147,11 @@ class AnnouncementsController < ApplicationController
|
||||||
anns = top_anns
|
anns = top_anns
|
||||||
else
|
else
|
||||||
feeds_anns = get_feed_announcements("widget")
|
feeds_anns = get_feed_announcements("widget")
|
||||||
rest_all_anns = feeds_anns + sorted_anns.select{|v| !v.is_top}.take(rest_count).map{|v| data_to_human_type(v)}
|
top_anns = top_anns + feeds_anns.select{|v| v['is_top']}
|
||||||
|
top_anns = top_anns.sort{|v1,v2| v2["postdate"]<=>v1["postdate"]}
|
||||||
|
rest_all_anns = feeds_anns.select{|v| v['is_top'] != true} + sorted_anns.select{|v| !v.is_top}.take(rest_count).map{|v| data_to_human_type(v)}
|
||||||
rest_anns = rest_all_anns.sort{|v1,v2| v2["postdate"]<=>v1["postdate"]}.take(rest_count)
|
rest_anns = rest_all_anns.sort{|v1,v2| v2["postdate"]<=>v1["postdate"]}.take(rest_count)
|
||||||
anns = top_anns + rest_anns
|
anns = (top_anns + rest_anns).take(widget_data_count)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
mp = (anns[0]["img_src"] rescue "")
|
mp = (anns[0]["img_src"] rescue "")
|
||||||
|
|
|
@ -60,42 +60,69 @@ module AnnouncementsHelper
|
||||||
"img_description" => desc
|
"img_description" => desc
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
def get_feed_annc(type,site_source,locale)
|
||||||
|
ma_key = 'announcement'
|
||||||
|
if type == "index"
|
||||||
|
categories = Array(OrbitHelper.widget_categories)
|
||||||
|
elsif type == "widget"
|
||||||
|
categories = Array(OrbitHelper.widget_categories)
|
||||||
|
else
|
||||||
|
categories = []
|
||||||
|
end
|
||||||
|
if categories.include?("all")
|
||||||
|
feeds = SiteFeedAnnc.where(:channel_key => ma_key)
|
||||||
|
else
|
||||||
|
feeds = SiteFeedAnnc.where(:channel_key => ma_key, :merge_with_category.in => categories)
|
||||||
|
end
|
||||||
|
if feeds.count > 0
|
||||||
|
temp_ids = []
|
||||||
|
data = feeds.collect do |feed|
|
||||||
|
feed.all_contents_for_feed(site_source,locale)
|
||||||
|
end.flatten.compact
|
||||||
|
else
|
||||||
|
data = []
|
||||||
|
end
|
||||||
|
data
|
||||||
|
end
|
||||||
def get_feed_announcements(type,site_source=nil)
|
def get_feed_announcements(type,site_source=nil)
|
||||||
feed_anns = OrbitHelper.get_feed_for_module(type)
|
|
||||||
fans = []
|
|
||||||
locale = OrbitHelper.get_site_locale.to_s
|
locale = OrbitHelper.get_site_locale.to_s
|
||||||
feed_anns.each do |fa|
|
if !(defined? SiteFeedAnnc).nil?
|
||||||
next if !site_source.nil? && site_source != fa["source-site-title"]
|
fans = get_feed_annc(type,site_source,locale)
|
||||||
status = {
|
else
|
||||||
"status" => "<a href='#{fa["source-site"]}' target='_blank' class='feed-source'>#{fa["source-site-title"]}</a>",
|
feed_anns = OrbitHelper.get_feed_for_module(type)
|
||||||
"status-class" => "status-source"
|
fans = []
|
||||||
}
|
feed_anns.each do |fa|
|
||||||
|
next if !site_source.nil? && site_source != fa["source-site-title"]
|
||||||
|
status = {
|
||||||
|
"status" => "<a href='#{fa["source-site"]}' target='_blank' class='feed-source'>#{fa["source-site-title"]}</a>",
|
||||||
|
"status-class" => "status-source"
|
||||||
|
}
|
||||||
|
|
||||||
files = fa["bulletin_files"].collect{|bf| { "file_url" => bf["url"], "file_title" => (fa["title_translations"][locale].blank? ? File.basename(fa["url"]) : fa["title_translations"][locale] rescue '') }} rescue []
|
files = fa["bulletin_files"].collect{|bf| { "file_url" => bf["url"], "file_title" => (fa["title_translations"][locale].blank? ? File.basename(fa["url"]) : fa["title_translations"][locale] rescue '') }} rescue []
|
||||||
links = fa["bulletin_links"].map{|link| { "link_url" => link["url"], "link_title" => (link["title_translations"][locale].blank? ? link["url"] : link["title_translations"][locale]) } } rescue []
|
links = fa["bulletin_links"].map{|link| { "link_url" => link["url"], "link_title" => (link["title_translations"][locale].blank? ? link["url"] : link["title_translations"][locale]) } } rescue []
|
||||||
|
|
||||||
x = {
|
x = {
|
||||||
"bulletin_links" => links,
|
"bulletin_links" => links,
|
||||||
"bulletin_files" => files,
|
"bulletin_files" => files,
|
||||||
"title" => fa["title_translations"][locale],
|
"title" => fa["title_translations"][locale],
|
||||||
"subtitle" => fa["subtitle_translations"][locale],
|
"subtitle" => fa["subtitle_translations"][locale],
|
||||||
"statuses" => [status],
|
"statuses" => [status],
|
||||||
"category" => fa["category"],
|
"category" => fa["category"],
|
||||||
"postdate" => fa["postdate"],
|
"postdate" => fa["postdate"],
|
||||||
"author" => fa["author"],
|
"author" => fa["author"],
|
||||||
"is_top" => 0,
|
"source-site" => "<a href='#{fa["source-site"]}' target='_blank' class='feed-source'>#{fa["source-site-title"]}</a>",
|
||||||
"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-title" => fa["source-site-title"],
|
"source-site-link" => fa["source-site"],
|
||||||
"source-site-link" => fa["source-site"],
|
"link_to_show" => OrbitHelper.url_to_show(fa["params"]),
|
||||||
"link_to_show" => OrbitHelper.url_to_show(fa["params"]),
|
"target" => "_self",
|
||||||
"target" => "_self",
|
"img_src" => fa["image"]["thumb"] || "/assets/announcement-default.jpg",
|
||||||
"img_src" => fa["image"]["thumb"] || "/assets/announcement-default.jpg",
|
"img_description" => fa["image_description_translations"][locale],
|
||||||
"img_description" => fa["image_description_translations"][locale],
|
"more" => t(:more_plus),
|
||||||
"more" => t(:more_plus),
|
"view_count" => ""
|
||||||
"view_count" => ""
|
}
|
||||||
}
|
if (!x["title"].empty? rescue false)
|
||||||
if (!x["title"].empty? rescue false)
|
fans << x
|
||||||
fans << x
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
fans
|
fans
|
||||||
|
@ -137,12 +164,12 @@ module AnnouncementsHelper
|
||||||
end
|
end
|
||||||
if !feeds_anns.blank?
|
if !feeds_anns.blank?
|
||||||
if announcements.count != 0
|
if announcements.count != 0
|
||||||
top_anns = announcements.select{|v| v.is_top}
|
top_anns = announcements.select{|v| v.is_top} + feeds_anns.select{|v| v['is_top']}
|
||||||
rest_all_anns = feeds_anns + announcements.select{|v| !v.is_top}
|
rest_all_anns = feeds_anns.select{|v| v['is_top'] != true} + announcements.select{|v| !v.is_top}
|
||||||
rest_anns = rest_all_anns.sort{|v1,v2| v2["postdate"]<=>v1["postdate"]}
|
rest_anns = rest_all_anns.sort{|v1,v2| v2["postdate"]<=>v1["postdate"]}
|
||||||
all_sorted = top_anns + rest_anns
|
all_sorted = top_anns.sort{|v1,v2| v2["postdate"]<=>v1["postdate"]} + rest_anns
|
||||||
else
|
else
|
||||||
all_sorted = feeds_anns.sort{|v1,v2| v2["postdate"]<=>v1["postdate"]}
|
all_sorted = feeds_anns.sort{|v1,v2| [v2['is_top'],v2["postdate"]]<=>[v1['is_top'],v1["postdate"]]}
|
||||||
end
|
end
|
||||||
all_filter = filter_by_keywords(all_sorted,params[:keywords])
|
all_filter = filter_by_keywords(all_sorted,params[:keywords])
|
||||||
else
|
else
|
||||||
|
|
|
@ -71,29 +71,6 @@ class Site
|
||||||
mount_uploader :site_logo_1, ImageUploader
|
mount_uploader :site_logo_1, ImageUploader
|
||||||
mount_uploader :favicon, ImageUploader
|
mount_uploader :favicon, ImageUploader
|
||||||
mount_uploader :mobile_icon, ImageUploader
|
mount_uploader :mobile_icon, ImageUploader
|
||||||
Impression.class_eval{
|
|
||||||
def self.create_date_for_group(date)
|
|
||||||
{'_id'=>{'year'=>date.year,'month'=>date.month,'day'=>date.day},'count'=>0}
|
|
||||||
end
|
|
||||||
def self.group_by(field,day_limit,start_day=Date.today,format = 'day')
|
|
||||||
limit_ele = self.desc(:id).where({ created_at: { "$lt" => start_day-(day_limit-2).days }}).first || self.first
|
|
||||||
key_op = [['year','$year'],['month', '$month'], ['day', '$dayOfMonth']]
|
|
||||||
key_op = key_op.take(1 + key_op.find_index { |key, op| format == key })
|
|
||||||
project_date_fields = Hash[*key_op.collect { |key, op| [key, {op => "$#{field}"}] }.flatten]
|
|
||||||
group_id_fields = Hash[*key_op.collect { |key, op| [key, "$#{key}"] }.flatten]
|
|
||||||
pipeline = [
|
|
||||||
{"$match"=> {"_id" => {"$gte" => (limit_ele['_id'] rescue '')}}},
|
|
||||||
{"$project" => {field => 1}.merge(project_date_fields)},
|
|
||||||
{"$group" => {"_id" => group_id_fields,"count" => {"$sum" => 1}}},
|
|
||||||
{"$sort" => {"_id"=>-1}}
|
|
||||||
]
|
|
||||||
tmp = collection.aggregate(pipeline)
|
|
||||||
if tmp.count < day_limit
|
|
||||||
tmp.concat(Array.new(day_limit-tmp.count).map.with_index.map{|v,i| create_date_for_group(start_day+i.days)})
|
|
||||||
end
|
|
||||||
tmp
|
|
||||||
end
|
|
||||||
}
|
|
||||||
after_initialize do
|
after_initialize do
|
||||||
if !self.new_record?
|
if !self.new_record?
|
||||||
if self.is_hidden_orbit_bar.nil?
|
if self.is_hidden_orbit_bar.nil?
|
||||||
|
|
Loading…
Reference in New Issue