Class: FlexiAdmin::Components::Resources::GridViewComponent

Inherits:
BaseComponent
  • Object
show all
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

Instance Method Summary collapse

Methods included from Helpers::LinkHelper

#navigate_to

Methods included from Helpers::Selectable

#selectable, #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

#contextObject (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_elementObject

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_elementObject

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_elementObject

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

#resourceObject (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

#resourcesObject (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_elementObject

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, **options, &block)
  value = block || proc { |resource| resource.send(attribute) }
  options[:formatter] = format(options[:as] || :text)

  self.description_element = Element.new(attribute, value, options)
end

#gridObject



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_viewObject



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, **options, &block)
  value = block || proc { |resource| resource.send(attribute) }
  options[:formatter] = format(options[:as] || :text)

  self.header_element = Element.new(attribute, value, options)
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, **options, &block)
  value = block || proc { |resource| resource.send(src_attribute) }

  self.image_element = Element.new(src_attribute, value, options, main_app)
end

#render?Boolean

Returns:

  • (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, **options, &block)
  value = block || proc { |resource| resource.send(attribute) }
  options[:formatter] = format(options[:as] || :text)

  self.title_element = Element.new(attribute, value, options)
end