diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7f4ea0fa..6e5f80e1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -234,7 +234,13 @@ class ApplicationController < ActionController::Base ret = '' 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 << "?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 end diff --git a/app/controllers/default_widget_controller.rb b/app/controllers/default_widget_controller.rb index d9fb8af0..0bff5ebc 100644 --- a/app/controllers/default_widget_controller.rb +++ b/app/controllers/default_widget_controller.rb @@ -11,26 +11,32 @@ class DefaultWidgetController< OrbitWidgetController end def query_for_default_widget + ori_class_name = @default_widget["query"].split('.')[0] result = nil result_objects = nil - params["tag_id"] = [] if params["tag_id"]=="[]" - params["category_id"] = [] if params["category_id"]=="[]" if !params["tag_id"].blank? @tags = Tag.find(params["tag_id"]) rescue 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 - else - 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 + + result_ids = @tags.collect{|tag| tag.send(ori_class_name.downcase.pluralize).entries.collect{|t| t.id}} + if params["category_id"].blank? #has tag no cate + #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 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"]) - else - result = eval("#{ori_class_name}.where(:category_id.in=>params['category_id'])") + else #no tag has cate + result = eval("#{ori_class_name}.where(:#{get_category_field_name(ori_class_name)}.in=>params['category_id'])") end + result.available_for_lang(I18n.locale).can_display end @@ -72,4 +78,12 @@ class DefaultWidgetController< OrbitWidgetController 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 diff --git a/lib/parsers/parser_common.rb b/lib/parsers/parser_common.rb index 7d858686..d2f8b7b2 100644 --- a/lib/parsers/parser_common.rb +++ b/lib/parsers/parser_common.rb @@ -236,7 +236,13 @@ module ParserCommon end ret << "
" else 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? "/panel/#{part.module_app.key}/widget/#{part.widget_path}?inner=true" 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 << "" when 'public_r_tag' ret << "