fix cates and tags

This commit is contained in:
Fu Matthew 2013-03-05 18:34:41 +08:00
parent 626b2a7bca
commit dc3966be81
4 changed files with 58 additions and 15 deletions

View File

@ -234,7 +234,13 @@ class ApplicationController < ActionController::Base
ret = '' ret = ''
ret << "/panel/#{@item.module_app.key}/front_end/#{@item.app_frontend_url}.rss" ret << "/panel/#{@item.module_app.key}/front_end/#{@item.app_frontend_url}.rss"
ret << "/#{params[:id]}" if params[:id] && !params[:id].eql?(@item.id.to_s) ret << "/#{params[:id]}" if params[:id] && !params[:id].eql?(@item.id.to_s)
ret << "?inner=true&category_id=#{params[:category]}&tag_id=#{params[:tag]}&page_main=#{params[:page_main]}"
categories_str=params[:category].collect{|t| "category_id[]=#{t}"}.join('&')
tags_str=params[:tag].collect{|t| "tag_id[]=#{t}"}.join('&')
categories_str = "&#{categories_str}" unless categories_str.blank?
tags_str = "&#{tags_str}" unless tags_str.blank?
ret << "?inner=true#{categories_str}#{tags_str}&page_main=#{params[:page_main]}"
redirect_to ret redirect_to ret
end end

View File

@ -11,26 +11,32 @@ class DefaultWidgetController< OrbitWidgetController
end end
def query_for_default_widget def query_for_default_widget
ori_class_name = @default_widget["query"].split('.')[0] ori_class_name = @default_widget["query"].split('.')[0]
result = nil result = nil
result_objects = nil result_objects = nil
params["tag_id"] = [] if params["tag_id"]=="[]"
params["category_id"] = [] if params["category_id"]=="[]"
if !params["tag_id"].blank? if !params["tag_id"].blank?
@tags = Tag.find(params["tag_id"]) rescue nil @tags = Tag.find(params["tag_id"]) rescue nil
result_ids = nil result_ids = nil
if params["category_id"].blank?
result_ids = @tags.collect{|tag| tag.send(ori_class_name.downcase.pluralize).entries.collect{|t| t.id}}.flatten result_ids = @tags.collect{|tag| tag.send(ori_class_name.downcase.pluralize).entries.collect{|t| t.id}}
else if params["category_id"].blank? #has tag no cate
result_ids = @tags.collect{|tag| tag.send(ori_class_name.downcase.pluralize).where(:category_id.in=>params["category_id"]).available_for_lang(I18n.locale).can_display.collect{|t| t.id}}.flatten #nothing
else #has tag and cate
# result_ids = @tags.collect{|tag| tag.send(ori_class_name.downcase.pluralize).where(:#{get_category_field_name(ori_class_name)}.in=>params["category_id"]).available_for_lang(I18n.locale).can_display.collect{|t| t.id}}.flatten
result_ids << eval("#{ori_class_name}.where(:#{get_category_field_name(ori_class_name)}.in=>params['category_id']).entries.collect{|t| t.id}")
result_ids.flatten!
end end
result = eval("#{ori_class_name}.where(:id=>result_ids)") result = eval("#{ori_class_name}.where(:id=>result_ids)")
elsif params["category_id"].blank? elsif params["category_id"].blank? #no tag no cate
result = eval(@default_widget["query"]) result = eval(@default_widget["query"])
else else #no tag has cate
result = eval("#{ori_class_name}.where(:category_id.in=>params['category_id'])") result = eval("#{ori_class_name}.where(:#{get_category_field_name(ori_class_name)}.in=>params['category_id'])")
end end
result.available_for_lang(I18n.locale).can_display result.available_for_lang(I18n.locale).can_display
end end
@ -72,4 +78,12 @@ class DefaultWidgetController< OrbitWidgetController
end end
end end
def get_category_field_name(ori_class_name)
ori_class_name = ori_class_name.constantize
ori_class_name.fields.each_key do |key|
return key if key.include?('category_id')
end
nil
end
end end

View File

@ -236,7 +236,13 @@ module ParserCommon
end end
ret << "<div id='appfrontend' class='dymanic_load' path='#{url}" ret << "<div id='appfrontend' class='dymanic_load' path='#{url}"
ret << "/#{params[:id]}" if params[:id] && !params[:id].eql?(page.id.to_s) ret << "/#{params[:id]}" if params[:id] && !params[:id].eql?(page.id.to_s)
ret << "?inner=true&page_id=#{page.id}&category_id=#{category}&tag_id=#{tag}&preview=#{params[:preview]}&page_main=#{params[:page_main]}&search_query=#{params[:search_query]}&name=#{params[:name]}&item_type=page"
categories_str=category.collect{|t| "category_id[]=#{t}"}.join('&')
tags_str=tag.collect{|t| "tag_id[]=#{t}"}.join('&')
categories_str = "&#{categories_str}" unless categories_str.blank?
tags_str = "&#{tags_str}" unless tags_str.blank?
ret << "?inner=true&page_id=#{page.id}#{categories_str}#{tags_str}&preview=#{params[:preview]}&page_main=#{params[:page_main]}&search_query=#{params[:search_query]}&name=#{params[:name]}&item_type=page"
ret << "'></div>" ret << "'></div>"
else else
part = page.page_parts.detect{ |p| p.name.to_s == content['name'].to_s } rescue nil part = page.page_parts.detect{ |p| p.name.to_s == content['name'].to_s } rescue nil
@ -258,7 +264,13 @@ module ParserCommon
raise ModuleAppError,"PagePart can't find ModuleApp" if part.module_app.nil? raise ModuleAppError,"PagePart can't find ModuleApp" if part.module_app.nil?
"/panel/#{part.module_app.key}/widget/#{part.widget_path}?inner=true" "/panel/#{part.module_app.key}/widget/#{part.widget_path}?inner=true"
end end
options = "&part_id=#{part.id}&category_id=#{!part[:category].blank? ? part[:category] : category}&tag_id=#{!part[:tag].blank? ? part[:tag] : tag}&page=#{params[:page]}&search_query=#{params[:search_query]}&part_title=#{Rack::Utils.escape(part_title).gsub("+", "%20") rescue nil}&item_type=page_part"
categories_str=(!part[:category].blank? ? part[:category] : category).collect{|t| "category_id[]=#{t}"}.join('&')
tags_str=(!part[:tag].blank? ? part[:tag] : tag).collect{|t| "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]}&part_title=#{Rack::Utils.escape(part_title).gsub("+", "%20") rescue nil}&item_type=page_part"
ret << "<div class='dymanic_load widget' path='#{url + options}'></div>" ret << "<div class='dymanic_load widget' path='#{url + options}'></div>"
when 'public_r_tag' when 'public_r_tag'
ret << "<r:#{part.public_r_tag} id='#{part.public_r_tag_object_id}'/>" ret << "<r:#{part.public_r_tag} id='#{part.public_r_tag_object_id}'/>"

View File

@ -110,6 +110,7 @@ module ParserFrontEnd
public_r_tags = [] public_r_tags = []
url = '' url = ''
body.css('.page_content').each do |content| body.css('.page_content').each do |content|
ret = '' ret = ''
if (content["main"] == "true" && !page.module_app.nil?) if (content["main"] == "true" && !page.module_app.nil?)
if page.app_frontend_url == 'default_widget' if page.app_frontend_url == 'default_widget'
@ -119,8 +120,12 @@ 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" 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 end
categories_str=category.collect{|t| "category_id[]=#{t}"}.join('&')
options = "&page_id=#{page.id}&category_id=\#{category}&tag_id=\#{tag}&preview=\#{params[:preview]}&page_main=\#{params[:page_main]}&search_query=\#{params[:search_query]}&name=\#{params[:name]}&item_type=page" tags_str=tag.collect{|t| "tag_id[]=#{t}"}.join('&')
categories_str = "&#{categories_str}" unless categories_str.blank?
tags_str = "&#{tags_str}" unless tags_str.blank?
options = "&page_id=\#{page.id}#{categories_str}#{tags_str}&preview=\#{params[:preview]}&page_main=\#{params[:page_main]}&search_query=\#{params[:search_query]}&name=\#{params[:name]}&item_type=page"
ret << "<orbit_front path='#{url + options}'></div>" ret << "<orbit_front path='#{url + options}'></div>"
else else
part = page.page_parts.detect{ |p| p.name.to_s == content['name'].to_s } rescue nil part = page.page_parts.detect{ |p| p.name.to_s == content['name'].to_s } rescue nil
@ -137,7 +142,13 @@ module ParserFrontEnd
else else
"/panel/\#{part.module_app.key}/widget/\#{part.widget_path}?inner=true" "/panel/\#{part.module_app.key}/widget/\#{part.widget_path}?inner=true"
end end
options = "&part_id=\#{part.id}&category_id=\#{part[:category]}&tag_id=\#{part[:tag]}&page=\#{params[:page]}&search_query=\#{params[:search_query]}&part_title=\#{Rack::Utils.escape(part_title).gsub(\"\+\", \"\%20\") rescue nil}&item_type=page_part"
categories_str=part[:category].collect{|t| "category_id[]=#{t}"}.join('&')
tags_str=part[:tag].collect{|t| "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]}&part_title=\#{Rack::Utils.escape(part_title).gsub(\"\+\", \"\%20\") rescue nil}&item_type=page_part"
ret << "<orbit_front path='#{url + options}' part_id=#{part.id} class='dymanic_load widget'></orbit_front>" ret << "<orbit_front path='#{url + options}' part_id=#{part.id} class='dymanic_load widget'></orbit_front>"
when 'public_r_tag' when 'public_r_tag'