Class: FlexiAdmin::Components::Resources::GridView::CardComponent

Inherits:
BaseComponent
  • Object
show all
Includes:
Helpers::LinkHelper
Defined in:
lib/flexi_admin/components/resources/grid_view/card_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::LinkHelper

#navigate_to

Constructor Details

#initialize(resource, title, header, description, image) ⇒ CardComponent

Returns a new instance of CardComponent.



9
10
11
12
13
14
15
# File 'lib/flexi_admin/components/resources/grid_view/card_component.rb', line 9

def initialize(resource, title, header, description, image)
  @resource = resource
  @title = title
  @header = header
  @description = description
  @image = image
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



7
8
9
# File 'lib/flexi_admin/components/resources/grid_view/card_component.rb', line 7

def description
  @description
end

#headerObject

Returns the value of attribute header.



7
8
9
# File 'lib/flexi_admin/components/resources/grid_view/card_component.rb', line 7

def header
  @header
end

#imageObject

Returns the value of attribute image.



7
8
9
# File 'lib/flexi_admin/components/resources/grid_view/card_component.rb', line 7

def image
  @image
end

#resourceObject

Returns the value of attribute resource.



7
8
9
# File 'lib/flexi_admin/components/resources/grid_view/card_component.rb', line 7

def resource
  @resource
end

#titleObject

Returns the value of attribute title.



7
8
9
# File 'lib/flexi_admin/components/resources/grid_view/card_component.rb', line 7

def title
  @title
end

Instance Method Details

#description_valueObject



59
60
61
62
63
# File 'lib/flexi_admin/components/resources/grid_view/card_component.rb', line 59

def description_value
  return unless description

  description.formatted_value(description.value[resource])
end

#header_valueObject



53
54
55
56
57
# File 'lib/flexi_admin/components/resources/grid_view/card_component.rb', line 53

def header_value
  return unless header

  header.formatted_value(header.value[resource])
end

#image_srcObject



21
22
23
24
25
26
# File 'lib/flexi_admin/components/resources/grid_view/card_component.rb', line 21

def image_src
  return unless image
  return if media_attachment.blank?

  image.src(media_attachment, variant: :thumb)
end

#media?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
# File 'lib/flexi_admin/components/resources/grid_view/card_component.rb', line 28

def media?
  return false unless image
  return false if media_attachment.blank?

  true
end

#media_attachmentObject



17
18
19
# File 'lib/flexi_admin/components/resources/grid_view/card_component.rb', line 17

def media_attachment
  @media_attachment ||= image.value[resource]
end

#render_mediaObject



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/flexi_admin/components/resources/grid_view/card_component.rb', line 35

def render_media
  case media_attachment.content_type.split("/").first
  when "image"
     :img, nil, src: image_src, style: "object-fit: cover; width: 100%; height: 180px;"
  when "video"
     :video, nil, src: image_src, style: "object-fit: cover; width: 100%; height: 180px;",
                             controls: true,
                             onmouseover: "this.play()",
                             onmouseout: "this.pause()"
  end
end

#title_valueObject



47
48
49
50
51
# File 'lib/flexi_admin/components/resources/grid_view/card_component.rb', line 47

def title_value
  return unless title

  title.formatted_value(title.value[resource])
end