Class: ActiveAdmin::Views::IndexAsSortable
- Inherits:
-
Component
- Object
- Component
- ActiveAdmin::Views::IndexAsSortable
- Defined in:
- lib/active_admin/views/index_as_sortable.rb
Overview
Index as a Sortable List or Tree
Class Method Summary collapse
Instance Method Summary collapse
-
#actions(options = {}, &block) ⇒ Object
Adds links to View, Edit and Delete.
- #build(page_presenter, collection) ⇒ Object
-
#default_roots_collection ⇒ Object
Find the roots by calling the roots method directly on the resource.
-
#label(method = nil, &block) ⇒ Object
Setter method for the configuration of the label.
- #options ⇒ Object
- #roots ⇒ Object
-
#roots_collection ⇒ Object
Use user-defined logic to find the root nodes.
- #tree? ⇒ Boolean
Class Method Details
.index_name ⇒ Object
26 |
# File 'lib/active_admin/views/index_as_sortable.rb', line 26 def self.index_name; "sortable"; end |
Instance Method Details
#actions(options = {}, &block) ⇒ Object
Adds links to View, Edit and Delete
73 74 75 76 77 |
# File 'lib/active_admin/views/index_as_sortable.rb', line 73 def actions( = {}, &block) = { :defaults => true }.merge() @default_actions = [:defaults] @other_actions = block end |
#build(page_presenter, collection) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/active_admin/views/index_as_sortable.rb', line 6 def build(page_presenter, collection) @page_presenter = page_presenter @collection = if tree? roots else collection end @collection = @collection.sort_by do |a| a.send([:sorting_attribute]) || 1 end @resource_name = active_admin_config.resource_name.to_s.underscore.parameterize('_') # Call the block passed in. This will set the # title and body methods instance_eval &page_presenter.block if page_presenter.block add_class "index" build_list end |
#default_roots_collection ⇒ Object
Find the roots by calling the roots method directly on the resource. This effectively performs:
TreeNode.roots # => [#<TreeNode id:1>, ... ]
Returns collection of roots.
42 43 44 |
# File 'lib/active_admin/views/index_as_sortable.rb', line 42 def default_roots_collection resource_class.send([:roots_method]) end |
#label(method = nil, &block) ⇒ Object
Setter method for the configuration of the label
65 66 67 68 69 70 |
# File 'lib/active_admin/views/index_as_sortable.rb', line 65 def label(method = nil, &block) if block_given? || method @label = block_given? ? block : method end @label end |
#options ⇒ Object
28 29 30 |
# File 'lib/active_admin/views/index_as_sortable.rb', line 28 def active_admin_config.dsl. end |
#roots ⇒ Object
32 33 34 |
# File 'lib/active_admin/views/index_as_sortable.rb', line 32 def roots roots_collection || default_roots_collection end |
#roots_collection ⇒ Object
Use user-defined logic to find the root nodes. This executes a callable object within the context of the resource’s controller.
Example
[:roots_collection] = proc { current_user.tree_nodes.roots }
Returns collection of roots.
54 55 56 57 58 |
# File 'lib/active_admin/views/index_as_sortable.rb', line 54 def roots_collection if (callable = [:roots_collection]) controller.instance_exec(&callable) end end |
#tree? ⇒ Boolean
60 61 62 |
# File 'lib/active_admin/views/index_as_sortable.rb', line 60 def tree? !![:tree] end |