New widget for tag cloud

This commit is contained in:
chris 2013-05-24 18:42:01 +08:00 committed by Matt K. Fu
parent 30824d1620
commit 253cca06cc
16 changed files with 122 additions and 27 deletions

View File

@ -22,6 +22,11 @@ class Admin::PagePartsController < OrbitBackendController
@part = PagePart.find(params[:id])
@r_tag = @part.public_r_tag.blank? ? LIST[:public_r_tags][0] : @part.public_r_tag
@tag_objects = @r_tag.classify.constantize.all rescue nil
if @r_tag.eql?('tag_cloud')
@tag_objects = ModuleApp.where(has_tag: true)
else
@tag_objects = @r_tag.classify.constantize.all rescue nil
end
@module_apps = ModuleApp.for_widget_select
@categories = nil
@ -119,7 +124,11 @@ class Admin::PagePartsController < OrbitBackendController
def reload_r_tag_options
@part = PagePart.find params[:id]
@r_tag = params[:type]
@tag_objects = @r_tag.classify.constantize.all rescue nil
if params[:type].eql?('tag_cloud')
@tag_objects = ModuleApp.where(has_tag: true)
else
@tag_objects = @r_tag.classify.constantize.all rescue nil
end
respond_to do |format|
format.js {}
end

View File

@ -38,6 +38,11 @@ class FrontController < ApplicationController
@ad_images = AdImage.all
end
def show_tag_cloud
module_app = ModuleApp.find(params[:id]) rescue nil
@tags = module_app.sorted_tags_for_cloud
end
private
def menu_level(page, current_page, current, menu)

View File

@ -3,7 +3,7 @@ module ApplicationHelper
FLASH_NOTICE_KEYS = [:error, :notice, :warning]
def delayed_impressionist(object)
Resque.enqueue_at(1.minute.from_now,DelayedImpressionist,object)
# Resque.enqueue_at(1.minute.from_now,DelayedImpressionist,object)
end
def check_user_role_enable(attribute_fields)

View File

@ -19,6 +19,7 @@ class ModuleApp
self[:get_widget_style] = reg.get_widgets
self[:using_default_widget] = !reg.get_default_widget.blank?
self[:widgets] = reg.get_widgets
self[:has_tag] = reg.get_has_tags
end
@ -135,5 +136,27 @@ class ModuleApp
def self.find_by_key(key)
self.where(key: key)[0] rescue nil
end
def sorted_tags_for_cloud
temp_tags = {}
self.tags.each{ |tag|
temp_tags.merge!({tag => Tag.get_impressionist(tag)})
}
if !temp_tags.blank?
sorted_tags = temp_tags.sort{|a,b| a[1]<=>b[1]}.reverse
sorted_tags[0][1] = :hot1
offset = (sorted_tags.size - 1) / 3
i = 1
class_i = 2
sorted_tags[1..-1].collect!{ |x|
x[1] = "hot#{class_i}"
i == offset ? i = 1 : i += 1 if class_i < 4
class_i += 1 if i == offset && class_i < 4
}
sorted_tags
else
[]
end
end
end

View File

@ -19,27 +19,27 @@ class Tag
#field :cloud_amper,:type: Integer,:default=> 0
def self.sorted_for_cloud
tags = {}
self.all.each{ |tag|
tags.merge!({tag => self.get_impressionist(tag)})
}
if !tags.blank?
sorted_tags = tags.sort{|a,b| a[1]<=>b[1]}.reverse
sorted_tags[0][1] = :hot1
offset = (sorted_tags.size - 1) / 3
i = 1
class_i = 2
sorted_tags[1..-1].collect!{ |x|
x[1] = "hot#{class_i}"
i == offset ? i = 1 : i += 1 if class_i < 4
class_i += 1 if i == offset && class_i < 4
}
sorted_tags
else
[]
end
end
# def self.sorted_for_cloud
# tags = {}
# self.all.each{ |tag|
# tags.merge!({tag => self.get_impressionist(tag)})
# }
# if !tags.blank?
# sorted_tags = tags.sort{|a,b| a[1]<=>b[1]}.reverse
# sorted_tags[0][1] = :hot1
# offset = (sorted_tags.size - 1) / 3
# i = 1
# class_i = 2
# sorted_tags[1..-1].collect!{ |x|
# x[1] = "hot#{class_i}"
# i == offset ? i = 1 : i += 1 if class_i < 4
# class_i += 1 if i == offset && class_i < 4
# }
# sorted_tags
# else
# []
# end
# end
protected

View File

@ -0,0 +1,10 @@
<% unless @tags.blank? %>
<div class="tag_cloud">
<h3 class="h3"><%= t(:tag_cloud) %></h3>
<div class="cloud">
<% @tags.each do |tag| %>
<%= link_to tag[0].name, '#?' + {:tag_id => tag[0].id, :category_id => params[:category_id]}.to_param, :class => "#{tag[1]} #{tag[0].id.to_s.eql?(params[:tag_id]) ? 'active' : nil} " %>
<% end %>
</div>
</div>
<% end %>

View File

@ -43,6 +43,7 @@ public_r_tags:
- sub_menu
- sitemap
- breadcrumb
- tag_cloud
page_part_kinds:
- text

View File

@ -8,7 +8,7 @@ defaults: &defaults
development:
<<: *defaults
database: test_site
database: production_7
test:
<<: *defaults
database: test_site

View File

@ -262,7 +262,7 @@ Orbit::Application.routes.draw do
end
end
controller_paths :front, %w[show_breadcrumb show_banner show_footer show_menu show_page_sub_menu show_site_sub_menu show_sitemap]
controller_paths :front, %w[show_breadcrumb show_banner show_footer show_menu show_page_sub_menu show_site_sub_menu show_sitemap show_tag_cloud]
# controller_paths :mobile, %w[index announcement announcement_content dialog_contact dialog_copyright dialog_language map page page_content]
# scope 'app' do

View File

@ -28,7 +28,7 @@ module OrbitApp
end
class DataSheet
attr_reader :name,:key,:base_path,:module_label,:data_count
attr_reader :name,:key,:base_path,:module_label,:data_count, :has_tag
def initialize(name, &block)
@name = name
@ -37,6 +37,7 @@ module OrbitApp
@front_end_app_pages = nil
@module_label = 'rulingcom.errors.init.module_app_noname'
@data_count = 1..15 # as default
@has_tag = nil
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
setup_module_app
end
@ -144,6 +145,14 @@ module OrbitApp
define_method(field){|var| instance_variable_set( "@" + field, var)}
end
def taggable
@has_tag = true
end
def get_has_tags
@has_tag.nil? ? false : true
end
end # of class DataSheet
end

View File

@ -1,5 +1,6 @@
module ParserCommon
include ActionView::Helpers::TagHelper
include ActionView::Helpers::TagHelper
# include ActionView::Helpers::UrlHelper
def menu_level(page, current_page, current, menu, edit = false)
res = ''
@ -170,6 +171,30 @@ module ParserCommon
end
end
# tag_cloud
def parse_tag_clouds_edit(body = nil, page = nil, edit=nil)
body.css('tag_cloud').each do |tag_cloud|
module_app = ModuleApp.find(tag_cloud["id"]) rescue nil
res = ''
if module_app
res << "<div class='tag_cloud'>"
res << "<h3 class='h3'>#{t(:tag_cloud)}</h3>"
res << "<div class='cloud'>"
module_app.sorted_tags_for_cloud.each do |tag|
# res << link_to(tag[0].name, ('/' + {:tag_id => tag[0].id, :category_id => params[:category_id]}.to_param), :class => "#{tag[1]} #{tag[0].id.to_s.eql?(params[:tag_id]) ? 'active' : nil} ")
res << "<span class='#{tag[1]} #{tag[0].id.to_s.eql?(params[:tag_id]) ? 'active' : nil}'>"
res << tag[0].name
res << "</span>"
end
res << "</div>"
res << "</div>"
end
fragment = Nokogiri::HTML::DocumentFragment.new(body, res)
tag_cloud.swap(fragment)
end
end
# page_footer
def parse_footer_edit(body, page)
page_footer = body.css('.page_footer').first

View File

@ -210,4 +210,9 @@ module ParserFrontEnd
def generate_breadcrumbs(*args)
"<div class='dymanic_load' path='#{front_show_breadcrumb_path(args[1])}'></div>"
end
# tag_cloud
def generate_tag_clouds(*args)
"<div class='dymanic_load' path='#{front_show_tag_cloud_path(args[0])}'></div>"
end
end

View File

@ -25,6 +25,8 @@ module Announcement
category ["BulletinCategory"]
data_count 3..10
taggable
widgets do
default_widget do
query 'Bulletin.any_of( {deadline: nil,:postdate.lte => Time.now} , {:deadline.gte => Time.now,:postdate.lte => Time.now} )'

View File

@ -19,6 +19,8 @@ module Archive
category ["ArchiveFileCategory"]
taggable
widgets do
# default_widget do
# query 'ArchiveFile.all'

View File

@ -19,6 +19,8 @@ module Faq
category ["QaCategory"]
data_count 1..20
taggable
widgets do
default_widget do
query 'Qa.all'

View File

@ -16,6 +16,8 @@ module WebResource
end
end
taggable
widgets do
# default_widget do
# query 'Bulletin.all'