Merge branch 'clean_development' into lukas/picked_ques

This commit is contained in:
iCross 2013-06-06 19:08:59 +08:00
commit 8c1e65994a
24 changed files with 204 additions and 46 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]
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

@ -110,7 +110,7 @@ class ApplicationController < ActionController::Base
end
# Render the page
def render_page(args=nil)
def render_page(args={})
if @item
respond_to do |format|
format.html { render :text => parse_page_content(@item,args), :layout => 'page_layout' }

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

@ -1,4 +1,9 @@
class OrbitWidgetController< OrbitFrontendComponentController
include FrontEndArrayParamsHelper
before_filter {get_tags_and_cates(params)}
def get_tags_and_cates(params)
params = tags_and_cates(params)
end
end

View File

@ -32,7 +32,7 @@ class PagesController < ApplicationController
if params[:clicked_field_name]
render_page({"clicked_field_name"=>params["clicked_field_name"]}) unless save_from_no_lang_for_page
else
render_page unless save_from_no_lang_for_page
render_page(params) unless save_from_no_lang_for_page
end
when 'Link'
redirect_to(@item[:url]) unless save_from_no_lang_for_page
@ -45,12 +45,28 @@ class PagesController < ApplicationController
#end
end
def convert_array_param(key,array)
array.collect{|t| "#{key}[]=#{t}"}.join("&")
end
def index_from_link
url = "/#{@item.path}"
options = ''
options << "#{options.blank? ? '?' : '&'}page_main=#{params[:page_main]}" unless params[:page_main].blank?
if params[:category_id].is_a? Array
options << "#{options.blank? ? '?' : '&'}#{convert_array_param('category_id',params[:category_id])}" unless params[:category_id].blank?
elsif params[:category_id].is_a? String
options << "#{options.blank? ? '?' : '&'}category_id=#{params[:category_id]}" unless params[:category_id].blank?
end
if params[:tag_id].is_a? Array
options << "#{options.blank? ? '?' : '&'}#{convert_array_param('tag_id',params[:tag_id])}" unless params[:tag_id].blank?
elsif params[:category_id].is_a? String
options << "#{options.blank? ? '?' : '&'}tag_id=#{params[:tag_id]}" unless params[:tag_id].blank?
end
options << "#{options.blank? ? '?' : '&'}search_query=#{params[:search_query]}" unless params[:search_query].blank?
options << "#{options.blank? ? '?' : '&'}name=#{params[:name]}" unless params[:name].blank?
uri = URI::escape(url + options)

View File

@ -2,8 +2,13 @@ module ApplicationHelper
FLASH_NOTICE_KEYS = [:error, :notice, :warning]
def current_path(param_hash)
request.referer.include?('?') ? [request.referer,param_hash.to_param].join('&') : [request.referer,param_hash.to_param].join('?')
end
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
@ -136,4 +137,26 @@ class ModuleApp
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, current_path({:tag_id => tag[0].id, :category_id => params[:category_id]}), :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

@ -4,6 +4,7 @@ require "orbit_app/helper/renderer"
require "orbit_app/helper/side_bar_renderer"
require "orbit_app/helper/context_link_renderer"
require "orbit_app/helper/default_widget_tag_helper"
require "orbit_app/helper/front_end_array_params_helper"
require "orbit_app/module/side_bar"
require "orbit_app/module/widget"
require "orbit_app/module/front_end"

View File

@ -4,9 +4,20 @@ module DefaultWidgetTagHelper
def link_to_more_tag(req,params)
@request = req
@params =params
params.delete :inner
@params = params
params_str ="?"
params.each do |index,param|
if param.is_a?(Array) and !param.blank?
params_str << param.collect{|t| "#{index}[]=#{t}"}.join("&")
params.delete index
end
end
params_str = params_str + (params_str.eql?("?") ? params.to_param : "&#{params.to_param}" )
content_tag :div,:class=> 'more' do
link_to I18n.t(@more_link[:label_i18n]),eval(@more_link[:path_method])
link_to I18n.t(@more_link[:label_i18n]),[eval("#{@more_link[:path_method]}"),params_str].join()
end
end
end

View File

@ -0,0 +1,20 @@
module FrontEndArrayParamsHelper
#Deal with multi tags and cates that could be sat at both from setting or passed by views like tag cloud.
#Take Tag as example: Those tags which be sat at setting will be pass as params 'tag_ext',and the rest will be pass as 'tag'
#But when the showing process goes to fronend or default widget itself the controller will need to know what data it should use exactly.
#That's why we need tags_and_cates
def tags_and_cates(params)
params["category_id"] = params["category_id"].collect{|t| t.gsub(/\"|\[|\]/,'').split(",").each(&:strip!)}.flatten if params["category_id"].is_a? Array
params["tag_id"] = params["tag_id"].collect{|t| t.gsub(/\"|\[|\]/,'').split(",").each(&:strip!)}.flatten if params["tag_id"].is_a? Array
params["category_id"] = [ params["base_category_id"],params["category_id"]].flatten.reject(&:nil?).reject(&:empty?)
params.delete :base_category_id
params["tag_id"] = [ params["base_tag_id"],params["tag_id"]].flatten.reject(&:nil?).reject(&:empty?)
params.delete :base_tag_id
return params
end
end

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::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

@ -18,9 +18,12 @@ module ParserFrontEnd
i18n
end
def parse_page_content(page,args=nil)
tag = params[:tag_id].blank? ? page[:tag] : params[:tag_id]
category = params[:category_id].blank? ? page[:category] : params[:category_id]
def parse_page_content(page,args={})
args["category_id"] = args["category_id"].gsub(/\"|\[|\]/,'').split(",").each(&:strip!) if !args["category_id"].blank? and args["category_id"].is_a?(String)
args["tag_id"] = args["tag_id"].gsub(/\"|\[|\]/,'').split(",").each(&:strip!) if !args["tag_id"].blank? and args["tag_id"].is_a? String
# tag = params[:tag_id].blank? ? page[:tag] : params[:tag_id]
# category = params[:category_id].blank? ? page[:category] : params[:category_id]
body = Nokogiri::HTML(page.content)
body.css('orbit_front').each do |front|
if front['value']
@ -29,9 +32,12 @@ module ParserFrontEnd
ret = ''
part = PagePart.find(front['part_id']) if front['part_id']
ret << eval("\"#{front['path']}\"") rescue ''
args.each do |index,arg|
if index=="tag_id" || index=="category_id"
ret << (ret.include?("?") ? "&#{index}[]=#{arg}": "?#{index}[]=#{arg}" )
else
ret << (ret.include?("?") ? "&#{index}=#{arg}": "?#{index}=#{arg}" )
end
end if args
fragment = Nokogiri::HTML::DocumentFragment.new(body, "<div class='dymanic_load widget' path='#{ret}'></div>")
end
@ -124,8 +130,8 @@ module ParserFrontEnd
url = "/panel/#{page.module_app.key}/front_end/#{page.app_frontend_url}\#{(\"/\" + params[:id]) if params[:id] && !params[:id].eql?(page.id.to_s)}\#{(\"/\" + params[:controller_action]) if params[:controller_action] && params[:id]}?inner=true"
end
categories_str=category.collect{|t| "category_id[]=#{t}"}.join('&')
tags_str=tag.collect{|t| "tag_id[]=#{t}"}.join('&')
categories_str=category.collect{|t| "base_category_id[]=#{t}"}.join('&')
tags_str=tag.collect{|t| "base_tag_id[]=#{t}"}.join('&')
categories_str = "&#{categories_str}" unless categories_str.blank?
tags_str = "&#{tags_str}" unless tags_str.blank?
@ -147,12 +153,13 @@ module ParserFrontEnd
"/panel/\#{part.module_app.key}/widget/\#{part.widget_path}?inner=true"
end
categories_str=part[:category].collect{|t| "category_id[]=#{t}"}.join('&')
tags_str=part[:tag].collect{|t| "tag_id[]=#{t}"}.join('&')
categories_str=part[:category].collect{|t| "base_category_id[]=#{t}"}.join('&')
tags_str=part[:tag].collect{|t| "base_tag_id[]=#{t}"}.join('&')
categories_str = "&#{categories_str}" unless categories_str.blank?
tags_str = "&#{tags_str}" unless tags_str.blank?
options = "&part_id=\#{part.id}#{categories_str}#{tags_str}&page=\#{params[:page]}&search_query=\#{params[:search_query]}&clicked_field_name=\#{params[:clicked_field_name]}&part_title=\#{Rack::Utils.escape(part_title).gsub(\"\+\", \"\%20\") rescue nil}&item_type=page_part"
options = "&part_id=\#{part.id}#{categories_str}#{tags_str}&page=\#{params[:page]}&search_query=\#{params[:search_query]}&clicked_field_name=\#{params[:clicked_field_name]}&part_title=\#{Rack::Utils.escape(part_title).gsub(\"\+\", \"\%20\") rescue nil}&item_type=page_part&tag_id=\#{params[:tag_id]}&category_id=\#{params[:category_id]}"
ret << "<orbit_front path='#{url + options}' part_id=#{part.id} class='dymanic_load widget'></orbit_front>"
when 'public_r_tag'
@ -210,4 +217,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

@ -35,7 +35,6 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController
end
@frontend_style = @item.frontend_style
end
@item = Page.find(params[:page_id]) rescue nil
if !params[:search_query].blank?
# search_cond = {:is_checked=>true,:is_hidden=>false,:is_pending => false}

View File

@ -31,6 +31,5 @@
<% end %>
</table>
<%= paginate @bulletins, :param_name => :page_main, :params => {:inner => 'false'} %>
<%= paginate( @bulletins, :param_name => :page_main, :params => {:inner => 'false'} ) rescue nil%>

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'