default widget show search
This commit is contained in:
parent
c0f1614cb9
commit
06fd305bf9
|
@ -12,25 +12,34 @@ class DefaultWidgetController< OrbitWidgetController
|
||||||
|
|
||||||
def query_for_default_widget
|
def query_for_default_widget
|
||||||
|
|
||||||
ori_class_name = @default_widget["query"].split('.')[0]
|
@ori_class_name = @default_widget["query"].split('.')[0]
|
||||||
result = nil
|
result = nil
|
||||||
result_objects = nil
|
result_objects = nil
|
||||||
|
|
||||||
if !params["tag_id"].blank?
|
if !params["tag_id"].blank?
|
||||||
if params["category_id"].blank? #has tag no cate
|
if params["category_id"].blank? #has tag no cate
|
||||||
result = ori_class_name.constantize.where(:tagged_ids.in => params["tag_id"])
|
result = @ori_class_name.constantize.where(:tagged_ids.in => params["tag_id"])
|
||||||
else #has tag and cate
|
else #has tag and cate
|
||||||
result = eval("#{ori_class_name}.where(:#{get_category_field_name(ori_class_name)}.in=>params['category_id'], :tagged_ids.in => params['tag_id'])")
|
result = eval("#{@ori_class_name}.where(:#{get_category_field_name(@ori_class_name)}.in=>params['category_id'], :tagged_ids.in => params['tag_id'])")
|
||||||
end
|
end
|
||||||
elsif params["category_id"].blank? #no tag no cate
|
elsif params["category_id"].blank? #no tag no cate
|
||||||
result = eval(@default_widget["query"])
|
result = eval(@default_widget["query"])
|
||||||
else #no tag has cate
|
else #no tag has cate
|
||||||
result = eval("#{ori_class_name}.where(:#{get_category_field_name(ori_class_name)}.in=>params['category_id'])")
|
result = eval("#{@ori_class_name}.where(:#{get_category_field_name(@ori_class_name)}.in=>params['category_id'])")
|
||||||
end
|
end
|
||||||
result.available_for_lang(I18n.locale).can_display.desc(:is_top, :postdate)
|
result.available_for_lang(I18n.locale).can_display.desc(:is_top, :postdate)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def search_result
|
||||||
|
@search = query_for_default_widget.solr_search do
|
||||||
|
fulltext params[:search_query]
|
||||||
|
end
|
||||||
|
search_result = @search.results.collect{|result| result.id}
|
||||||
|
@items = eval(@ori_class_name).all.available_for_lang(I18n.locale).can_display.any_in(_id:search_result)
|
||||||
|
end
|
||||||
|
|
||||||
def default_widget
|
def default_widget
|
||||||
|
@search = params["search_query"].blank? ? false : true
|
||||||
if !params[:id].blank?
|
if !params[:id].blank?
|
||||||
clicked_field_name = params["clicked_field_name"].to_sym
|
clicked_field_name = params["clicked_field_name"].to_sym
|
||||||
redirect_to eval("#{@page_part.module_app.widget_fields_link_method[clicked_field_name][:method]}('#{params[:id]}', {inner: #{params[:inner] || true}})")
|
redirect_to eval("#{@page_part.module_app.widget_fields_link_method[clicked_field_name][:method]}('#{params[:id]}', {inner: #{params[:inner] || true}})")
|
||||||
|
@ -55,8 +64,13 @@ class DefaultWidgetController< OrbitWidgetController
|
||||||
@fields = @page_part.widget_field
|
@fields = @page_part.widget_field
|
||||||
@data_limit = @page_part.widget_data_count.is_a?(Fixnum) ? @page_part.widget_data_count : (@page_part.widget_data_count.to_i rescue 3)
|
@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
|
end
|
||||||
if @paginate
|
|
||||||
@data = query_for_default_widget.includes(@widget_image_field).page(params[:page_main]).per(@data_limit)
|
if @paginate || @search
|
||||||
|
if @search
|
||||||
|
@data = search_result.page(params[:page_main]).per(@data_limit) rescue []
|
||||||
|
else #regular listing
|
||||||
|
@data = query_for_default_widget.includes(@widget_image_field).page(params[:page_main]).per(@data_limit)
|
||||||
|
end
|
||||||
# @data = query_for_default_widget.limit(@data_limit).includes(@widget_image_field)
|
# @data = query_for_default_widget.limit(@data_limit).includes(@widget_image_field)
|
||||||
else
|
else
|
||||||
@data = query_for_default_widget.includes(@widget_image_field).limit(@data_limit)
|
@data = query_for_default_widget.includes(@widget_image_field).limit(@data_limit)
|
||||||
|
@ -76,9 +90,9 @@ class DefaultWidgetController< OrbitWidgetController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_category_field_name(ori_class_name)
|
def get_category_field_name()
|
||||||
ori_class_name = ori_class_name.constantize
|
@ori_class_name = @ori_class_name.constantize
|
||||||
ori_class_name.fields.each_key do |key|
|
@ori_class_name.fields.each_key do |key|
|
||||||
return key if key.include?('category_id')
|
return key if key.include?('category_id')
|
||||||
end
|
end
|
||||||
nil
|
nil
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
|
<% if @data.blank? and @search %>
|
||||||
|
<%=render :partial => 'shared/search_not_found' %>
|
||||||
|
<% elsif @search %>
|
||||||
|
<%= t("search.result_get",:search_word => params[:search_query],:item_num=>@data.count) unless (@data.count == 30) %>
|
||||||
|
<%= t("search.too_many",:search_word => params[:search_query],:exceed_num=>@data.count) if (@data.count ==30) %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<%= render @partial %>
|
<%= render @partial %>
|
||||||
<% if @paginate %>
|
<% if @paginate and !@data.blank? %>
|
||||||
<%= paginate @data, :param_name => :page_main, :params => {:same_page_id => @page_id} %>
|
<%= paginate @data, :param_name => :page_main, :params => {:same_page_id => @page_id} %>
|
||||||
<% elsif @page_part.module_app %>
|
<% elsif @page_part.module_app %>
|
||||||
<%= @page_part.module_app.get_registration.default_widget_setting.link_to_more_tag(request,params) %>
|
<%= @page_part.module_app.get_registration.default_widget_setting.link_to_more_tag(request,params) %>
|
||||||
|
|
Reference in New Issue