fix link for default widget

This commit is contained in:
Fu Matthew 2013-02-18 17:03:18 +08:00 committed by chris
parent 0a115906f1
commit 572e512a1d
6 changed files with 28 additions and 10 deletions

View File

@ -23,7 +23,7 @@ class DefaultWidgetController< OrbitWidgetController
@fields = @page_part.widget_field @fields = @page_part.widget_field
@page_part.widget_data_count.is_a?(Fixnum) ? @page_part.widget_data_count : (@page_part.widget_data_count.to_i rescue 3) @page_part.widget_data_count.is_a?(Fixnum) ? @page_part.widget_data_count : (@page_part.widget_data_count.to_i rescue 3)
end end
@data = eval(@default_widget["query"]).limit(data_limit).includes(@widget_image_field) @data = eval(@default_widget["query"]).limit(data_limit).includes(@widget_image_field).desc(:created_at)
case params[:type] case params[:type]
when "typeA" when "typeA"
@tag_class = 'default_widget_typeA' @tag_class = 'default_widget_typeA'

View File

@ -3,20 +3,21 @@ module DefaultWidgetHelper
I18n.t("#{@page_part.module_app.key}.default_widget.#{field}") I18n.t("#{@page_part.module_app.key}.default_widget.#{field}")
end end
def link_to_field(row_data,field) def link_to_field(row_data,field,switch)
method_ary = @page_part.module_app.widget_fields_link_method method_ary = @page_part.module_app.widget_fields_link_method
if method_ary.has_key? field field = field.to_sym
url = case method_ary[field]["args"] if(method_ary.has_key?(field) and (switch == "true"))
url = case method_ary[field][:args]
when nil # no args when nil # no args
get_data_link(method_ary[field]["method"]) get_data_link(method_ary[field][:method])
when :self # passing self when :self # passing self
get_data_link(method_ary[field]['method'],row_data.id) get_data_link(method_ary[field][:method],row_data.id)
else else
ary = method_ary[field]["args"].clone ary = method_ary[field][:args].clone
object_hash = ary.each do |key,val| object_hash = ary.each do |key,val|
ary[key]= type_trans_or_to_s(row_data.send(val[0]).send(val[1])) ary[key]= type_trans_or_to_s(row_data.send(val[0]).send(val[1]))
end end
get_data_link(method_ary[field]['method'],object_hash) get_data_link(method_ary[field][:method],object_hash)
end end
link_to row_data.send(field),url link_to row_data.send(field),url

View File

@ -98,7 +98,8 @@ class ModuleApp
end end
def widget_fields_link_method def widget_fields_link_method
raise 'Need to link with OrbitApp [type: Hash]' get_registration.get_link_methods
# raise 'Need to link with OrbitApp [type: Hash]'
end end

View File

@ -11,7 +11,7 @@
<% @data.each do |row_data| %> <% @data.each do |row_data| %>
<tr> <tr>
<% @fields.each do |field|%> <% @fields.each do |field|%>
<td><%= content_tag(:span,link_to_field(row_data,field[0]),:class=>field[1])%></td> <td><%= content_tag(:span,link_to_field(row_data,field[0],field[2]),:class=>field[1])%></td>
<% end %> <% end %>
</tr> </tr>
<% end %> <% end %>

View File

@ -64,6 +64,10 @@ module OrbitApp
return @widget_set.get_fields return @widget_set.get_fields
end end
def get_link_methods
return @widget_set.get_link_methods
end
def get_default_widget def get_default_widget
if @widget_set.nil? # Init not defining widget if @widget_set.nil? # Init not defining widget
return {} return {}

View File

@ -75,6 +75,10 @@ module OrbitApp
get_default_widget.get_fields get_default_widget.get_fields
end end
def get_link_methods
get_default_widget.get_link_methods
end
def get_default_widget def get_default_widget
return @default_widget return @default_widget
end end
@ -117,6 +121,10 @@ module OrbitApp
@fields @fields
end end
def get_link_methods
return flatten_hashes(@fields.select{|t| t[2]==:link}.map{|t| Hash[t[0].to_sym,t[1]] })
end
def query(var) def query(var)
@query = var @query = var
end end
@ -125,6 +133,10 @@ module OrbitApp
@image = var @image = var
end end
def flatten_hashes(ary)
Hash[*ary.map(&:to_a).flatten]
end
end end
class Widget class Widget