now feeds are sorted. major change in algo
This commit is contained in:
parent
0d14ffa23e
commit
140a8f0332
|
@ -4,14 +4,32 @@ class AnnouncementsController < ApplicationController
|
||||||
Bulletin.remove_expired_status
|
Bulletin.remove_expired_status
|
||||||
params = OrbitHelper.params
|
params = OrbitHelper.params
|
||||||
feeds_anns = []
|
feeds_anns = []
|
||||||
|
top_anns = []
|
||||||
if !params['tags'].blank?
|
if !params['tags'].blank?
|
||||||
announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).and(:title.ne => nil).can_display.is_approved.filter_by_tags(params['tags']).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count)
|
announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).and(:title.ne => nil).can_display.is_approved.filter_by_tags(params['tags']).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count).to_a
|
||||||
else
|
else
|
||||||
announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).and(:title.ne => nil).can_display.is_approved.filter_by_categories.filter_by_tags
|
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([],false).filter_by_tags.to_a
|
||||||
|
|
||||||
feeds_anns = get_feed_announcements("index")
|
feeds_anns = get_feed_announcements("index")
|
||||||
end
|
end
|
||||||
|
|
||||||
anns = announcements.collect do |a|
|
if OrbitHelper.page_number == 1 or OrbitHelper.page_number.nil?
|
||||||
|
top_anns = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil], :is_top => true).and(:title.ne => nil).can_display.filter_by_categories([],false).to_a
|
||||||
|
end
|
||||||
|
if !feeds_anns.blank?
|
||||||
|
announcements = announcements.concat(feeds_anns)
|
||||||
|
sorted = announcements.sort{ |k,v| v["postdate"] <=> k["postdate"] }
|
||||||
|
sorted = top_anns + sorted
|
||||||
|
sorted = Kaminari.paginate_array(sorted).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count) rescue []
|
||||||
|
else
|
||||||
|
announcements = top_anns + announcements
|
||||||
|
sorted = Kaminari.paginate_array(announcements).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count) rescue []
|
||||||
|
end
|
||||||
|
total_pages = sorted.total_pages
|
||||||
|
|
||||||
|
anns = []
|
||||||
|
sorted.each do |a|
|
||||||
|
if !a["source-site"].present?
|
||||||
statuses = a.statuses_with_classname.collect do |status|
|
statuses = a.statuses_with_classname.collect do |status|
|
||||||
{
|
{
|
||||||
"status" => status["name"],
|
"status" => status["name"],
|
||||||
|
@ -23,7 +41,7 @@ class AnnouncementsController < ApplicationController
|
||||||
author = User.find(a.create_user_id).member_profile.name rescue ""
|
author = User.find(a.create_user_id).member_profile.name rescue ""
|
||||||
desc = a.image_description
|
desc = a.image_description
|
||||||
desc = (desc.nil? || desc == "" ? "announcement image" : desc)
|
desc = (desc.nil? || desc == "" ? "announcement image" : desc)
|
||||||
{
|
anns << {
|
||||||
"bulletin_links" => links,
|
"bulletin_links" => links,
|
||||||
"bulletin_files" => files,
|
"bulletin_files" => files,
|
||||||
"title" => a.title,
|
"title" => a.title,
|
||||||
|
@ -35,19 +53,25 @@ class AnnouncementsController < ApplicationController
|
||||||
"category" => a.category.title,
|
"category" => a.category.title,
|
||||||
"postdate" => a.postdate,
|
"postdate" => a.postdate,
|
||||||
"author" => author,
|
"author" => author,
|
||||||
|
"is_top" => (a.is_top? ? 1 : 0),
|
||||||
"link_to_show" => OrbitHelper.url_to_show(a.to_param),
|
"link_to_show" => OrbitHelper.url_to_show(a.to_param),
|
||||||
"img_src" => a.image.thumb.url || "/assets/announcement-default.jpg",
|
"img_src" => a.image.thumb.url || "/assets/announcement-default.jpg",
|
||||||
"img_description" => desc,
|
"img_description" => desc,
|
||||||
"more" => t(:more_plus),
|
"more" => t(:more_plus),
|
||||||
"view_count" => a.view_count
|
"view_count" => a.view_count
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
anns << a
|
||||||
|
end
|
||||||
end
|
end
|
||||||
#If no data , hide title&table
|
#If no data , hide title&table
|
||||||
if announcements.count == 0
|
if announcements.count == 0
|
||||||
display = "hide"
|
display = "hide"
|
||||||
end
|
end
|
||||||
anns = anns.concat(feeds_anns)
|
# anns = anns.concat(feeds_anns)
|
||||||
# sorted = anns.sort{ |k,v| v["postdate"] <=> k["postdate"] }
|
# total_pages = announcements.total_pages
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
"announcements" => anns,
|
"announcements" => anns,
|
||||||
"extras" => {
|
"extras" => {
|
||||||
|
@ -63,7 +87,7 @@ class AnnouncementsController < ApplicationController
|
||||||
"view-count-head" => t('announcement.table.view_count'),
|
"view-count-head" => t('announcement.table.view_count'),
|
||||||
"display" => display
|
"display" => display
|
||||||
},
|
},
|
||||||
"total_pages" => announcements.total_pages
|
"total_pages" => total_pages
|
||||||
}
|
}
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -86,6 +110,7 @@ class AnnouncementsController < ApplicationController
|
||||||
"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"],
|
||||||
|
@ -95,8 +120,10 @@ class AnnouncementsController < ApplicationController
|
||||||
"more" => t(:more_plus),
|
"more" => t(:more_plus),
|
||||||
"view_count" => ""
|
"view_count" => ""
|
||||||
}
|
}
|
||||||
|
if !x["title"].empty?
|
||||||
fans << x
|
fans << x
|
||||||
end
|
end
|
||||||
|
end
|
||||||
fans
|
fans
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -106,21 +133,33 @@ class AnnouncementsController < ApplicationController
|
||||||
categories = OrbitHelper.widget_categories || []
|
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)
|
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)
|
pack_data(announcements, [])
|
||||||
end
|
end
|
||||||
|
|
||||||
def widget
|
def widget
|
||||||
Bulletin.remove_expired_status
|
Bulletin.remove_expired_status
|
||||||
uid = OrbitHelper.params[:uid] rescue ""
|
uid = OrbitHelper.params[:uid] rescue ""
|
||||||
tags = OrbitHelper.widget_tags
|
tags = OrbitHelper.widget_tags
|
||||||
announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil],:uid.ne => uid).and(:title.ne => nil).can_display.is_approved.filter_by_widget_categories.filter_by_tags(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.filter_by_widget_categories([],false).to_a
|
||||||
pack_data(announcements)
|
pack_data(announcements, top_anns)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pack_data(announcements)
|
def pack_data(announcements, top_anns = [])
|
||||||
page = Page.where(:module => "announcement").first rescue nil
|
page = Page.where(:module => "announcement").first rescue nil
|
||||||
anns = announcements.collect do |a|
|
feeds_anns = get_feed_announcements("widget")
|
||||||
|
announcements = announcements + feeds_anns
|
||||||
|
if !feeds_anns.blank?
|
||||||
|
sorted = announcements.sort{ |k,v| v["postdate"] <=> k["postdate"] }
|
||||||
|
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|
|
statuses = a.statuses_with_classname.collect do |status|
|
||||||
{
|
{
|
||||||
"status" => status["name"],
|
"status" => status["name"],
|
||||||
|
@ -132,7 +171,7 @@ class AnnouncementsController < ApplicationController
|
||||||
author = User.find(a.create_user_id).member_profile.name rescue ""
|
author = User.find(a.create_user_id).member_profile.name rescue ""
|
||||||
desc = a.image_description
|
desc = a.image_description
|
||||||
desc = (desc.nil? || desc == "" ? "announcement image" : desc)
|
desc = (desc.nil? || desc == "" ? "announcement image" : desc)
|
||||||
{
|
anns << {
|
||||||
"bulletin_links" => links,
|
"bulletin_links" => links,
|
||||||
"bulletin_files" => files,
|
"bulletin_files" => files,
|
||||||
"title" => a.title,
|
"title" => a.title,
|
||||||
|
@ -148,11 +187,13 @@ class AnnouncementsController < ApplicationController
|
||||||
"img_src" => a.image.thumb.url || "/assets/announcement-default.jpg",
|
"img_src" => a.image.thumb.url || "/assets/announcement-default.jpg",
|
||||||
"img_description" => desc
|
"img_description" => desc
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
anns << a
|
||||||
|
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 "")
|
||||||
anns = anns.concat(get_feed_announcements("widget"))
|
|
||||||
# sorted = anns.sort{ |k,v| v["postdate"] <=> k["postdate"] }
|
|
||||||
{
|
{
|
||||||
"announcements" => anns,
|
"announcements" => anns,
|
||||||
"extras" => {
|
"extras" => {
|
||||||
|
|
Loading…
Reference in New Issue