Class: ActiveElement::Components::CollectionTable
- Inherits:
-
Object
- Object
- ActiveElement::Components::CollectionTable
- Includes:
- LinkHelpers, SecretFields, Translations
- Defined in:
- lib/active_element/components/collection_table.rb
Overview
A table component for rendering a collection of data.
Constant Summary collapse
- DEFAULT_PAGE_SIZE =
50
Constants included from SecretFields
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#model_name ⇒ Object
readonly
Returns the value of attribute model_name.
Instance Method Summary collapse
- #grouped_collection ⇒ Object
-
#initialize(controller, class_name:, collection:, fields:, params:, model_name: nil, style: nil, show: false, new: false, edit: false, destroy: false, paginate: true, group: nil, group_title: false, nested_for: nil, row_class: nil, title: nil, footer_pagination: nil, **_kwargs) ⇒ CollectionTable
constructor
rubocop:disable Metrics/MethodLength.
-
#locals ⇒ Object
rubocop:disable Metrics/MethodLength, Metrics/AbcSize.
- #model ⇒ Object
-
#template ⇒ Object
rubocop:enable Metrics/MethodLength.
Methods included from Translations
Methods included from SecretFields
Constructor Details
#initialize(controller, class_name:, collection:, fields:, params:, model_name: nil, style: nil, show: false, new: false, edit: false, destroy: false, paginate: true, group: nil, group_title: false, nested_for: nil, row_class: nil, title: nil, footer_pagination: nil, **_kwargs) ⇒ CollectionTable
rubocop:disable Metrics/MethodLength
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/active_element/components/collection_table.rb', line 16 def initialize(controller, class_name:, collection:, fields:, params:, model_name: nil, style: nil, show: false, new: false, edit: false, destroy: false, paginate: true, group: nil, group_title: false, nested_for: nil, row_class: nil, title: nil, footer_pagination: nil, **_kwargs) @controller = controller @class_name = class_name @model_name = model_name @fields = fields @collection = with_includes(collection) || [] @style = style @params = params @show = show @new = new @edit = edit @destroy = destroy @paginate = paginate @group = group @group_title = group_title @row_class = row_class @title = title @nested_for = nested_for verify_paginate_and_group @footer_pagination = end |
Instance Attribute Details
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
13 14 15 |
# File 'lib/active_element/components/collection_table.rb', line 13 def controller @controller end |
#model_name ⇒ Object (readonly)
Returns the value of attribute model_name.
13 14 15 |
# File 'lib/active_element/components/collection_table.rb', line 13 def model_name @model_name end |
Instance Method Details
#grouped_collection ⇒ Object
75 76 77 78 79 |
# File 'lib/active_element/components/collection_table.rb', line 75 def grouped_collection collection.group_by do |item| item.class.is_a?(ActiveModel::Naming) ? item.public_send(group) : item.fetch(group) end end |
#locals ⇒ Object
rubocop:disable Metrics/MethodLength, Metrics/AbcSize
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/active_element/components/collection_table.rb', line 45 def locals # rubocop:disable Metrics/MethodLength, Metrics/AbcSize { component: self, class_name: class_name, title: title, collection: group ? collection : paginated_collection, fields: Util::FieldMapping.new(self, fields, class_name).mapped_fields, style: style, new: new, show: show, edit: edit, destroy: destroy, group: group, group_title: group_title, nested_for: nested_for, display_pagination: display_pagination?, page_sizes: [5, 10, 25, 50, 75, 100, 200], page_size: page_size, i18n: i18n, row_class_mapper: row_class_mapper, footer_pagination: @footer_pagination && display_pagination? } end |
#model ⇒ Object
69 70 71 72 73 |
# File 'lib/active_element/components/collection_table.rb', line 69 def model return collection.model if collection.is_a?(ActiveRecord::Relation) collection&.first.class.is_a?(ActiveModel::Naming) ? collection.first.class : nil end |
#template ⇒ Object
rubocop:enable Metrics/MethodLength
41 42 43 |
# File 'lib/active_element/components/collection_table.rb', line 41 def template 'active_element/components/table/collection' end |