Class: Outpost::List::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/outpost/list/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) {|_self| ... } ⇒ Base

Returns a new instance of Base.

Yields:

  • (_self)

Yield Parameters:



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/outpost/list/base.rb', line 4

def initialize(model, &block)
  @model   = model
  @columns = ActiveSupport::HashWithIndifferentAccess.new
  @filters = ActiveSupport::HashWithIndifferentAccess.new
  @fields  = []

  yield self if block_given?

  @default_order_attribute     ||= List::DEFAULT_ORDER_ATTRIBUTE
  @default_order_direction     ||= List::DEFAULT_ORDER_DIRECTION
  @per_page                    ||= List::DEFAULT_PER_PAGE
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



22
23
24
# File 'lib/outpost/list/base.rb', line 22

def columns
  @columns
end

#default_order_attributeObject

Returns the value of attribute default_order_attribute.



18
19
20
# File 'lib/outpost/list/base.rb', line 18

def default_order_attribute
  @default_order_attribute
end

#default_order_directionObject

Returns the value of attribute default_order_direction.



18
19
20
# File 'lib/outpost/list/base.rb', line 18

def default_order_direction
  @default_order_direction
end

#fieldsObject (readonly)

Returns the value of attribute fields.



22
23
24
# File 'lib/outpost/list/base.rb', line 22

def fields
  @fields
end

#filtersObject (readonly)

Returns the value of attribute filters.



22
23
24
# File 'lib/outpost/list/base.rb', line 22

def filters
  @filters
end

#modelObject (readonly)

Returns the value of attribute model.



22
23
24
# File 'lib/outpost/list/base.rb', line 22

def model
  @model
end

#per_pageObject

Returns the value of attribute per_page.



22
23
24
# File 'lib/outpost/list/base.rb', line 22

def per_page
  @per_page
end

Instance Method Details

#column(attribute, options = {}) ⇒ Object

Public: Add a column to the list.

attribute - (String) The attribute that this column represents. options - (Hash) A hash of options. Gets passed directly to

List::Column (default: {}).
* header  - (String) The title of the column, displayed in
            the table header
            (default: self.attribute.titleize).
* display - (Symbol or Proc) How to display this attribute.
            * If symbol, should be the name of a method in
              AdminListHelper
            * If Proc, gets run as an instance of the class.
            * See AdminListHelper for more info.

Examples

define_list do
  column :name, header: "Full Name", display: :display_full_name
  column :user,
    header: "Associated User", display: proc { self.user.name }
end

Returns nothing.



63
64
65
66
# File 'lib/outpost/list/base.rb', line 63

def column(attribute, options={})
  column = Column.new(attribute, self, options)
  @columns[attribute] = column
end

#default_columnsObject

Private: Default columns for this list

Returns Array of default columns.



83
84
85
# File 'lib/outpost/list/base.rb', line 83

def default_columns
  @model.column_names - Outpost.config.excluded_list_columns
end

#filter(attribute, options = {}) ⇒ Object

Public: Define a filter for the list.

attribute - (String) The attribute on which to filter. options - (Hash) A hash of options that gets passed into Filter.new

(default: {}).

Returns nothing.



75
76
77
78
# File 'lib/outpost/list/base.rb', line 75

def filter(attribute, options={})
  filter = Filter.new(attribute, self, options)
  @filters[attribute] = filter
end