From 7729161123ef32045b921955686535e0be76375c Mon Sep 17 00:00:00 2001 From: "Matt K. Fu" Date: Fri, 31 May 2013 11:30:01 +0800 Subject: [PATCH] fix for passing args. code in complete,fronted controller need to take care params,too. backend parser need to catch up. --- app/controllers/application_controller.rb | 2 +- app/controllers/orbit_widget_controller.rb | 7 +++++++ app/controllers/pages_controller.rb | 20 ++++++++++++++++-- lib/orbit_app.rb | 1 + .../helper/default_widget_tag_helper.rb | 15 +++++++++++-- .../helper/front_end_array_params_helper.rb | 21 +++++++++++++++++++ lib/parsers/parser_front_end.rb | 16 +++++++------- .../front_end/bulletins_controller.rb | 1 - .../front_end/bulletins/index.html.erb | 3 +-- 9 files changed, 71 insertions(+), 15 deletions(-) create mode 100644 lib/orbit_app/helper/front_end_array_params_helper.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 07da9be1..30a8a3ac 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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' } diff --git a/app/controllers/orbit_widget_controller.rb b/app/controllers/orbit_widget_controller.rb index f006cd43..857d7e4e 100644 --- a/app/controllers/orbit_widget_controller.rb +++ b/app/controllers/orbit_widget_controller.rb @@ -1,4 +1,11 @@ class OrbitWidgetController< OrbitFrontendComponentController + include FrontEndArrayParamsHelper + before_filter :get_tags_and_cates + + def get_tags_and_cates + binding.pry + params = tags_and_cates(params) + end end \ No newline at end of file diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 2796c6a5..dbec5ba2 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -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? - options << "#{options.blank? ? '?' : '&'}category_id=#{params[:category_id]}" unless params[:category_id].blank? - options << "#{options.blank? ? '?' : '&'}tag_id=#{params[:tag_id]}" unless params[:tag_id].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) diff --git a/lib/orbit_app.rb b/lib/orbit_app.rb index 0d801751..36d5839a 100644 --- a/lib/orbit_app.rb +++ b/lib/orbit_app.rb @@ -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" diff --git a/lib/orbit_app/helper/default_widget_tag_helper.rb b/lib/orbit_app/helper/default_widget_tag_helper.rb index 52160398..58a789e5 100644 --- a/lib/orbit_app/helper/default_widget_tag_helper.rb +++ b/lib/orbit_app/helper/default_widget_tag_helper.rb @@ -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 \ No newline at end of file diff --git a/lib/orbit_app/helper/front_end_array_params_helper.rb b/lib/orbit_app/helper/front_end_array_params_helper.rb new file mode 100644 index 00000000..c8b0de2a --- /dev/null +++ b/lib/orbit_app/helper/front_end_array_params_helper.rb @@ -0,0 +1,21 @@ +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 \ No newline at end of file diff --git a/lib/parsers/parser_front_end.rb b/lib/parsers/parser_front_end.rb index 472c302b..46b5066d 100644 --- a/lib/parsers/parser_front_end.rb +++ b/lib/parsers/parser_front_end.rb @@ -18,11 +18,12 @@ module ParserFrontEnd i18n end - def parse_page_content(page,args=nil) - args["category_id"] = args["category_id"].gsub(/\"|\[|\]/,'').split(",").each(&:strip!) if args["category_id"].is_a? String - args["tag_id"] = args["tag_id"].gsub(/\"|\[|\]/,'').split(",").each(&:strip!) if args["tag_id"].is_a? String + 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'] @@ -129,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? @@ -152,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&tag_id=\#{params[:tag_id]}&category_id=\#{params[:category_id]}" + ret << "" when 'public_r_tag' diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb index be191fbf..9b4dc528 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb @@ -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} diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/index.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/index.html.erb index 2182869f..007b6d0d 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/index.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/front_end/bulletins/index.html.erb @@ -31,6 +31,5 @@ <% end %> - -<%= paginate @bulletins, :param_name => :page_main, :params => {:inner => 'false'} %> +<%= paginate( @bulletins, :param_name => :page_main, :params => {:inner => 'false'} ) rescue nil%>