Class: Avo::Fields::ShowComponent

Inherits:
BaseComponent
  • Object
show all
Includes:
ResourcesHelper
Defined in:
app/components/avo/fields/show_component.rb

Constant Summary

Constants included from Concerns::FindAssociationField

Concerns::FindAssociationField::ASSOCIATIONS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ResourcesHelper

#field_wrapper, #filter_wrapper, #index_field_wrapper, #item_selector_data_attributes, #record_path, #record_title, #resource_for_record, #resource_grid, #resource_show_path, #resource_table

Methods inherited from BaseComponent

#component_name

Methods included from ApplicationHelper

#a_button, #a_link, #body_classes, #button_classes, #chart_color, #container_classes, #d, #decode_filter_params, #e, #editor_file_path, #editor_url, #empty_state, #encode_filter_params, #frame_id, #get_model_class, #input_classes, #mount_path, #number_to_social, #possibly_rails_authentication?, #render_license_warning, #root_path_without_url, #rtl?, #text_direction, #ui, #wrap_in_modal

Methods included from Concerns::FindAssociationField

#find_association_field

Constructor Details

#initialize(field: nil, resource: nil, index: 0, form: nil, stacked: nil, full_width: nil, **kwargs) ⇒ ShowComponent

Returns a new instance of ShowComponent.



14
15
16
17
18
19
20
21
22
# File 'app/components/avo/fields/show_component.rb', line 14

def initialize(field: nil, resource: nil, index: 0, form: nil, stacked: nil, full_width: nil, **kwargs)
  @field = field
  @index = index
  @resource = resource
  @stacked = stacked
  @kwargs = kwargs
  @view = Avo::ViewInquirer.new("show")
  @full_width = full_width
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



6
7
8
# File 'app/components/avo/fields/show_component.rb', line 6

def field
  @field
end

#full_widthObject (readonly)

Returns the value of attribute full_width.



12
13
14
# File 'app/components/avo/fields/show_component.rb', line 12

def full_width
  @full_width
end

#indexObject (readonly)

Returns the value of attribute index.



7
8
9
# File 'app/components/avo/fields/show_component.rb', line 7

def index
  @index
end

#kwargsObject (readonly)

Returns the value of attribute kwargs.



8
9
10
# File 'app/components/avo/fields/show_component.rb', line 8

def kwargs
  @kwargs
end

#resourceObject (readonly)

Returns the value of attribute resource.



9
10
11
# File 'app/components/avo/fields/show_component.rb', line 9

def resource
  @resource
end

#stackedObject (readonly)

Returns the value of attribute stacked.



10
11
12
# File 'app/components/avo/fields/show_component.rb', line 10

def stacked
  @stacked
end

#viewObject (readonly)

Returns the value of attribute view.



11
12
13
# File 'app/components/avo/fields/show_component.rb', line 11

def view
  @view
end

Instance Method Details

#disabled?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'app/components/avo/fields/show_component.rb', line 58

def disabled?
  field.is_readonly? || field.is_disabled?
end

#field_wrapper_argsObject



47
48
49
50
51
52
53
54
55
56
# File 'app/components/avo/fields/show_component.rb', line 47

def field_wrapper_args
  {
    field: field,
    index: index,
    resource: resource,
    stacked: stacked,
    full_width: full_width,
    view: view
  }
end

#stimulus_attributesObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/components/avo/fields/show_component.rb', line 30

def stimulus_attributes
  attributes = {}

  if @resource.present?
    @resource.get_stimulus_controllers.split(" ").each do |controller|
      attributes["#{controller}-target"] = "#{@field.id.to_s.underscore}_#{@field.type.to_s.underscore}_wrapper".camelize(:lower)
    end
  end

  wrapper_data_attributes = @field.get_html :data, view: view, element: :wrapper
  if wrapper_data_attributes.present?
    attributes.merge! wrapper_data_attributes
  end

  attributes
end

#wrapper_dataObject



24
25
26
27
28
# File 'app/components/avo/fields/show_component.rb', line 24

def wrapper_data
  {
    **stimulus_attributes
  }
end