Add pagination to default widget for front end page
This commit is contained in:
parent
0cacfb7c05
commit
a9fecec985
|
@ -12,31 +12,38 @@ class DefaultWidgetController< OrbitWidgetController
|
||||||
|
|
||||||
def default_widget
|
def default_widget
|
||||||
if !params[:id].blank?
|
if !params[:id].blank?
|
||||||
redirect_to eval("#{@page_part.module_app.widget_fields_link_method['title']['method']}('#{params[:id]}', {inner: true})")
|
redirect_to eval("#{@page_part.module_app.widget_fields_link_method['title']['method']}('#{params[:id]}', {inner: #{params[:inner] || true}})")
|
||||||
else
|
else
|
||||||
@tag_class = nil
|
@tag_class = nil
|
||||||
|
|
||||||
@default_widget = @page_part.module_app.get_default_widget
|
@default_widget = @page_part.module_app.get_default_widget
|
||||||
@widget_image_field = @default_widget["image"] || @default_widget[:image]
|
@widget_image_field = @default_widget["image"] || @default_widget[:image]
|
||||||
data_limit = case @page_part
|
case @page_part
|
||||||
when Page
|
when Page
|
||||||
@fields = @page_part.frontend_field
|
@fields = @page_part.frontend_field
|
||||||
@page_part.frontend_data_count.is_a?(Fixnum) ? @page_part.frontend_data_count : (@page_part.frontend_data_count.to_i rescue 3)
|
@data_limit = @page_part.frontend_data_count.is_a?(Fixnum) ? @page_part.frontend_data_count : (@page_part.frontend_data_count.to_i rescue 3)
|
||||||
|
@paginate = true
|
||||||
|
@page_id = @page_part.id
|
||||||
when PagePart
|
when PagePart
|
||||||
@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)
|
@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
|
||||||
@data = eval(@default_widget["query"]).limit(data_limit).includes(@widget_image_field).desc(:created_at)
|
if @paginate
|
||||||
|
@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)
|
||||||
|
end
|
||||||
|
|
||||||
case params[:type]
|
case params[:type]
|
||||||
when "typeA"
|
when "typeA"
|
||||||
@tag_class = 'default_widget_typeA'
|
@tag_class = 'default_widget_typeA'
|
||||||
render "typeA"
|
@partial = "typeA"
|
||||||
when /typeB_/
|
when /typeB_/
|
||||||
@tag_class = "default_widget_#{params[:type]}"
|
@tag_class = "default_widget_#{params[:type]}"
|
||||||
render "typeB"
|
@partial = "typeB"
|
||||||
when "typeC"
|
when "typeC"
|
||||||
@tag_class = 'default_widget_typeC'
|
@tag_class = 'default_widget_typeC'
|
||||||
render "typeC"
|
@partial = "typeC"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -64,6 +64,9 @@ class PagesController < ApplicationController
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def get_item
|
def get_item
|
||||||
|
if params[:same_page_id]
|
||||||
|
@item = Item.find(params[:same_page_id])
|
||||||
|
else
|
||||||
module_app = ModuleApp.first(:conditions => {:key => params[:app_name]})
|
module_app = ModuleApp.first(:conditions => {:key => params[:app_name]})
|
||||||
if !params[:category_id].blank? && !params[:tag_id].blank?
|
if !params[:category_id].blank? && !params[:tag_id].blank?
|
||||||
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id], :tag => params[:tag_id]})
|
@item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id], :tag => params[:tag_id]})
|
||||||
|
@ -76,6 +79,7 @@ class PagesController < ApplicationController
|
||||||
@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]).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: 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: 'default_widget').first unless @item
|
||||||
|
end
|
||||||
raise PageError,'Missing Frontend Page' if @item.nil?
|
raise PageError,'Missing Frontend Page' if @item.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
<%= render @partial %>
|
||||||
|
<% if @paginate %>
|
||||||
|
<%= paginate @data, :param_name => :page_main, :params => {:same_page_id => @page_id} %>
|
||||||
|
<% end %>
|
|
@ -274,7 +274,9 @@ Orbit::Application.routes.draw do
|
||||||
root :to => 'mobile#index', :as => 'mobile'
|
root :to => 'mobile#index', :as => 'mobile'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
match '/panel/orbit_app/widget/:type' => 'pages#index_from_link', :constraints => lambda { |request|
|
||||||
|
request.query_string.include?("same_page_id=")
|
||||||
|
}
|
||||||
match '/panel/orbit_app/widget/:type' => 'default_widget#default_widget'
|
match '/panel/orbit_app/widget/:type' => 'default_widget#default_widget'
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue