first version of tag cloud.
This commit is contained in:
parent
033667f99b
commit
946ec9306f
|
@ -1,10 +1,28 @@
|
||||||
class Tag
|
class Tag
|
||||||
|
|
||||||
include Mongoid::Document
|
include Mongoid::Document
|
||||||
include Mongoid::Timestamps
|
include Mongoid::Timestamps
|
||||||
|
include Impressionist::Impressionable
|
||||||
|
|
||||||
|
is_impressionable :counter_cache => { :column_name => :view_count }
|
||||||
field :key
|
field :key
|
||||||
|
#field :cloud_amper,:type: Integer,:default=> 0
|
||||||
belongs_to :module_app
|
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
|
end
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
<h3 class="h3"><%= t('announcement.tag_cloud') %></h3>
|
<h3 class="h3"><%= t('announcement.tag_cloud') %></h3>
|
||||||
<div class="cloud">
|
<div class="cloud">
|
||||||
<% @tags.each do |tag| %>
|
<% @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 %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -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)
|
@news_bulletins = NewsBulletin.all.can_display.any_in(_id:search_result).page( params[:page_main]).per(10)
|
||||||
else
|
else
|
||||||
date_now = Time.now
|
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?
|
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)
|
@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?
|
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
|
@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
|
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)
|
@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)
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
class NewsTag < Tag
|
class NewsTag < Tag
|
||||||
|
|
||||||
has_and_belongs_to_many :news_bulletins
|
has_and_belongs_to_many :news_bulletins
|
||||||
|
|
||||||
|
|
||||||
def get_visible_news_bulletins(sort = :name)
|
def get_visible_news_bulletins(sort = :name)
|
||||||
date_now = Time.now
|
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)
|
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)
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
<h3 class="h3"><%= t('announcement.tag_cloud') %></h3>
|
<h3 class="h3"><%= t('announcement.tag_cloud') %></h3>
|
||||||
<div class="cloud">
|
<div class="cloud">
|
||||||
<% @tags.each do |tag| %>
|
<% @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 %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue