tag clout
This commit is contained in:
parent
0a51baf815
commit
141851568e
|
@ -6,18 +6,50 @@ class AnnouncementsController < ApplicationController
|
||||||
announcements = nil
|
announcements = nil
|
||||||
|
|
||||||
if params[:keywords]
|
if params[:keywords]
|
||||||
announcements = Bulletin.where(:title.ne => "").any_of(:title => /#{params[:keywords].to_s}/i).is_approved.order_by(:created_at=>'desc').filter_by_categories(["all"]).per(15) if !params[:keywords].nil?
|
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:postdate=>"desc"}
|
||||||
|
announcements = Bulletin.where(:title.ne => "").any_of(:title => /#{params[:keywords].to_s}/i).is_approved.order_by(sort).filter_by_categories(["all"]).per(15) if !params[:keywords].nil?
|
||||||
announcements_count = announcements.count
|
announcements_count = announcements.count
|
||||||
keyword = params[:keywords]
|
keyword = params[:keywords]
|
||||||
elsif params[:unit]
|
elsif params[:unit]
|
||||||
announcements = Bulletin.where(:title.ne => "" ,:cache_dept => params[:unit].to_s).is_approved.order_by(:created_at=>'desc').filter_by_categories(["all"]).per(15) if !params[:unit].nil?
|
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:postdate=>"desc"}
|
||||||
|
announcements = Bulletin.where(:title.ne => "" ,:cache_dept => params[:unit].to_s).is_approved.order_by(sort).filter_by_categories(["all"]).per(15) if !params[:unit].nil?
|
||||||
announcements_count = announcements.count
|
announcements_count = announcements.count
|
||||||
keyword = params[:unit]
|
keyword = params[:unit]
|
||||||
|
elsif params[:tag]
|
||||||
|
announcements = Bulletin.where(:title.ne => "" ,:is_preview.in=>[false,nil]).is_approved.order_by(sort).filter_by_categories(["all"]).filter_by_tags([params[:tag]])
|
||||||
else
|
else
|
||||||
announcements = Bulletin.where(:title.ne => "" ,:is_preview.in=>[false,nil]).is_approved.order_by(:created_at=>'desc').filter_by_categories.filter_by_tags(OrbitHelper.params['tags'])
|
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:postdate=>"desc"}
|
||||||
|
announcements = Bulletin.where(:title.ne => "" ,:is_preview.in=>[false,nil]).is_approved.order_by(sort).filter_by_categories.filter_by_tags(params['tags'])
|
||||||
end
|
end
|
||||||
page = Page.where(:module => "announcement").first rescue nil
|
page = Page.where(:module => "announcement").first rescue nil
|
||||||
ma = ModuleApp.find_by_key("announcement") rescue nil
|
ma = ModuleApp.find_by_key("announcement") rescue nil
|
||||||
|
max_tag_count = 0
|
||||||
|
tags =[]
|
||||||
|
ma.tags.each do |t|
|
||||||
|
max_tag_count = (t.taggings.count > max_tag_count ? t.taggings.count : max_tag_count)
|
||||||
|
tags << {
|
||||||
|
"tag-id" => t.id.to_s,
|
||||||
|
"tag-name" => t.name,
|
||||||
|
"tag-link" => "/#{I18n.locale.to_s + page.url}/?tag=#{t.id.to_s}",
|
||||||
|
"count" => t.taggings.count
|
||||||
|
}
|
||||||
|
end
|
||||||
|
tags.each do |t|
|
||||||
|
percent = (t["count"].to_i * 100) / max_tag_count
|
||||||
|
if percent >= 75
|
||||||
|
t["tag-class"] = "hot1"
|
||||||
|
elsif percent >= 50
|
||||||
|
t["tag-class"] = "hot2"
|
||||||
|
elsif percent >= 25
|
||||||
|
t["tag-class"] = "hot3"
|
||||||
|
else
|
||||||
|
t["tag-class"] = "hot4"
|
||||||
|
end
|
||||||
|
if t["tag-id"] == params[:tag]
|
||||||
|
t["tag-class"] = t["tag-class"] + " active"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
categories = ma.categories.enabled.collect do |cat|
|
categories = ma.categories.enabled.collect do |cat|
|
||||||
{
|
{
|
||||||
"category-name" => cat.title,
|
"category-name" => cat.title,
|
||||||
|
@ -46,7 +78,9 @@ class AnnouncementsController < ApplicationController
|
||||||
{
|
{
|
||||||
"announcements" => anns,
|
"announcements" => anns,
|
||||||
"categories" => categories,
|
"categories" => categories,
|
||||||
|
"tag-cloud" => tags,
|
||||||
"extras" => {
|
"extras" => {
|
||||||
|
"tag-cloud-title" => t("announcement.tag_cloud"),
|
||||||
"categories-title" => t("announcement.categories"),
|
"categories-title" => t("announcement.categories"),
|
||||||
"widget-title" =>t('announcement.announcement'),
|
"widget-title" =>t('announcement.announcement'),
|
||||||
"title-head" => t('announcement.table.title'),
|
"title-head" => t('announcement.table.title'),
|
||||||
|
@ -116,8 +150,30 @@ class AnnouncementsController < ApplicationController
|
||||||
"category-link" => "/#{I18n.locale.to_s + page.url}/?category=#{cat.to_param}"
|
"category-link" => "/#{I18n.locale.to_s + page.url}/?category=#{cat.to_param}"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
max_tag_count = 0
|
||||||
|
tags =[]
|
||||||
|
ma.tags.each do |t|
|
||||||
|
max_tag_count = (t.taggings.count > max_tag_count ? t.taggings.count : max_tag_count)
|
||||||
|
tags << {
|
||||||
|
"tag-name" => t.name,
|
||||||
|
"tag-link" => "/#{I18n.locale.to_s + page.url}/?tag=#{t.id.to_s}",
|
||||||
|
"count" => t.taggings.count
|
||||||
|
}
|
||||||
|
end
|
||||||
|
tags.each do |t|
|
||||||
|
percent = (t["count"].to_i * 100) / max_tag_count
|
||||||
|
if percent >= 75
|
||||||
|
t["tag-class"] = "hot1"
|
||||||
|
elsif percent >= 50
|
||||||
|
t["tag-class"] = "hot2"
|
||||||
|
elsif percent >= 25
|
||||||
|
t["tag-class"] = "hot3"
|
||||||
|
else
|
||||||
|
t["tag-class"] = "hot4"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
tags = announcement.tags.map{|tag| {
|
ann_tags = announcement.tags.map{|tag| {
|
||||||
"tag" => tag.name ,
|
"tag" => tag.name ,
|
||||||
"url" => OrbitHelper.page_for_tag(tag)
|
"url" => OrbitHelper.page_for_tag(tag)
|
||||||
} } rescue []
|
} } rescue []
|
||||||
|
@ -126,11 +182,13 @@ class AnnouncementsController < ApplicationController
|
||||||
links = announcement.bulletin_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue []
|
links = announcement.bulletin_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue []
|
||||||
update_user = announcement.update_user.member_profile.name rescue ""
|
update_user = announcement.update_user.member_profile.name rescue ""
|
||||||
{
|
{
|
||||||
"tags" => tags,
|
"tags" => ann_tags,
|
||||||
"categories" => categories,
|
"categories" => categories,
|
||||||
"bulletin_files" => files,
|
"bulletin_files" => files,
|
||||||
"bulletin_links" => links,
|
"bulletin_links" => links,
|
||||||
|
"tag-cloud" => tags,
|
||||||
"data" => {
|
"data" => {
|
||||||
|
"tag-cloud-title" => t("announcement.tag_cloud"),
|
||||||
"title" => announcement.title,
|
"title" => announcement.title,
|
||||||
"categories-title" => t("announcement.categories"),
|
"categories-title" => t("announcement.categories"),
|
||||||
"update_user" => update_user,
|
"update_user" => update_user,
|
||||||
|
|
|
@ -9,6 +9,7 @@ en:
|
||||||
category: Category
|
category: Category
|
||||||
add_new: Add New
|
add_new: Add New
|
||||||
approve: Approve
|
approve: Approve
|
||||||
|
tag_cloud: Tag Cloud
|
||||||
all_articles: All Articles
|
all_articles: All Articles
|
||||||
announcement: Announcement
|
announcement: Announcement
|
||||||
approval_setting: Approval Setting
|
approval_setting: Approval Setting
|
||||||
|
|
|
@ -9,6 +9,7 @@ zh_tw:
|
||||||
category: 類別
|
category: 類別
|
||||||
add_new: 新建
|
add_new: 新建
|
||||||
approve: 通過
|
approve: 通過
|
||||||
|
tag_cloud: 標籤雲
|
||||||
all_articles: 文章列表
|
all_articles: 文章列表
|
||||||
announcement: 公告
|
announcement: 公告
|
||||||
approval_setting: 審核設定
|
approval_setting: 審核設定
|
||||||
|
|
Reference in New Issue