Class: FlexiAdmin::Components::Resources::GridViewComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- FlexiAdmin::Components::Resources::GridViewComponent
- Includes:
- Helpers::LinkHelper, Helpers::ResourceHelper, Helpers::Selectable, Helpers::ValueFormatter
- Defined in:
- lib/flexi_admin/components/resources/grid_view_component.rb
Defined Under Namespace
Classes: Element
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#description_element ⇒ Object
Returns the value of attribute description_element.
-
#header_element ⇒ Object
Returns the value of attribute header_element.
-
#image_element ⇒ Object
Returns the value of attribute image_element.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
-
#title_element ⇒ Object
Returns the value of attribute title_element.
Instance Method Summary collapse
- #description(attribute, **options, &block) ⇒ Object
- #grid ⇒ Object
- #grid_view ⇒ Object
- #header(attribute, **options, &block) ⇒ Object
- #image(src_attribute, **options, &block) ⇒ Object
-
#initialize(context) ⇒ GridViewComponent
constructor
A new instance of GridViewComponent.
- #render? ⇒ Boolean
- #title(attribute, **options, &block) ⇒ Object
Methods included from Helpers::LinkHelper
Methods included from Helpers::Selectable
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
Methods included from Helpers::ValueFormatter
#as_date, #as_navigation, #as_text, #format
Constructor Details
#initialize(context) ⇒ GridViewComponent
Returns a new instance of GridViewComponent.
36 37 38 39 40 41 |
# File 'lib/flexi_admin/components/resources/grid_view_component.rb', line 36 def initialize(context) @context = context @resources = context.resources @is_selectable = false end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
33 34 35 |
# File 'lib/flexi_admin/components/resources/grid_view_component.rb', line 33 def context @context end |
#description_element ⇒ Object
Returns the value of attribute description_element.
34 35 36 |
# File 'lib/flexi_admin/components/resources/grid_view_component.rb', line 34 def description_element @description_element end |
#header_element ⇒ Object
Returns the value of attribute header_element.
34 35 36 |
# File 'lib/flexi_admin/components/resources/grid_view_component.rb', line 34 def header_element @header_element end |
#image_element ⇒ Object
Returns the value of attribute image_element.
34 35 36 |
# File 'lib/flexi_admin/components/resources/grid_view_component.rb', line 34 def image_element @image_element end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
33 34 35 |
# File 'lib/flexi_admin/components/resources/grid_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/grid_view_component.rb', line 33 def resources @resources end |
#title_element ⇒ Object
Returns the value of attribute title_element.
34 35 36 |
# File 'lib/flexi_admin/components/resources/grid_view_component.rb', line 34 def title_element @title_element end |
Instance Method Details
#description(attribute, **options, &block) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/flexi_admin/components/resources/grid_view_component.rb', line 82 def description(attribute, **, &block) value = block || proc { |resource| resource.send(attribute) } [:formatter] = format([:as] || :text) self.description_element = Element.new(attribute, value, ) end |
#grid ⇒ Object
51 52 53 54 55 |
# File 'lib/flexi_admin/components/resources/grid_view_component.rb', line 51 def grid render FlexiAdmin::Components::Resources::GridView::GridComponent.new(resources, title_element, header_element, description_element, image_element, context) end |
#grid_view ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/flexi_admin/components/resources/grid_view_component.rb', line 43 def grid_view yield grid rescue StandardError => e binding.pry if Rails.env.development? end |
#header(attribute, **options, &block) ⇒ Object
75 76 77 78 79 80 |
# File 'lib/flexi_admin/components/resources/grid_view_component.rb', line 75 def header(attribute, **, &block) value = block || proc { |resource| resource.send(attribute) } [:formatter] = format([:as] || :text) self.header_element = Element.new(attribute, value, ) end |
#image(src_attribute, **options, &block) ⇒ Object
62 63 64 65 66 |
# File 'lib/flexi_admin/components/resources/grid_view_component.rb', line 62 def image(src_attribute, **, &block) value = block || proc { |resource| resource.send(src_attribute) } self.image_element = Element.new(src_attribute, value, , main_app) end |
#render? ⇒ Boolean
57 58 59 60 |
# File 'lib/flexi_admin/components/resources/grid_view_component.rb', line 57 def render? context.params.current_view == "grid" || (context.views.first == "grid" && context.params.current_view.blank?) end |
#title(attribute, **options, &block) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/flexi_admin/components/resources/grid_view_component.rb', line 68 def title(attribute, **, &block) value = block || proc { |resource| resource.send(attribute) } [:formatter] = format([:as] || :text) self.title_element = Element.new(attribute, value, ) end |