Class: Outpost::List::Base
- Inherits:
-
Object
- Object
- Outpost::List::Base
- Defined in:
- lib/outpost/list/base.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#default_order_attribute ⇒ Object
Returns the value of attribute default_order_attribute.
-
#default_order_direction ⇒ Object
Returns the value of attribute default_order_direction.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#per_page ⇒ Object
Returns the value of attribute per_page.
Instance Method Summary collapse
-
#column(attribute, options = {}) ⇒ Object
Public: Add a column to the list.
-
#default_columns ⇒ Object
Private: Default columns for this list.
-
#filter(attribute, options = {}) ⇒ Object
Public: Define a filter for the list.
-
#initialize(model) {|_self| ... } ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(model) {|_self| ... } ⇒ Base
Returns a new instance of Base.
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
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
22 23 24 |
# File 'lib/outpost/list/base.rb', line 22 def columns @columns end |
#default_order_attribute ⇒ Object
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_direction ⇒ Object
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 |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
22 23 24 |
# File 'lib/outpost/list/base.rb', line 22 def fields @fields end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
22 23 24 |
# File 'lib/outpost/list/base.rb', line 22 def filters @filters end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
22 23 24 |
# File 'lib/outpost/list/base.rb', line 22 def model @model end |
#per_page ⇒ Object
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, ={}) column = Column.new(attribute, self, ) @columns[attribute] = column end |
#default_columns ⇒ Object
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, ={}) filter = Filter.new(attribute, self, ) @filters[attribute] = filter end |