From 946ec9306fe7148f0bb614787ed215ab8f639e3a Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Mon, 30 Jul 2012 11:59:20 +0800 Subject: [PATCH] first version of tag cloud. --- app/models/tag.rb | 22 +++++++++++++++++-- .../bulletins/bulletins_side_bar.html.erb | 2 +- .../front_end/news_bulletins_controller.rb | 8 +++++-- .../news/app/models/news_tag.rb | 2 -- .../news_bulletins_side_bar.html.erb | 2 +- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/app/models/tag.rb b/app/models/tag.rb index f621de6a..381a0253 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -1,10 +1,28 @@ class Tag - include Mongoid::Document include Mongoid::Timestamps + include Impressionist::Impressionable + is_impressionable :counter_cache => { :column_name => :view_count } field :key - + #field :cloud_amper,:type: Integer,:default=> 0 belongs_to :module_app + def cloud_amper + for_now = {:start_at=>20.days.ago,:end_at=>Time.now} + for_yesterday = {:start_at=>19.days.ago,:end_at=>1.days.ago} + + range = self.class.all.collect{ |tag| + get_impressionist_diff(tag) + } + (get_impressionist_diff - range.min).abs + end + +protected + def get_impressionist_diff(item_tag = self) + for_now = item_tag.impressionist_count(:start_date=>20.days.ago,:end_date=>Time.now) + for_yesterday = item_tag.impressionist_count(:start_date=>21.days.ago,:end_date=>1.days.ago) + for_now - for_yesterday + end + end diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/bulletins_side_bar.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/bulletins_side_bar.html.erb index fde9e976..2612fbb3 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/bulletins_side_bar.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/bulletins_side_bar.html.erb @@ -13,7 +13,7 @@

<%= t('announcement.tag_cloud') %>

<% @tags.each do |tag| %> - <%= link_to tag[I18n.locale], panel_announcement_front_end_bulletins_path(:tag_id => tag.id), :class => "hot#{rand(4) + 1} #{(tag.id.to_s.eql?(params[:tag_id]) || tag.key.eql?(params[:tag_id])) ? 'active' : nil}" %> + <%= link_to tag[I18n.locale], panel_announcement_front_end_bulletins_path(:tag_id => tag.id),:style=>"font-size: #{100+ tag.cloud_amper * 10}%", :class => "hot#{rand(4) + 1} #{(tag.id.to_s.eql?(params[:tag_id]) || tag.key.eql?(params[:tag_id])) ? 'active' : nil}" %> <% end %>
diff --git a/vendor/built_in_modules/news/app/controllers/panel/news/front_end/news_bulletins_controller.rb b/vendor/built_in_modules/news/app/controllers/panel/news/front_end/news_bulletins_controller.rb index e43e90d1..11f178f7 100644 --- a/vendor/built_in_modules/news/app/controllers/panel/news/front_end/news_bulletins_controller.rb +++ b/vendor/built_in_modules/news/app/controllers/panel/news/front_end/news_bulletins_controller.rb @@ -28,11 +28,15 @@ class Panel::News::FrontEnd::NewsBulletinsController < OrbitWidgetController @news_bulletins = NewsBulletin.all.can_display.any_in(_id:search_result).page( params[:page_main]).per(10) else date_now = Time.now + if !params[:tag_id].blank? + tmp = NewsTag.find(params[:tag_id]) rescue nil + tmp = NewsTag.where(key: params[:tag_id])[0] unless tmp + impressionist(@tag) + end + if !params[:category_id].blank? @news_bulletins = NewsBulletin.all.can_display.where(:news_bulletin_category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(10) elsif !params[:tag_id].blank? - tmp = NewsTag.find(params[:tag_id]) rescue nil - tmp = NewsTag.where(key: params[:tag_id])[0] unless tmp @news_bulletins = tmp.news_bulletins.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(10) rescue nil else @news_bulletins = NewsBulletin.all.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(10) diff --git a/vendor/built_in_modules/news/app/models/news_tag.rb b/vendor/built_in_modules/news/app/models/news_tag.rb index 5005f617..440bdea1 100644 --- a/vendor/built_in_modules/news/app/models/news_tag.rb +++ b/vendor/built_in_modules/news/app/models/news_tag.rb @@ -1,8 +1,6 @@ class NewsTag < Tag - has_and_belongs_to_many :news_bulletins - def get_visible_news_bulletins(sort = :name) date_now = Time.now self.news_bulletins.where(:is_hidden => false).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc(:is_top, sort) diff --git a/vendor/built_in_modules/news/app/views/panel/news/widget/news_bulletins/news_bulletins_side_bar.html.erb b/vendor/built_in_modules/news/app/views/panel/news/widget/news_bulletins/news_bulletins_side_bar.html.erb index 5ea1a930..b1fdac81 100644 --- a/vendor/built_in_modules/news/app/views/panel/news/widget/news_bulletins/news_bulletins_side_bar.html.erb +++ b/vendor/built_in_modules/news/app/views/panel/news/widget/news_bulletins/news_bulletins_side_bar.html.erb @@ -13,7 +13,7 @@

<%= t('announcement.tag_cloud') %>

<% @tags.each do |tag| %> - <%= link_to tag[I18n.locale], panel_news_front_end_news_bulletins_path(:tag_id => tag.id), :class => "hot#{rand(4) + 1} #{(tag.id.to_s.eql?(params[:tag_id]) || tag.key.eql?(params[:tag_id])) ? 'active' : nil}" %> + <%= link_to tag[I18n.locale], panel_news_front_end_news_bulletins_path(:tag_id => tag.id), :style => "font-size: #{100+ tag.cloud_amper * 10}%",:class => "hot#{rand(4) + 1} #{(tag.id.to_s.eql?(params[:tag_id]) || tag.key.eql?(params[:tag_id])) ? 'active' : nil}" %> <% end %>