diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index a0bab23..f476c9c 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -6,18 +6,50 @@ class AnnouncementsController < ApplicationController announcements = nil 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 keyword = params[:keywords] 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 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 - 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 page = Page.where(:module => "announcement").first 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| { "category-name" => cat.title, @@ -46,7 +78,9 @@ class AnnouncementsController < ApplicationController { "announcements" => anns, "categories" => categories, + "tag-cloud" => tags, "extras" => { + "tag-cloud-title" => t("announcement.tag_cloud"), "categories-title" => t("announcement.categories"), "widget-title" =>t('announcement.announcement'), "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}" } 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 , "url" => OrbitHelper.page_for_tag(tag) } } 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 [] update_user = announcement.update_user.member_profile.name rescue "" { - "tags" => tags, + "tags" => ann_tags, "categories" => categories, "bulletin_files" => files, "bulletin_links" => links, + "tag-cloud" => tags, "data" => { + "tag-cloud-title" => t("announcement.tag_cloud"), "title" => announcement.title, "categories-title" => t("announcement.categories"), "update_user" => update_user, diff --git a/config/locales/en.yml b/config/locales/en.yml index ab5c5ba..a8f9376 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -9,6 +9,7 @@ en: category: Category add_new: Add New approve: Approve + tag_cloud: Tag Cloud all_articles: All Articles announcement: Announcement approval_setting: Approval Setting diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 261d1ab..fff75f1 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -9,6 +9,7 @@ zh_tw: category: 類別 add_new: 新建 approve: 通過 + tag_cloud: 標籤雲 all_articles: 文章列表 announcement: 公告 approval_setting: 審核設定