default widget query for category and tags
This commit is contained in:
parent
a9fecec985
commit
5a177f34a8
|
@ -10,6 +10,24 @@ class DefaultWidgetController< OrbitWidgetController
|
|||
@page_part.module_app.enable_frontend?
|
||||
end
|
||||
|
||||
def query_for_default_widget
|
||||
ori_class_name = @default_widget["query"].split('.')[0]
|
||||
result = nil
|
||||
if !params["tag_id"].blank?
|
||||
@tag = Tag.find(params["tag_id"]) rescue nil
|
||||
if params["category_id"].blank?
|
||||
result = @tag.send(ori_class_name.downcase.pluralize)
|
||||
else
|
||||
result = @tag.send(ori_class_name.downcase.pluralize).where(:category_id=>params["category_id"])
|
||||
end
|
||||
elsif params["category_id"].blank?
|
||||
result = eval(@default_widget["query"])
|
||||
else
|
||||
result = eval("#{ori_class_name}.where(:category_id=>params['category_id'])")
|
||||
end
|
||||
result.available_for_lang(I18n.locale).can_display
|
||||
end
|
||||
|
||||
def default_widget
|
||||
if !params[:id].blank?
|
||||
redirect_to eval("#{@page_part.module_app.widget_fields_link_method['title']['method']}('#{params[:id]}', {inner: #{params[:inner] || true}})")
|
||||
|
@ -29,11 +47,16 @@ 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 @paginate
|
||||
<<<<<<< HEAD
|
||||
@data = eval(@default_widget["query"]).includes(@widget_image_field).page(params[:page_main]).per(@data_limit).desc(:created_at)
|
||||
else
|
||||
@data = eval(@default_widget["query"]).limit(@data_limit).includes(@widget_image_field).desc(:created_at)
|
||||
=======
|
||||
@data = query_for_default_widget.includes(@widget_image_field).page(params[:page_main]).per(@data_limit)
|
||||
else
|
||||
@data = query_for_default_widget.limit(@data_limit).includes(@widget_image_field)
|
||||
>>>>>>> 4650f80... default widget query for category and tags
|
||||
end
|
||||
|
||||
case params[:type]
|
||||
when "typeA"
|
||||
@tag_class = 'default_widget_typeA'
|
||||
|
|
Loading…
Reference in New Issue