From 6d1f919bb7b5d0353a26d8fd204e80a5817b6060 Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 7 Feb 2013 21:15:38 +0800 Subject: [PATCH] Fix links in default widget --- app/controllers/pages_controller.rb | 3 ++- app/helpers/default_widget_helper.rb | 26 ++++++++++++++---------- app/views/default_widget/_typeA.html.erb | 2 +- app/views/default_widget/_typeB.html.erb | 2 +- app/views/default_widget/_typeC.html.erb | 2 +- lib/parsers/parser_front_end.rb | 5 +++-- 6 files changed, 23 insertions(+), 17 deletions(-) diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index ece047f1..ef9e3e77 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -76,9 +76,10 @@ class PagesController < ApplicationController elsif !params[:tag_id].blank? @item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action], tag: params[:tag_id]).any_in(category: [nil,'']).first 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.where(module_app_id: module_app.id, app_frontend_url: params[:app_action]).first unless @item @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? end diff --git a/app/helpers/default_widget_helper.rb b/app/helpers/default_widget_helper.rb index 913c77ee..9173b823 100644 --- a/app/helpers/default_widget_helper.rb +++ b/app/helpers/default_widget_helper.rb @@ -3,24 +3,24 @@ module DefaultWidgetHelper I18n.t("#{@page_part.module_app.key}.default_widget.#{field}") end - def link_to_field(row_data,field,switch) + def link_to_field(row_data,field, options=nil, switch) method_ary = @page_part.module_app.widget_fields_link_method field = field.to_sym if(method_ary.has_key?(field) and (switch == "true")) url = case method_ary[field][:args] when nil # no args - get_data_link(method_ary[field][:method]) + get_data_link(method_ary[field]["method"], options) when :self # passing self - get_data_link(method_ary[field][:method],row_data.id) + get_data_link(method_ary[field]['method'], options,row_data.id) else ary = method_ary[field][:args].clone object_hash = ary.each do |key,val| ary[key]= type_trans_or_to_s(row_data.send(val[0]).send(val[1])) end - get_data_link(method_ary[field][:method],object_hash) + get_data_link(method_ary[field]['method'], options,object_hash) end - - link_to row_data.send(field),url + + link_to row_data.send(field), url else type_trans_or_to_s(row_data.send(field) ) end @@ -45,13 +45,17 @@ module DefaultWidgetHelper end end - def get_data_link(method_entry,object = nil) + def get_data_link(method_entry, options=nil, object = nil) case object - when nil - eval method_entry + when NilClass + eval eval("#{method_entry}(#{options})") + when BSON::ObjectId + object = "'#{object.to_s}'" + eval("#{method_entry}(#{object}, #{options})") + when Hash + eval("#{method_entry}(#{object.merge options})") else - object = "'#{object.to_s}'" if object.class == BSON::ObjectId - eval("#{method_entry}(#{object})" ) + '' end end diff --git a/app/views/default_widget/_typeA.html.erb b/app/views/default_widget/_typeA.html.erb index 20ce3dbd..02dabedb 100644 --- a/app/views/default_widget/_typeA.html.erb +++ b/app/views/default_widget/_typeA.html.erb @@ -11,7 +11,7 @@ <% @data.each do |row_data| %> <% @fields.each do |field|%> - <%= content_tag(:span,link_to_field(row_data,field[0],field[2]),:class=>field[1])%> + <%= content_tag(:span,link_to_field(row_data,field[0], orig_page: @page_id.to_s, field[2]),:class=>field[1])%> <% end %> <% end %> diff --git a/app/views/default_widget/_typeB.html.erb b/app/views/default_widget/_typeB.html.erb index 12dade57..1fa82150 100644 --- a/app/views/default_widget/_typeB.html.erb +++ b/app/views/default_widget/_typeB.html.erb @@ -7,7 +7,7 @@
<% @fields.each do |field|%> - <%= content_tag(:span,link_to_field(row_data,field[0]),:class=>field[1])%> + <%= content_tag(:span,link_to_field(row_data,field[0], orig_page: @page_id.to_s, field[2]),:class=>field[1])%> <% end %>
<% end %> diff --git a/app/views/default_widget/_typeC.html.erb b/app/views/default_widget/_typeC.html.erb index 1fa99ee0..f6e2adde 100644 --- a/app/views/default_widget/_typeC.html.erb +++ b/app/views/default_widget/_typeC.html.erb @@ -6,7 +6,7 @@ <% @data.each do |row_data| %> <%= content_tag(:li) do %> <% @fields.each do |field|%> - <%= content_tag(:span,link_to_field(row_data,field[0]),:class=>field[1])%> + <%= content_tag(:span, link_to_field(row_data,field[0], orig_page: @page_id.to_s, field[2]),:class=>field[1])%> <% end %> <% end %> <% end %> diff --git a/lib/parsers/parser_front_end.rb b/lib/parsers/parser_front_end.rb index 8cc2a668..2ab10cdd 100644 --- a/lib/parsers/parser_front_end.rb +++ b/lib/parsers/parser_front_end.rb @@ -20,6 +20,7 @@ module ParserFrontEnd def parse_page_content(page) 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'] @@ -119,7 +120,7 @@ module ParserFrontEnd end - options = "&page_id=#{page.id}&category_id=\#{page[:category]}&tag_id=\#{tag}&preview=\#{params[:preview]}&page_main=\#{params[:page_main]}&search_query=\#{params[:search_query]}&name=\#{params[:name]}&item_type=page" + 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" ret << "" else part = page.page_parts.detect{ |p| p.name.to_s == content['name'].to_s } rescue nil @@ -136,7 +137,7 @@ module ParserFrontEnd else "/panel/\#{part.module_app.key}/widget/\#{part.widget_path}?inner=true" end - options = "&part_id=\#{part.id}&category_id=\#{part[: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" + 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" ret << "" when 'public_r_tag'