Sha256: ff8da858305d085b8832fb3e286ab0ba7368e8c043dd06cad439e5d93a4d19ee

Contents?: true

Size: 1.22 KB

Versions: 6

Compression:

Stored size: 1.22 KB

Contents

module SmartTable
  module SmartTableConcern
    extend ActiveSupport::Concern

    included do
      helper_method :get_cached_smart_table_params
    end

    class Params
      attr_accessor :sort, :page_size, :page_number, :search

      def initialize
        self.sort = nil
        self.page_size = nil
        self.page_number = 1
        self.search = nil
      end

      def limit
        page_size
      end

      def offset
        page_size * (page_number-1) if page_size
      end
    end

    def smart_table_params(initial_page_size: 25)
      return @st_params if @st_params

      @st_params = Params.new
      @st_params.sort = params[SORT_PARAM]
      @st_params.search = params[SEARCH_PARAM]
      @st_params.page_size = params[PAGE_SIZE_PARAM] || initial_page_size
      if @st_params.page_size == SHOW_ALL
        @st_params.page_size = nil
      else
        @st_params.page_size = @st_params.page_size.to_i

        if params[PAGE_PARAM].present? && params[PAGE_PARAM] =~ /\d+/
          page = params[PAGE_PARAM].to_i
          page = 1 if page < 1
          @st_params.page_number = page
        end
      end

      @st_params
    end

  private

    def get_cached_smart_table_params
      @st_params
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
smart_table-0.0.6 ./app/controllers/concerns/smart_table/smart_table_concern.rb
smart_table-0.0.5 ./app/controllers/concerns/smart_table/smart_table_concern.rb
smart_table-0.0.4 ./app/controllers/concerns/smart_table/smart_table_concern.rb
smart_table-0.0.3 ./app/controllers/concerns/smart_table/smart_table_concern.rb
smart_table-0.0.2 ./app/controllers/concerns/smart_table/smart_table_concern.rb
smart_table-0.0.1 ./app/controllers/concerns/smart_table/smart_table_concern.rb