From 0e1123396b5cd62813aac4ac78df3a88cc861bfa Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Thu, 29 Jun 2017 16:03:39 +0800 Subject: [PATCH] added tag cloud widget --- app/controllers/announcements_controller.rb | 29 +++++++++++++++++++++ config/locales/zh_tw.yml | 2 +- lib/announcement/engine.rb | 2 +- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index def60f5..638b715 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -178,6 +178,35 @@ class AnnouncementsController < ApplicationController pack_data(announcements, top_anns) end + def tag_cloud + ma = ModuleApp.where(:key => "announcement").first + temp = [] + ma.tags.each do |tag| + t1 = tag.taggings.collect{|t| t.taggable_id.to_s} + count = Bulletin.where(:id.in => t1).can_display.count + temp << { + "tag-name" => tag.name, + "count" => count, + "tag-url" => OrbitHelper.widget_more_url + "?tags[]=" + tag.id.to_s + } + end + max = temp.max_by{|t| t["count"]}["count"] + min = temp.min_by{|t| t["count"]}["count"] + tags = [] + temp.each do |tag| + if tag["count"] > 0 + percent = (tag["count"] * 100) / max + font_size = ((percent / 10).ceil) + 11 + tag["font-size"] = font_size + tags << tag + end + end + { + "tags" => tags, + "extras" => {} + } + end + def pack_data(announcements, top_anns = []) page = Page.where(:module => "announcement").first rescue nil feeds_anns = get_feed_announcements("widget") diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index b910925..e67cba8 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -79,6 +79,6 @@ zh_tw: mail_time: 時間 image_upload_size_note: 建議檔案小於%{image_upload_size} resend_mail: 重新寄送提醒 - is_external_link: 開啟內部連結 + is_external_link: 連結外部網址 external_link: 外部連結 external_link_hint: "確定連結開頭為http://" diff --git a/lib/announcement/engine.rb b/lib/announcement/engine.rb index 5a55f1b..cf06edf 100644 --- a/lib/announcement/engine.rb +++ b/lib/announcement/engine.rb @@ -5,7 +5,7 @@ module Announcement OrbitApp.registration "Announcement", :type => "ModuleApp" do module_label "announcement.announcement" base_url File.expand_path File.dirname(__FILE__) - widget_methods ["widget","random_announcement_widget"] + widget_methods ["widget","random_announcement_widget", "tag_cloud"] widget_settings [{"data_count"=>30}] taggable "Bulletin" categorizable