Class: Avo::Fields::ShowComponent

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ResourcesHelper

#field_wrapper, #filter_wrapper, #index_field_wrapper, #item_select_all_input, #item_selector_init, #item_selector_input, #resource_grid, #resource_table

Constructor Details

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

Returns a new instance of ShowComponent.



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

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

Instance Attribute Details

#compactObject (readonly)

Returns the value of attribute compact.



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

def compact
  @compact
end

#fieldObject (readonly)

Returns the value of attribute field.



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

def field
  @field
end

#indexObject (readonly)

Returns the value of attribute index.



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

def index
  @index
end

#kwargsObject (readonly)

Returns the value of attribute kwargs.



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

def kwargs
  @kwargs
end

#resourceObject (readonly)

Returns the value of attribute resource.



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

def resource
  @resource
end

#shortObject (readonly)

Returns the value of attribute short.



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

def short
  @short
end

#stackedObject (readonly)

Returns the value of attribute stacked.



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

def stacked
  @stacked
end

#viewObject (readonly)

Returns the value of attribute view.



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

def view
  @view
end

Instance Method Details

#disabled?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'app/components/avo/fields/show_component.rb', line 61

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

#field_wrapper_argsObject



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

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

#stimulus_attributesObject



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

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



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

def wrapper_data
  {
    **stimulus_attributes
  }
end