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
 | 
			
		||||
    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
 | 
			
		||||
      @tag_class = nil
 | 
			
		||||
 | 
			
		||||
      @default_widget = @page_part.module_app.get_default_widget
 | 
			
		||||
      @widget_image_field = @default_widget["image"] || @default_widget[:image]
 | 
			
		||||
      data_limit = case @page_part
 | 
			
		||||
      case @page_part
 | 
			
		||||
      when Page
 | 
			
		||||
        @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
 | 
			
		||||
        @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
 | 
			
		||||
      @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]
 | 
			
		||||
      when "typeA"
 | 
			
		||||
        @tag_class = 'default_widget_typeA'
 | 
			
		||||
        render "typeA"
 | 
			
		||||
        @partial = "typeA"
 | 
			
		||||
      when /typeB_/
 | 
			
		||||
        @tag_class = "default_widget_#{params[:type]}"
 | 
			
		||||
        render "typeB"
 | 
			
		||||
        @partial = "typeB"
 | 
			
		||||
      when "typeC"
 | 
			
		||||
        @tag_class = 'default_widget_typeC'
 | 
			
		||||
        render "typeC"
 | 
			
		||||
        @partial = "typeC"
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -64,18 +64,22 @@ class PagesController < ApplicationController
 | 
			
		|||
  protected
 | 
			
		||||
   
 | 
			
		||||
  def get_item
 | 
			
		||||
    module_app = ModuleApp.first(:conditions => {:key => params[:app_name]})
 | 
			
		||||
    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 => ''}) unless @item
 | 
			
		||||
    elsif !params[:category_id].blank?
 | 
			
		||||
      @item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action], category: params[:category_id]).any_in(tag: [nil,'']).first
 | 
			
		||||
    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
 | 
			
		||||
    if params[:same_page_id]
 | 
			
		||||
      @item = Item.find(params[:same_page_id])
 | 
			
		||||
    else
 | 
			
		||||
      module_app = ModuleApp.first(:conditions => {:key => params[:app_name]})
 | 
			
		||||
      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 => ''}) unless @item
 | 
			
		||||
      elsif !params[:category_id].blank?
 | 
			
		||||
        @item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action], category: params[:category_id]).any_in(tag: [nil,'']).first
 | 
			
		||||
      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.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
 | 
			
		||||
    end
 | 
			
		||||
    @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
 | 
			
		||||
    raise PageError,'Missing Frontend Page' if @item.nil?
 | 
			
		||||
  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'
 | 
			
		||||
  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'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue