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
27 |
# File 'lib/active_admin/views/index_as_sortable.rb', line 27 def self.index_name; "sortable"; end |
Instance Method Details
#actions(options = {}, &block) ⇒ Object
Adds links to View, Edit and Delete
74 75 76 77 78 |
# File 'lib/active_admin/views/index_as_sortable.rb', line 74 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 25 |
# 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 = ActiveAdmin::SortableTree::Compatibility.normalized_resource_name(active_admin_config.resource_name) # 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.
43 44 45 |
# File 'lib/active_admin/views/index_as_sortable.rb', line 43 def default_roots_collection resource_class.send([:roots_method]) end |
#label(method = nil, &block) ⇒ Object
Setter method for the configuration of the label
66 67 68 69 70 71 |
# File 'lib/active_admin/views/index_as_sortable.rb', line 66 def label(method = nil, &block) if block_given? || method @label = block_given? ? block : method end @label end |
#options ⇒ Object
29 30 31 |
# File 'lib/active_admin/views/index_as_sortable.rb', line 29 def active_admin_config.dsl. end |
#roots ⇒ Object
33 34 35 |
# File 'lib/active_admin/views/index_as_sortable.rb', line 33 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.
55 56 57 58 59 |
# File 'lib/active_admin/views/index_as_sortable.rb', line 55 def roots_collection if (callable = [:roots_collection]) controller.instance_exec(&callable) end end |
#tree? ⇒ Boolean
61 62 63 |
# File 'lib/active_admin/views/index_as_sortable.rb', line 61 def tree? !![:tree] end |