Sha256: ea3718669a2ac829c4036abd2175319d894258c497c571f3b3e7ea7b94b1966a

Contents?: true

Size: 1.06 KB

Versions: 19

Compression:

Stored size: 1.06 KB

Contents

module AdminIt
  module ActiveRecordData
    #
    module CollectionContext
      def entities=(value)
        super(value)
        @count = @entities.nil? ? 0 : @entities.count
      end

      protected

      def load_entities
        collection =
          if AdminIt::Env.pundit?
            controller.policy_scope(entity_class)
          else
            entity_class.all
          end
        if child?
          collection = collection.where(parent.resource.name => parent.entity)
        end
        sort = {}
        sorting.each do |_sort|
          name, order = _sort.split(':')
          sort[name.to_sym] = order.to_sym
        end
        unless collection.nil? || sort.empty?
          collection = collection.order(sort)
        end
        collection
      end
    end

    #
    module TableContext
      def entities
        if @entities.count > page_size
          # limit collection to current page
          @entities = @entities
            .offset(page_size * (page - 1))
            .limit(page_size)
        end
        super
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
admin_it-1.3.8 lib/admin_it/data/active_record/collection_context.rb
admin_it-1.3.7 lib/admin_it/data/active_record/collection_context.rb
admin_it-1.3.6 lib/admin_it/data/active_record/collection_context.rb
admin_it-1.3.5 lib/admin_it/data/active_record/collection_context.rb
admin_it-1.3.4 lib/admin_it/data/active_record/collection_context.rb
admin_it-1.3.3 lib/admin_it/data/active_record/collection_context.rb
admin_it-1.3.2 lib/admin_it/data/active_record/collection_context.rb
admin_it-1.3.1 lib/admin_it/data/active_record/collection_context.rb
admin_it-1.3.0 lib/admin_it/data/active_record/collection_context.rb
admin_it-1.2.8 lib/admin_it/data/active_record/collection_context.rb
admin_it-1.2.7 lib/admin_it/data/active_record/collection_context.rb
admin_it-1.2.6 lib/admin_it/data/active_record/collection_context.rb
admin_it-1.2.5 lib/admin_it/data/active_record/collection_context.rb
admin_it-1.2.4 lib/admin_it/data/active_record/collection_context.rb
admin_it-1.2.3 lib/admin_it/data/active_record/collection_context.rb
admin_it-1.2.2 lib/admin_it/data/active_record/collection_context.rb
admin_it-1.2.1 lib/admin_it/data/active_record/collection_context.rb
admin_it-1.2.0 lib/admin_it/data/active_record/collection_context.rb
admin_it-1.1.0 lib/admin_it/data/active_record/collection_context.rb