From 369bbe4d72abef473768819f9f73996d6e6a956b Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Mon, 18 Nov 2013 17:11:47 +0800 Subject: [PATCH] category click, event click and more button fix --- app/controllers/default_widget_controller.rb | 13 +++++--- app/controllers/pages_controller.rb | 32 ++++++++++++++----- .../helper/default_widget_tag_helper.rb | 1 - lib/parsers/parser_front_end.rb | 5 +-- .../front_end/web_links_controller.rb | 4 +-- 5 files changed, 37 insertions(+), 18 deletions(-) diff --git a/app/controllers/default_widget_controller.rb b/app/controllers/default_widget_controller.rb index 370b1de9..f79e513a 100644 --- a/app/controllers/default_widget_controller.rb +++ b/app/controllers/default_widget_controller.rb @@ -70,8 +70,8 @@ class DefaultWidgetController< OrbitWidgetController @data_limit = @page_part.widget_data_count.is_a?(Fixnum) ? @page_part.widget_data_count : (@page_part.widget_data_count.to_i rescue 3) end - if params[:click] - @data = get_more_btn_data.page(params[:page_main]).per(@data_limit) + if params[:filter_category_id] and !params[:filter_category_id].blank? + @data = get_filter_data.page(params[:page_main]).per(@data_limit) elsif @paginate || @search if @search @@ -98,10 +98,13 @@ class DefaultWidgetController< OrbitWidgetController end end - def get_more_btn_data - filterids = PagePart.find(params[:part_id]).category + def get_filter_data model = eval(@default_widget["query"]) - data = model.where(:category_id.in => filterids) + if params[:filter_category_id].is_a? Array + data = model.where(:category_id.in => params[:filter_category_id]) + elsif params[:filter_category_id].is_a? String + data = model.where(:category_id => params[:filter_category_id]) + end data.available_for_lang(I18n.locale).can_display.desc(:is_top, :postdate) end diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index db7fcf96..275a1950 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -65,24 +65,24 @@ class PagesController < ApplicationController options = '' options << "#{options.blank? ? '?' : '&'}page_main=#{params[:page_main]}" unless params[:page_main].blank? options << "#{options.blank? ? '?' : '&'}click=#{params[:click]}" unless params[:click].blank? - options << "#{options.blank? ? '?' : '&'}part_id=#{params[:page_part_id]}" unless params[:page_part_id].blank? + # options << "#{options.blank? ? '?' : '&'}part_id=#{params[:page_part_id]}" unless params[:page_part_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? + options << "#{options.blank? ? '?' : '&'}#{convert_array_param('filter_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? + options << "#{options.blank? ? '?' : '&'}filter_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? + options << "#{options.blank? ? '?' : '&'}#{convert_array_param('filter_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? + options << "#{options.blank? ? '?' : '&'}filter_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) + # uri = URI::escape(url + options) + uri = url + options #uri = URI::escape("#{url}?" + params.collect{|k,v| "#{k}=#{v}"}.join('&')) redirect_to(uri)unless save_from_no_lang_for_page end @@ -168,17 +168,33 @@ class PagesController < ApplicationController # end # @item = Item.find(params[:orig_page]) unless @item || params[:orig_page].blank? # @item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action]).all_of("tag" => {"$in" => [nil, []]},"category" => { "$in" => [nil, []]}).first unless @item + # # @item = Item.root.children.where(:module_app_id => module_app.id).first # @item = Item.where(module_app_id: module_app.id, app_frontend_url: 'default_widget').first unless @item # @item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action]).first unless @item # end # raise PageError,'Missing Frontend Page' if @item.nil? + if params[:page_id] @item = Item.find(params[:page_id]) elsif params[:same_page_id] @item = Item.find(params[:same_page_id]) else module_app = ModuleApp.first(:conditions => {:key => params[:app_name]}) - @item = Item.root.children.where(:module_app_id => module_app.id).first + category_ids = params[:category_id] ? (params[:category_id].is_a?(Array) ? params[:category_id] : [params[:category_id]]) : [] + tag_ids = params[:tag_id].is_a?(Array) ? params[:tag_id] : [params[:tag_id]] + + if !category_ids.blank? + @item = Item.where(:category => category_ids).first + else + if params[:action] && params[:action] == "show_from_link" + default_widget = module_app.get_default_widget + model = eval(default_widget["query"]) + item = model.find(params[:id]) + @item = Item.where(:category => [item.category_id.to_s]).first + end + end + + @item = Item.root.children.where(:module_app_id => module_app.id).first unless @item end raise PageError,'Missing Frontend Page' if @item.nil? end diff --git a/lib/orbit_app/helper/default_widget_tag_helper.rb b/lib/orbit_app/helper/default_widget_tag_helper.rb index a831095c..935848c6 100644 --- a/lib/orbit_app/helper/default_widget_tag_helper.rb +++ b/lib/orbit_app/helper/default_widget_tag_helper.rb @@ -16,7 +16,6 @@ module DefaultWidgetTagHelper end end params_str = params_str + (params_str.eql?("?") ? params.to_param : "&#{params.to_param}" ) - params_str = params_str + "&click=more_btn&page_part_id=#{@params[:part_id]}" content_tag :div,:class=> 'more' do link_to I18n.t(@more_link[:label_i18n]),[eval("#{@more_link[:path_method]}"),params_str].join() end diff --git a/lib/parsers/parser_front_end.rb b/lib/parsers/parser_front_end.rb index 3fa923a2..3f8b02e7 100644 --- a/lib/parsers/parser_front_end.rb +++ b/lib/parsers/parser_front_end.rb @@ -19,7 +19,6 @@ module ParserFrontEnd end 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] @@ -48,7 +47,9 @@ module ParserFrontEnd ret = '' part = PagePart.find(front['part_id']) if front['part_id'] ret << eval("\"#{front['path']}\"") rescue '' - ret << (ret.include?("?") ? "&#{args.to_param}" : "?#{args.to_param}") if args.present? + ar = args.to_param + ar = URI.unescape(ar) + ret << (ret.include?("?") ? "&#{ar}" : "?#{ar}") if args.present? fragment = Nokogiri::HTML::DocumentFragment.new(body, "
") end front.swap(fragment) diff --git a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/front_end/web_links_controller.rb b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/front_end/web_links_controller.rb index 91056001..bda0672e 100644 --- a/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/front_end/web_links_controller.rb +++ b/vendor/built_in_modules/web_resource/app/controllers/panel/web_resource/front_end/web_links_controller.rb @@ -23,8 +23,8 @@ class Panel::WebResource::FrontEnd::WebLinksController < OrbitWidgetController date_now = Time.now # @web_link_categorys = get_categories_for_index - if !params[:category_id].blank? - @web_link_categorys = @module_app.categories.enabled.any_in(:_id => params[:category_id]) + if !params[:filter_category_id].blank? + @web_link_categorys = @module_app.categories.enabled.any_in(:_id => params[:filter_category_id]) else @web_link_categorys = @module_app.categories.enabled end