Class: Avo::Fields::Common::Files::ListViewerComponent

Inherits:
BaseComponent
  • Object
show all
Includes:
Turbo::FramesHelper
Defined in:
app/components/avo/fields/common/files/list_viewer_component.rb

Instance Method Summary collapse

Instance Method Details

#after_initializeObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/components/avo/fields/common/files/list_viewer_component.rb', line 9

def after_initialize
  @available_view_types = [:list, :grid]

  params_view_type = @resource.params.dig(:view_type)&.to_sym

  @view_type = if params_view_type.in?(@available_view_types)
    params_view_type
  else
    @field.view_type
  end

  @component_class = "Avo::Fields::Common::Files::ViewType::#{@view_type.to_s.capitalize}ItemComponent".constantize
end

#view_type_component(file) ⇒ Object



23
24
25
# File 'app/components/avo/fields/common/files/list_viewer_component.rb', line 23

def view_type_component(file)
  @component_class.new(field: @field, resource: @resource, file: file, extra_classes: "aspect-video")
end