Sha256: a2e8f2cc7608ca4c1ae437ee5198329e7eb9df8b7ce54977f93d357937310d9f

Contents?: true

Size: 789 Bytes

Versions: 13

Compression:

Stored size: 789 Bytes

Contents

module Admin::Resources::PaginationHelper

  def admin_paginate
    params[:per_page] ||= @resource.typus_options_for(:per_page)
    params[:per_page] = params[:per_page].to_i

    params[:offset] ||= 0
    params[:offset] = params[:offset].to_i

    next_offset = params[:offset] + params[:per_page]
    previous_offset = params[:offset] - params[:per_page]

    options = {}

    current_page = (params[:offset].to_f / params[:per_page]) + 1
    num_pages = (@resource.count.to_f / params[:per_page]).ceil
    unless current_page >= num_pages
      options[:next] = params.merge(offset: next_offset)
    end

    if previous_offset >= 0
      options[:previous] = params.merge(offset: previous_offset)
    end

    render "admin/resources/pagination", { :options => options }
  end

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
brainsome_typus-4.0.0.beta13 app/helpers/admin/resources/pagination_helper.rb
brainsome_typus-4.0.0.beta12 app/helpers/admin/resources/pagination_helper.rb
brainsome_typus-4.0.0.beta11 app/helpers/admin/resources/pagination_helper.rb
brainsome_typus-4.0.0.beta10 app/helpers/admin/resources/pagination_helper.rb
brainsome_typus-4.0.0.beta9 app/helpers/admin/resources/pagination_helper.rb
brainsome_typus-4.0.0.beta8 app/helpers/admin/resources/pagination_helper.rb
brainsome_typus-4.0.0.beta7 app/helpers/admin/resources/pagination_helper.rb
brainsome_typus-4.0.0.beta6 app/helpers/admin/resources/pagination_helper.rb
brainsome_typus-4.0.0.beta5 app/helpers/admin/resources/pagination_helper.rb
brainsome_typus-4.0.0.beta4 app/helpers/admin/resources/pagination_helper.rb
brainsome_typus-4.0.0.beta3 app/helpers/admin/resources/pagination_helper.rb
brainsome_typus-4.0.0.beta2 app/helpers/admin/resources/pagination_helper.rb
brainsome_typus-4.0.0.beta1 app/helpers/admin/resources/pagination_helper.rb