Class: FlexiAdmin::Components::Resources::ListViewComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- FlexiAdmin::Components::Resources::ListViewComponent
- Includes:
- Helpers::LinkHelper, Helpers::ResourceHelper, Helpers::Selectable, Helpers::ValueFormatter
- Defined in:
- lib/flexi_admin/components/resources/list_view_component.rb
Defined Under Namespace
Classes: Column
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
Instance Method Summary collapse
- #as_date(value, format: nil) ⇒ Object
- #as_text(value) ⇒ Object
- #build_column(attribute, options, &block) ⇒ Object
- #column(attribute, options = {}, &block) ⇒ Object
-
#initialize(context) ⇒ ListViewComponent
constructor
A new instance of ListViewComponent.
- #list_view ⇒ Object
- #render? ⇒ Boolean
- #table ⇒ Object
Methods included from Helpers::LinkHelper
Methods included from Helpers::Selectable
Methods included from Helpers::ValueFormatter
Methods included from Helpers::ResourceHelper
#autocomplete_path, #bulk_action_path, #datalist_path, #edit_resource_path, #paginate, #resource__path, #resource_input_name, #resource_path, #resources_path, #scope, #scope_plural, #scope_singular
Constructor Details
#initialize(context) ⇒ ListViewComponent
Returns a new instance of ListViewComponent.
35 36 37 38 39 40 41 |
# File 'lib/flexi_admin/components/resources/list_view_component.rb', line 35 def initialize(context) @context = context @resources = context.resources @columns = [] @headers = [] @is_selectable = false end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
33 34 35 |
# File 'lib/flexi_admin/components/resources/list_view_component.rb', line 33 def columns @columns end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
33 34 35 |
# File 'lib/flexi_admin/components/resources/list_view_component.rb', line 33 def context @context end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
33 34 35 |
# File 'lib/flexi_admin/components/resources/list_view_component.rb', line 33 def resource @resource end |
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
33 34 35 |
# File 'lib/flexi_admin/components/resources/list_view_component.rb', line 33 def resources @resources end |
Instance Method Details
#as_date(value, format: nil) ⇒ Object
52 53 54 55 56 |
# File 'lib/flexi_admin/components/resources/list_view_component.rb', line 52 def as_date(value, format: nil) return if value.blank? I18n.l(value, format:) end |
#as_text(value) ⇒ Object
48 49 50 |
# File 'lib/flexi_admin/components/resources/list_view_component.rb', line 48 def as_text(value) value.to_s end |
#build_column(attribute, options, &block) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/flexi_admin/components/resources/list_view_component.rb', line 72 def build_column(attribute, , &block) [:formatter] = format([:as] || :text) Column.new(attribute, block || proc { |resource| resource.send(attribute) }, .presence || {}) end |
#column(attribute, options = {}, &block) ⇒ Object
68 69 70 |
# File 'lib/flexi_admin/components/resources/list_view_component.rb', line 68 def column(attribute, = {}, &block) @columns << build_column(attribute, , &block) end |
#list_view ⇒ Object
58 59 60 61 62 |
# File 'lib/flexi_admin/components/resources/list_view_component.rb', line 58 def list_view yield table end |
#render? ⇒ Boolean
43 44 45 46 |
# File 'lib/flexi_admin/components/resources/list_view_component.rb', line 43 def render? context.params.current_view == 'list' || (context.views.first == 'list' && context.params.current_view.blank?) end |
#table ⇒ Object
64 65 66 |
# File 'lib/flexi_admin/components/resources/list_view_component.rb', line 64 def table render FlexiAdmin::Components::Resources::ListView::TableComponent.new(headers, columns, resources, context, selectable: true) end |