fix update manager error and accelerate the announcement widget loading
speed
This commit is contained in:
parent
8546eb10a4
commit
c9abece068
|
@ -37,7 +37,7 @@ all_template.each do |folder|
|
||||||
i = texts.rindex(s1[-1])
|
i = texts.rindex(s1[-1])
|
||||||
texts[i] = ""
|
texts[i] = ""
|
||||||
end
|
end
|
||||||
regex_pattern = /.response-content {\n position: static;\n}|.response-content {\n position: relative;\n}|.response-content[^{]*{[^}]*@media[^{]*{[^{]*}[^{]*@media[^{]*{[^{]*}[^}]*}[^}]*}/m
|
regex_pattern = /.response-content {\n justify-self: auto;\n}|.response-content {\n position: static;\n}|.response-content {\n position: relative;\n}|.response-content[^{]*{[^}]*@media[^{]*{[^{]*}[^{]*@media[^{]*{[^{]*}[^}]*}[^}]*}/m
|
||||||
if !texts.include? "$font-h1:"
|
if !texts.include? "$font-h1:"
|
||||||
texts = "$font-h1: 1.5rem;\n$font-h2: 1.35rem;\n$font-h3: 1.2rem;\n$font-h4: 1.1rem;\n$font-h5: 1rem;\n$font-h6: 0.9rem;\n\n" + texts
|
texts = "$font-h1: 1.5rem;\n$font-h2: 1.35rem;\n$font-h3: 1.2rem;\n$font-h4: 1.1rem;\n$font-h5: 1rem;\n$font-h6: 0.9rem;\n\n" + texts
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,7 +13,7 @@ class AnnouncementFeedsController < ApplicationController
|
||||||
if !@bf.nil?
|
if !@bf.nil?
|
||||||
tags = @bf.tag_ids
|
tags = @bf.tag_ids
|
||||||
if !tags.empty?
|
if !tags.empty?
|
||||||
@announcements = Bulletin.can_display.is_approved.filter_by_tags(tags)
|
@announcements = Bulletin.can_display_and_sorted.is_approved.filter_by_tags(tags)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
@ -74,17 +74,17 @@ class AnnouncementFeedsController < ApplicationController
|
||||||
if !dt.nil?
|
if !dt.nil?
|
||||||
dt = DateTime.parse(dt)
|
dt = DateTime.parse(dt)
|
||||||
dtt = dt + 1.day
|
dtt = dt + 1.day
|
||||||
announcements = Bulletin.where(:postdate.gt => dt, :postdate.lt => dtt).can_display.is_approved.filter_by_tags(tags)
|
announcements = Bulletin.where(:postdate.gt => dt, :postdate.lt => dtt).can_display_and_sorted.is_approved.filter_by_tags(tags)
|
||||||
elsif !startdt.nil? && enddt.nil?
|
elsif !startdt.nil? && enddt.nil?
|
||||||
startdt = DateTime.parse(startdt)
|
startdt = DateTime.parse(startdt)
|
||||||
enddt = DateTime.now
|
enddt = DateTime.now
|
||||||
announcements = Bulletin.where(:postdate.gt => startdt, :postdate.lt => enddt).can_display.is_approved.filter_by_tags(tags)
|
announcements = Bulletin.where(:postdate.gt => startdt, :postdate.lt => enddt).can_display_and_sorted.is_approved.filter_by_tags(tags)
|
||||||
elsif !startdt.nil? && !enddt.nil?
|
elsif !startdt.nil? && !enddt.nil?
|
||||||
startdt = DateTime.parse(startdt)
|
startdt = DateTime.parse(startdt)
|
||||||
enddt = DateTime.parse(enddt) + 1.day
|
enddt = DateTime.parse(enddt) + 1.day
|
||||||
announcements = Bulletin.where(:postdate.gt => startdt, :postdate.lt => enddt).can_display.is_approved.filter_by_tags(tags)
|
announcements = Bulletin.where(:postdate.gt => startdt, :postdate.lt => enddt).can_display_and_sorted.is_approved.filter_by_tags(tags)
|
||||||
else
|
else
|
||||||
announcements = Bulletin.all.can_display.is_approved.filter_by_tags(tags)
|
announcements = Bulletin.all.can_display_and_sorted.is_approved.filter_by_tags(tags)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
announcements = []
|
announcements = []
|
||||||
|
|
|
@ -2,9 +2,8 @@ class AnnouncementsController < ApplicationController
|
||||||
include AnnouncementsHelper
|
include AnnouncementsHelper
|
||||||
def index
|
def index
|
||||||
Bulletin.remove_expired_status
|
Bulletin.remove_expired_status
|
||||||
announcements,sorted,total_pages = get_sorted_annc
|
sorted,total_pages = get_sorted_annc
|
||||||
anns = []
|
anns = sorted.collect do |a|
|
||||||
sorted.each do |a|
|
|
||||||
if !a["source-site"].present?
|
if !a["source-site"].present?
|
||||||
statuses = a.statuses_with_classname.collect do |status|
|
statuses = a.statuses_with_classname.collect do |status|
|
||||||
{
|
{
|
||||||
|
@ -22,7 +21,7 @@ class AnnouncementsController < ApplicationController
|
||||||
target = a.is_external_link ? "_blank" : "_self"
|
target = a.is_external_link ? "_blank" : "_self"
|
||||||
doc = Nokogiri::HTML(a.title)
|
doc = Nokogiri::HTML(a.title)
|
||||||
title = doc.text.empty? ? 'no content' : doc.text
|
title = doc.text.empty? ? 'no content' : doc.text
|
||||||
anns << {
|
{
|
||||||
"bulletin_links" => links,
|
"bulletin_links" => links,
|
||||||
"bulletin_files" => files,
|
"bulletin_files" => files,
|
||||||
"title" => a.title,
|
"title" => a.title,
|
||||||
|
@ -43,11 +42,11 @@ class AnnouncementsController < ApplicationController
|
||||||
"view_count" => a.view_count
|
"view_count" => a.view_count
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
anns << a
|
a
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
#If no data , hide title&table
|
#If no data , hide title&table
|
||||||
if announcements.count == 0
|
if sorted.count == 0
|
||||||
display = "hide"
|
display = "hide"
|
||||||
end
|
end
|
||||||
# anns = anns.concat(feeds_anns)
|
# anns = anns.concat(feeds_anns)
|
||||||
|
@ -75,21 +74,11 @@ class AnnouncementsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def random_announcement_widget
|
def random_announcement_widget
|
||||||
uid = OrbitHelper.params[:uid] rescue ""
|
pack_data(true)
|
||||||
tags = OrbitHelper.widget_tags
|
|
||||||
categories = OrbitHelper.widget_categories || []
|
|
||||||
announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil],:uid.ne => uid, :category_id.in => categories).and(:title.ne => nil).can_display.is_approved.filter_by_tags(tags).sample(OrbitHelper.widget_data_count)
|
|
||||||
|
|
||||||
pack_data(announcements, [])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def widget
|
def widget
|
||||||
Bulletin.remove_expired_status
|
pack_data()
|
||||||
uid = OrbitHelper.params[:uid] rescue ""
|
|
||||||
tags = OrbitHelper.widget_tags
|
|
||||||
announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil],:uid.ne => uid).and(:title.ne => nil, :is_top.ne => true).can_display.is_approved.filter_by_widget_categories([],false).filter_by_tags(tags).to_a
|
|
||||||
top_anns = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil], :is_top => true, :uid.ne => uid).and(:title.ne => nil).can_display.is_approved.filter_by_widget_categories([],false).filter_by_tags(tags).to_a
|
|
||||||
pack_data(announcements, top_anns)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_cloud
|
def tag_cloud
|
||||||
|
@ -97,7 +86,7 @@ class AnnouncementsController < ApplicationController
|
||||||
temp = []
|
temp = []
|
||||||
ma.tags.each do |tag|
|
ma.tags.each do |tag|
|
||||||
t1 = tag.taggings.collect{|t| t.taggable_id.to_s}
|
t1 = tag.taggings.collect{|t| t.taggable_id.to_s}
|
||||||
count = Bulletin.where(:id.in => t1).can_display.count
|
count = Bulletin.where(:id.in => t1).can_display_and_sorted.count
|
||||||
temp << {
|
temp << {
|
||||||
"tag-name" => tag.name,
|
"tag-name" => tag.name,
|
||||||
"count" => count,
|
"count" => count,
|
||||||
|
@ -120,85 +109,52 @@ class AnnouncementsController < ApplicationController
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def pack_data(announcements, top_anns = [])
|
def pack_data(is_random=false)
|
||||||
page = Page.where(:module => "announcement").first rescue nil
|
t1 = Time.now
|
||||||
|
tags = OrbitHelper.widget_tags || []
|
||||||
|
cats = OrbitHelper.widget_categories || []
|
||||||
subpart = OrbitHelper.get_current_widget
|
subpart = OrbitHelper.get_current_widget
|
||||||
@image_version = 'thumb'
|
anns_cache = AnnsCache.where(parent_id: subpart.id)
|
||||||
if subpart.methods.include? 'select_options'.to_sym
|
widget_data_count = OrbitHelper.widget_data_count
|
||||||
ModuleApp.all.select{|tmp| tmp.key.to_s=='announcement'}.each do |modile_app|
|
if !(defined? SiteFeed).nil? || anns_cache.count != 1 || is_random
|
||||||
@show_options = modile_app.show_options rescue nil
|
page = Page.where(:module => "announcement").first rescue nil
|
||||||
end
|
Bulletin.remove_expired_status
|
||||||
subpart.select_options.each do |select_option|
|
uid = OrbitHelper.params[:uid] rescue ""
|
||||||
if !(@show_options.nil?) && select_option.field_name == @show_options.keys.first.to_s
|
set_image_version_for_widget
|
||||||
value = YAML.load(select_option.value)
|
sorted_anns = Bulletin.where(:title.nin => ["",nil],:is_preview.in=>[false,nil], :uid.ne => uid)
|
||||||
if value[I18n.locale] == t('announcement.small_size')
|
.can_display_and_sorted.is_approved
|
||||||
@image_version = 'thumb'
|
.filter_by_widget_categories(cats,false).filter_by_tags(tags)
|
||||||
elsif value[I18n.locale] == t('announcement.medium_size')
|
if !is_random
|
||||||
@image_version = 'mobile'
|
sorted_anns = sorted_anns.limit(widget_data_count)
|
||||||
elsif value[I18n.locale] == t('announcement.orignal_size')
|
if anns_cache.count > 1
|
||||||
@image_version = 'orignal'
|
anns_cache.destroy
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
AnnsCache.create(parent_id: subpart.id,filter_result: sorted_anns.map{|v| v.id})
|
||||||
|
else
|
||||||
|
sorted_anns = sorted_anns.sample(widget_data_count)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
sorted_anns = Bulletin.find(anns_cache.first.filter_result)
|
||||||
|
sorted_anns = sorted_anns.sort_by{|v| [(v.is_top==true ? 1 : 0),v['postdate']]}.reverse
|
||||||
end
|
end
|
||||||
|
if (defined? SiteFeed).nil? || is_random
|
||||||
|
anns = sorted_anns.map{|v| data_to_human_type(v)}
|
||||||
|
else
|
||||||
|
top_anns = sorted_anns.select{|v| v.is_top}.map{|v| data_to_human_type(v)}
|
||||||
|
rest_count = widget_data_count - top_anns.count
|
||||||
|
if rest_count <= 0
|
||||||
|
anns = top_anns
|
||||||
|
else
|
||||||
feeds_anns = get_feed_announcements("widget")
|
feeds_anns = get_feed_announcements("widget")
|
||||||
announcements = announcements + feeds_anns
|
rest_all_anns = feeds_anns + sorted_anns.select{|v| !v.is_top}.take(rest_count).map{|v| data_to_human_type(v)}
|
||||||
if !feeds_anns.blank?
|
rest_anns = rest_all_anns.sort_by{|v| v["postdate"]}.take(rest_count)
|
||||||
sorted = announcements.sort{ |k,v| v["postdate"] <=> k["postdate"] }
|
anns = top_anns + rest_anns
|
||||||
sorted = top_anns + sorted
|
|
||||||
sorted = Kaminari.paginate_array(sorted).page(1).per(OrbitHelper.widget_data_count) rescue []
|
|
||||||
else
|
|
||||||
announcements = top_anns + announcements
|
|
||||||
sorted = Kaminari.paginate_array(announcements).page(1).per(OrbitHelper.widget_data_count) rescue []
|
|
||||||
end
|
|
||||||
anns = []
|
|
||||||
sorted.each do |a|
|
|
||||||
if !a["source-site"].present?
|
|
||||||
statuses = a.statuses_with_classname.collect do |status|
|
|
||||||
{
|
|
||||||
"status" => status["name"],
|
|
||||||
"status-class" => "status-#{status['classname']}"
|
|
||||||
}
|
|
||||||
end
|
|
||||||
files = a.bulletin_files.map{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title rescue '') } if file.enabled_for?(locale) } rescue []
|
|
||||||
files.delete(nil)
|
|
||||||
links = a.bulletin_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue []
|
|
||||||
author = User.find(a.create_user_id).member_profile.name rescue ""
|
|
||||||
desc = a.image_description
|
|
||||||
desc = (desc.nil? || desc == "" ? "announcement image" : desc)
|
|
||||||
link_to_show = a.is_external_link ? a.external_link : OrbitHelper.widget_item_url(a.to_param)
|
|
||||||
target = a.is_external_link ? "_blank" : "_self"
|
|
||||||
if @image_version == 'thumb'
|
|
||||||
image_url = a.image.thumb.url
|
|
||||||
elsif @image_version == 'mobile'
|
|
||||||
image_url = a.image.mobile.url
|
|
||||||
else
|
|
||||||
image_url = a.image.url
|
|
||||||
end
|
|
||||||
anns << {
|
|
||||||
"bulletin_links" => links,
|
|
||||||
"bulletin_files" => files,
|
|
||||||
"title" => a.title,
|
|
||||||
"source-site" => "",
|
|
||||||
"source-site-title" => "",
|
|
||||||
"source-site-link" => "",
|
|
||||||
"subtitle" => a.subtitle,
|
|
||||||
"statuses" => statuses,
|
|
||||||
"category" => a.category.title,
|
|
||||||
"postdate" => a.postdate,
|
|
||||||
"author" => author,
|
|
||||||
"link_to_show" => link_to_show,
|
|
||||||
"target" => target,
|
|
||||||
"img_src" => image_url || "/assets/announcement-default.jpg",
|
|
||||||
"img_description" => desc
|
|
||||||
}
|
|
||||||
else
|
|
||||||
anns << a
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
mp = (anns[0]["img_src"] rescue "")
|
mp = (anns[0]["img_src"] rescue "")
|
||||||
mpd = (anns[0]["img_description"] rescue "")
|
mpd = (anns[0]["img_description"] rescue "")
|
||||||
|
t2 = Time.now
|
||||||
|
puts ['anns',tags,t2-t1]
|
||||||
{
|
{
|
||||||
"announcements" => anns,
|
"announcements" => anns,
|
||||||
"extras" => {
|
"extras" => {
|
||||||
|
@ -223,7 +179,7 @@ class AnnouncementsController < ApplicationController
|
||||||
if is_preview
|
if is_preview
|
||||||
announcement = Bulletin.where(:uid => uid).first
|
announcement = Bulletin.where(:uid => uid).first
|
||||||
else
|
else
|
||||||
announcement = Bulletin.can_display.where(:uid => uid).first
|
announcement = Bulletin.can_display_and_sorted.where(:uid => uid).first
|
||||||
end
|
end
|
||||||
url_to_edit = OrbitHelper.user_can_edit?(announcement) ? "/admin/announcements/#{announcement.id.to_s}/edit" : ""
|
url_to_edit = OrbitHelper.user_can_edit?(announcement) ? "/admin/announcements/#{announcement.id.to_s}/edit" : ""
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,65 @@
|
||||||
module AnnouncementsHelper
|
module AnnouncementsHelper
|
||||||
|
def set_image_version_for_widget
|
||||||
|
subpart = OrbitHelper.get_current_widget
|
||||||
|
@image_version = 'thumb'
|
||||||
|
if subpart.methods.include? 'select_options'.to_sym
|
||||||
|
ModuleApp.all.select{|tmp| tmp.key.to_s=='announcement'}.each do |modile_app|
|
||||||
|
@show_options = modile_app.show_options rescue nil
|
||||||
|
end
|
||||||
|
subpart.select_options.each do |select_option|
|
||||||
|
if !(@show_options.nil?) && select_option.field_name == @show_options.keys.first.to_s
|
||||||
|
value = YAML.load(select_option.value)
|
||||||
|
if value[I18n.locale] == t('announcement.small_size')
|
||||||
|
@image_version = 'thumb'
|
||||||
|
elsif value[I18n.locale] == t('announcement.medium_size')
|
||||||
|
@image_version = 'mobile'
|
||||||
|
elsif value[I18n.locale] == t('announcement.orignal_size')
|
||||||
|
@image_version = 'orignal'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
def data_to_human_type(a)
|
||||||
|
statuses = a.statuses_with_classname.collect do |status|
|
||||||
|
{
|
||||||
|
"status" => status["name"],
|
||||||
|
"status-class" => "status-#{status['classname']}"
|
||||||
|
}
|
||||||
|
end
|
||||||
|
files = a.bulletin_files.map{|file| { "file_url" => file.file.url, "file_title" => (file.title.blank? ? File.basename(file.file.path) : file.title rescue '') } if file.enabled_for?(locale) } rescue []
|
||||||
|
files.delete(nil)
|
||||||
|
links = a.bulletin_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue []
|
||||||
|
author = User.find(a.create_user_id).member_profile.name rescue ""
|
||||||
|
desc = a.image_description
|
||||||
|
desc = (desc.nil? || desc == "" ? "announcement image" : desc)
|
||||||
|
link_to_show = a.is_external_link ? a.external_link : OrbitHelper.widget_item_url(a.to_param)
|
||||||
|
target = a.is_external_link ? "_blank" : "_self"
|
||||||
|
if @image_version == 'thumb'
|
||||||
|
image_url = a.image.thumb.url
|
||||||
|
elsif @image_version == 'mobile'
|
||||||
|
image_url = a.image.mobile.url
|
||||||
|
else
|
||||||
|
image_url = a.image.url
|
||||||
|
end
|
||||||
|
{
|
||||||
|
"bulletin_links" => links,
|
||||||
|
"bulletin_files" => files,
|
||||||
|
"title" => a.title,
|
||||||
|
"source-site" => "",
|
||||||
|
"source-site-title" => "",
|
||||||
|
"source-site-link" => "",
|
||||||
|
"subtitle" => a.subtitle,
|
||||||
|
"statuses" => statuses,
|
||||||
|
"category" => a.category.title,
|
||||||
|
"postdate" => a.postdate,
|
||||||
|
"author" => author,
|
||||||
|
"link_to_show" => link_to_show,
|
||||||
|
"target" => target,
|
||||||
|
"img_src" => image_url || "/assets/announcement-default.jpg",
|
||||||
|
"img_description" => desc
|
||||||
|
}
|
||||||
|
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)
|
feed_anns = OrbitHelper.get_feed_for_module(type)
|
||||||
fans = []
|
fans = []
|
||||||
|
@ -39,77 +100,65 @@ module AnnouncementsHelper
|
||||||
end
|
end
|
||||||
fans
|
fans
|
||||||
end
|
end
|
||||||
def test
|
def filter_by_keywords(sorted,keywords,postdate)
|
||||||
123
|
sorted.select{|anns|
|
||||||
|
flag1 = true
|
||||||
|
if !keywords.nil?
|
||||||
|
if anns["source-site"].present?
|
||||||
|
title = Nokogiri::HTML(anns["title"].to_s).text
|
||||||
|
else
|
||||||
|
title = Nokogiri::HTML(anns.title.to_s).text
|
||||||
|
end
|
||||||
|
flag1 = title.include?(keywords.to_s)
|
||||||
|
end
|
||||||
|
flag1
|
||||||
|
}
|
||||||
end
|
end
|
||||||
def get_sorted_annc
|
def get_sorted_annc
|
||||||
|
t1 = Time.now
|
||||||
params = OrbitHelper.params
|
params = OrbitHelper.params
|
||||||
locale = OrbitHelper.get_site_locale.to_s
|
locale = OrbitHelper.get_site_locale.to_s
|
||||||
page = Page.where(url:params['url']).first
|
page = Page.where(url:params['url']).first
|
||||||
|
page_number = OrbitHelper.page_number.to_i
|
||||||
|
page_number = 1 if page_number == 0
|
||||||
|
page_data_count = OrbitHelper.page_data_count.to_i
|
||||||
feeds_anns = []
|
feeds_anns = []
|
||||||
tags = page.tags
|
tags = page.tags
|
||||||
if !tags.blank?
|
categories = params['category']=='all' ? (page.categories || []) : ([Category.find(params['category'])] rescue (page.categories || []))
|
||||||
announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).and(:title.ne => nil).can_display.is_approved.filter_by_categories(page.categories || [],false).filter_by_tags(tags).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count).to_a
|
|
||||||
else
|
|
||||||
if !params["source"].present?
|
if !params["source"].present?
|
||||||
announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).and(:title.ne => nil, :is_top.ne => true).can_display.is_approved.filter_by_categories(page.categories || [],false).filter_by_tags.to_a
|
announcements = Bulletin.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
|
||||||
|
if (defined? SiteFeed).nil?
|
||||||
feeds_anns = get_feed_announcements("index")
|
feeds_anns = get_feed_announcements("index")
|
||||||
|
end
|
||||||
else
|
else
|
||||||
announcements = []
|
announcements = []
|
||||||
feeds_anns = get_feed_announcements("index",params["source"])
|
feeds_anns = get_feed_announcements("index",params["source"])
|
||||||
end
|
end
|
||||||
end
|
|
||||||
# (OrbitHelper.page_number == 1 or OrbitHelper.page_number.nil?) &&
|
|
||||||
if !feeds_anns.blank?
|
if !feeds_anns.blank?
|
||||||
announcements = announcements.concat(feeds_anns)
|
if announcements.count != 0
|
||||||
sorted = announcements.sort{ |k,v| v["postdate"] <=> k["postdate"] }
|
top_anns = announcements.select{|v| v.is_top}
|
||||||
if params["keywords"].present?
|
rest_all_anns = feeds_anns + announcements.select{|v| !v.is_top}
|
||||||
sorted = sorted.find_all{|anns|
|
rest_anns = rest_all_anns.sort_by{|v| v["postdate"]}
|
||||||
if anns["source-site"].present?
|
anns = top_anns + rest_anns
|
||||||
/#{params[:keywords].to_s}/i.match anns["title"]
|
all_sorted = anns.sort_by{|v| v["postdate"] }
|
||||||
else
|
else
|
||||||
/#{params[:keywords].to_s}/i.match anns.title
|
all_sorted = feeds_anns.sort_by{|v| v["postdate"] }
|
||||||
end
|
end
|
||||||
}
|
all_filter = filter_by_keywords(all_sorted,params[:keywords],params[:postdate])
|
||||||
end
|
|
||||||
if params["postdate"].present?
|
|
||||||
sorted = sorted.find_all{|anns|
|
|
||||||
if anns["source-site"].present?
|
|
||||||
/#{params[:postdate].to_s}/i.match anns["postdate"].strftime("%Y-%m") if !anns["postdate"].nil?
|
|
||||||
else
|
else
|
||||||
/#{params[:postdate].to_s}/i.match anns.postdate.strftime("%Y-%m") if !anns.postdate.nil?
|
all_filter = filter_by_keywords(announcements,params[:keywords],params[:postdate])
|
||||||
end
|
end
|
||||||
}
|
if page_data_count != 0
|
||||||
end
|
sorted = all_filter[(page_number-1)*page_data_count...page_number*page_data_count]
|
||||||
sorted = Kaminari.paginate_array(sorted).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count) rescue []
|
|
||||||
else
|
else
|
||||||
if params["keywords"].present?
|
sorted = all_filter
|
||||||
announcements = announcements.find_all{|anns| /#{params[:keywords].to_s}/i.match anns.title}
|
|
||||||
end
|
end
|
||||||
if params["postdate"].present?
|
annc_count = all_filter.count
|
||||||
announcements = announcements.find_all{|anns|
|
total_pages = page_data_count == 0 ? 1 : (annc_count.to_f / page_data_count).ceil
|
||||||
if !anns.postdate.nil?
|
t2 = Time.now
|
||||||
/#{params[:postdate].to_s}/i.match anns.postdate.strftime("%Y-%m")
|
puts ['get_sorted_annc',t2-t1]
|
||||||
end
|
[sorted,total_pages]
|
||||||
}
|
|
||||||
end
|
|
||||||
sorted = Kaminari.paginate_array(announcements).page(1).per(OrbitHelper.page_data_count) rescue []
|
|
||||||
end
|
|
||||||
begin
|
|
||||||
if !tags.blank?
|
|
||||||
annc_count = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).and(:title.ne => nil).can_display.is_approved.filter_by_categories(page.categories || [],false).filter_by_tags(tags).count
|
|
||||||
else
|
|
||||||
if !params["source"].present?
|
|
||||||
annc_count = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).and(:title.ne => nil, :is_top.ne => true).can_display.is_approved.filter_by_categories(page.categories || [],false).filter_by_tags.count
|
|
||||||
annc_count += get_feed_announcements("index").count
|
|
||||||
else
|
|
||||||
annc_count = get_feed_announcements("index",params["source"]).count
|
|
||||||
end
|
|
||||||
end
|
|
||||||
total_pages = (annc_count * 1.0 / OrbitHelper.page_data_count).ceil
|
|
||||||
rescue
|
|
||||||
total_pages = 1
|
|
||||||
end
|
|
||||||
[announcements,sorted,total_pages]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
class AnnsCache
|
||||||
|
include Mongoid::Document
|
||||||
|
field :parent_id
|
||||||
|
field :filter_result,type: Array,default: []
|
||||||
|
field :tag_ids,type: Array,default: []
|
||||||
|
field :cat_ids,type: Array,default: []
|
||||||
|
end
|
|
@ -8,6 +8,9 @@ class Bulletin
|
||||||
include OrbitTag::Taggable
|
include OrbitTag::Taggable
|
||||||
include OrbitCategory::Categorizable
|
include OrbitCategory::Categorizable
|
||||||
include Slug
|
include Slug
|
||||||
|
require 'bulletin_model/cache'
|
||||||
|
include BulletinModel::Cache
|
||||||
|
SubPart.class_eval { include BulletinModel::Cache }
|
||||||
|
|
||||||
field :title, type: String, localize: true
|
field :title, type: String, localize: true
|
||||||
field :subtitle, localize: true
|
field :subtitle, localize: true
|
||||||
|
@ -47,10 +50,11 @@ class Bulletin
|
||||||
|
|
||||||
before_destroy :destroy_email
|
before_destroy :destroy_email
|
||||||
|
|
||||||
scope :can_display, ->{where(:is_hidden=>false,:is_preview => false).any_of({:postdate.lt=>Time.now, :deadline.gt=>Time.now},{:postdate.lt=>Time.now, :deadline=>nil}).order_by([:is_top, :desc],[:postdate, :desc])}
|
scope :can_display_and_sorted, ->{where(:is_hidden=>false,:is_preview => false).any_of({:postdate.lte=>Time.now, :deadline.gte=>Time.now},{:postdate.lte=>Time.now, :deadline=>nil}).order(is_top: :desc,postdate: :desc)}
|
||||||
scope :is_approved, ->{where(:approved => true)}
|
scope :is_approved, ->{where(:approved => true)}
|
||||||
|
|
||||||
before_create :set_expire
|
before_create :set_expire
|
||||||
|
|
||||||
def slug_title
|
def slug_title
|
||||||
doc = Nokogiri::HTML(self.title)
|
doc = Nokogiri::HTML(self.title)
|
||||||
title = doc.text.gsub('/','-')
|
title = doc.text.gsub('/','-')
|
||||||
|
|
|
@ -1 +1,62 @@
|
||||||
|
<% params = OrbitHelper.params
|
||||||
|
page = Page.where(url:params['url']).first
|
||||||
|
enable_search_flag = false
|
||||||
|
if page.methods.include? 'select_option_items'.to_sym
|
||||||
|
ModuleApp.all.select{|tmp| tmp.key.to_s=='announcement'}.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('announcement.yes')
|
||||||
|
enable_search_flag = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
%>
|
||||||
|
<% if enable_search_flag %>
|
||||||
|
<style type="text/css">
|
||||||
|
#category_select_box{
|
||||||
|
margin: 0;
|
||||||
|
background: linear-gradient(0deg, #515fff, #ff3e3e);
|
||||||
|
color: white;
|
||||||
|
outline: 0;
|
||||||
|
border-radius: 0.9em;
|
||||||
|
}
|
||||||
|
#category_select_box>option{
|
||||||
|
background: #5640dd;
|
||||||
|
}
|
||||||
|
input.search_box{
|
||||||
|
margin: 0;
|
||||||
|
background: #a2c3df;
|
||||||
|
color: #9100ff;
|
||||||
|
border-radius: 0.7em;
|
||||||
|
outline: 0;
|
||||||
|
}
|
||||||
|
input.search_box[type='submit']:hover{
|
||||||
|
background: #9100ff;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
input.search_box[type='submit']:active{
|
||||||
|
background: #7201ff;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<form>
|
||||||
|
<% cats = Array(page.categories)
|
||||||
|
if cats.include? 'all'
|
||||||
|
cats = ModuleApp.where(key: 'announcement').first.categories
|
||||||
|
else
|
||||||
|
cats = cats.map{|v| Category.where(id: v).first}.compact
|
||||||
|
end
|
||||||
|
all_cat = [[t('announcement.all'),'all']]
|
||||||
|
%>
|
||||||
|
<div class="search_widget" style="font-size: 1.2em;">
|
||||||
|
<%= 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('announcement.select_prompt')) %>
|
||||||
|
<input class="search_box" type="text" name="keywords" value="<%= params['keywords'] %>" placeholder="<%= t('announcement.keywords') %>">
|
||||||
|
<input class="search_box" type="submit" value="<%= t('announcement.search') %>">
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<% end %>
|
||||||
<%= render_view %>
|
<%= render_view %>
|
|
@ -22,7 +22,7 @@
|
||||||
end
|
end
|
||||||
if @show_back_and_next_flag != 0
|
if @show_back_and_next_flag != 0
|
||||||
uid = params['uid']
|
uid = params['uid']
|
||||||
announcements,sorted = get_sorted_annc
|
sorted,total_pages = get_sorted_annc
|
||||||
now_index = sorted.to_enum.with_index.select{|v| v[0].uid==uid}[0][1]
|
now_index = sorted.to_enum.with_index.select{|v| v[0].uid==uid}[0][1]
|
||||||
if now_index != 0
|
if now_index != 0
|
||||||
prev_result = sorted[now_index-1]
|
prev_result = sorted[now_index-1]
|
||||||
|
|
|
@ -3,6 +3,12 @@ en:
|
||||||
feed: Feed
|
feed: Feed
|
||||||
import: Import
|
import: Import
|
||||||
announcement:
|
announcement:
|
||||||
|
select_prompt: --select category--
|
||||||
|
all: All
|
||||||
|
keywords: Keywords
|
||||||
|
enable_search: Enable search feature
|
||||||
|
'yes': 'Yes'
|
||||||
|
'no': 'No'
|
||||||
image: Cover Image
|
image: Cover Image
|
||||||
picture_showing_size: Picture Showing Size
|
picture_showing_size: Picture Showing Size
|
||||||
orignal_size: Original Size
|
orignal_size: Original Size
|
||||||
|
|
|
@ -3,6 +3,12 @@ zh_tw:
|
||||||
feed: 供給
|
feed: 供給
|
||||||
import: 匯入
|
import: 匯入
|
||||||
announcement:
|
announcement:
|
||||||
|
select_prompt: --選取類別--
|
||||||
|
all: 全部
|
||||||
|
keywords: 關鍵字
|
||||||
|
enable_search: 開啟搜尋功能
|
||||||
|
'yes': 是
|
||||||
|
'no': 否
|
||||||
image: 封面圖片
|
image: 封面圖片
|
||||||
picture_showing_size: 圖片顯示大小
|
picture_showing_size: 圖片顯示大小
|
||||||
orignal_size: 原圖大小
|
orignal_size: 原圖大小
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require "announcement/engine"
|
require "announcement/engine"
|
||||||
|
|
||||||
module Announcement
|
module Announcement
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,31 +2,42 @@ require "yaml"
|
||||||
module Announcement
|
module Announcement
|
||||||
class Engine < ::Rails::Engine
|
class Engine < ::Rails::Engine
|
||||||
initializer "announcement" do
|
initializer "announcement" do
|
||||||
|
begin
|
||||||
translate_data = Dir["#{Announcement::Engine.root}/config/locales/*.yml"] .map{|yaml_file| YAML.load(File.read(yaml_file))}
|
translate_data = Dir["#{Announcement::Engine.root}/config/locales/*.yml"] .map{|yaml_file| YAML.load(File.read(yaml_file))}
|
||||||
data = {}
|
data = {}
|
||||||
key1 = {}
|
key1 = {}
|
||||||
value1 = {}
|
value1 = {}
|
||||||
value2 = {}
|
value2 = {}
|
||||||
value3 = {}
|
value3 = {}
|
||||||
translate_data.each do |t_data|
|
|
||||||
key1[t_data.keys[0]] = t_data.values[0]['announcement']['picture_showing_size']
|
|
||||||
value1[t_data.keys[0]] = t_data.values[0]['announcement']['small_size']
|
|
||||||
value2[t_data.keys[0]] = t_data.values[0]['announcement']['medium_size']
|
|
||||||
value3[t_data.keys[0]] = t_data.values[0]['announcement']['orignal_size']
|
|
||||||
end
|
|
||||||
data[key1] = [value1,value2,value3]
|
|
||||||
data_item = {}
|
data_item = {}
|
||||||
key_item1 = {}
|
key_item1 = {}
|
||||||
|
key_item2 = {}
|
||||||
value_item1 = {}
|
value_item1 = {}
|
||||||
value_item2 = {}
|
value_item2 = {}
|
||||||
value_item3 = {}
|
value_item3 = {}
|
||||||
|
value2_item1 = {}
|
||||||
|
value2_item2 = {}
|
||||||
translate_data.each do |t_data|
|
translate_data.each do |t_data|
|
||||||
key_item1[t_data.keys[0]] = t_data.values[0]['announcement']['showing_back_and_next']
|
v = t_data.values
|
||||||
value_item1[t_data.keys[0]] = t_data.values[0]['announcement']['not_show']
|
k = t_data.keys[0]
|
||||||
value_item2[t_data.keys[0]] = t_data.values[0]['announcement']['show_bottom']
|
key1[k] = v[0]['announcement']['picture_showing_size']
|
||||||
value_item3[t_data.keys[0]] = t_data.values[0]['announcement']['show_top']
|
value1[k] = v[0]['announcement']['small_size']
|
||||||
|
value2[k] = v[0]['announcement']['medium_size']
|
||||||
|
value3[k] = v[0]['announcement']['orignal_size']
|
||||||
|
key_item1[k] = v[0]['announcement']['showing_back_and_next']
|
||||||
|
key_item2[k] = v[0]['announcement']['enable_search']
|
||||||
|
value_item1[k] = v[0]['announcement']['not_show']
|
||||||
|
value_item2[k] = v[0]['announcement']['show_bottom']
|
||||||
|
value_item3[k] = v[0]['announcement']['show_top']
|
||||||
|
value2_item1[k] = v[0]['announcement']['no']
|
||||||
|
value2_item2[k] = v[0]['announcement']['yes']
|
||||||
end
|
end
|
||||||
|
data[key1] = [value1,value2,value3]
|
||||||
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]
|
||||||
|
rescue => e
|
||||||
|
puts ['error in announcement',e]
|
||||||
|
end
|
||||||
OrbitApp.registration "Announcement", :type => "ModuleApp" do
|
OrbitApp.registration "Announcement", :type => "ModuleApp" do
|
||||||
module_label "announcement.announcement"
|
module_label "announcement.announcement"
|
||||||
base_url File.expand_path File.dirname(__FILE__)
|
base_url File.expand_path File.dirname(__FILE__)
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
module BulletinModel
|
||||||
|
module Cache
|
||||||
|
require 'active_support/concern'
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
included do
|
||||||
|
before_save :do_before_save
|
||||||
|
end
|
||||||
|
def do_before_save
|
||||||
|
if self.class == SubPart
|
||||||
|
AnnsCache.where(parent_id:self.id).destroy
|
||||||
|
elsif self.class == Bulletin
|
||||||
|
AnnsCache.all.destroy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -168,11 +168,11 @@ class Admin::SitesController < OrbitAdminController
|
||||||
git = 'git_1.9.1/usr/bin/git'
|
git = 'git_1.9.1/usr/bin/git'
|
||||||
end
|
end
|
||||||
git_add_except_public = Dir['*'].select{|v| v!= 'public' && v!= 'log'}.collect do |v|
|
git_add_except_public = Dir['*'].select{|v| v!= 'public' && v!= 'log'}.collect do |v|
|
||||||
"#{git} add -f '#{v}'"
|
"#{git} add -f --all --ignore-errors '#{v}'"
|
||||||
end.join(' && ')
|
end.join(' ; ')
|
||||||
git_add_custom = (Dir['*'].select{|v| v !='app' && v != 'lib' && v != 'config' && v != 'public' && v!= 'log'} + ['app/templates','config/mongoid.yml']).collect do |v|
|
git_add_custom = (Dir['*'].select{|v| v !='app' && v != 'lib' && v != 'config' && v != 'public' && v!= 'log'} + ['app/templates','config/mongoid.yml']).collect do |v|
|
||||||
"#{git} add -f --all '#{v}'"
|
"#{git} add -f --all --ignore-errors '#{v}'"
|
||||||
end.join(' && ')
|
end.join(' ; ')
|
||||||
git_restore = "#{git} checkout ."
|
git_restore = "#{git} checkout ."
|
||||||
time_now = Time.now.strftime('%Y_%m_%d_%H_%M')
|
time_now = Time.now.strftime('%Y_%m_%d_%H_%M')
|
||||||
if %x[#{git} config user.name].empty?
|
if %x[#{git} config user.name].empty?
|
||||||
|
@ -181,7 +181,7 @@ class Admin::SitesController < OrbitAdminController
|
||||||
if %x[#{git} config user.email].empty?
|
if %x[#{git} config user.email].empty?
|
||||||
%x[#{git} config --global user.email "orbit@rulingcom.com"]
|
%x[#{git} config --global user.email "orbit@rulingcom.com"]
|
||||||
end
|
end
|
||||||
Bundler.with_clean_env{system("#{git_add_except_public} && #{git} commit -m auto_backup_before_#{type}_#{time_now} && #{git} reset #{commit} --mixed && #{git_add_custom} && #{git_restore} && #{git_add_except_public}&& #{git} commit -m complete_#{type}_#{time_now}")}
|
Bundler.with_clean_env{system("#{git_add_except_public} ; #{git} commit -m auto_backup_before_#{type}_#{time_now} && #{git} reset #{commit} --mixed ; #{git_add_custom} ; #{git_restore} ; #{git_add_except_public} ; #{git} commit -m complete_#{type}_#{time_now}")}
|
||||||
mul.update_attributes(status: 'finish')
|
mul.update_attributes(status: 'finish')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue