Class: Avo::Fields::HasBaseField

Inherits:
BaseField show all
Defined in:
lib/avo/fields/has_base_field.rb

Instance Attribute Summary collapse

Attributes inherited from BaseField

#action, #as_avatar, #as_description, #as_label, #block, #computable, #computed, #computed_value, #default, #format_using, #help, #id, #model, #null_values, #nullable, #panel_name, #readonly, #required, #sortable, #updatable, #user, #view, #visible

Attributes included from FieldExtensions::VisibleInDifferentViews

#show_on_edit, #show_on_index, #show_on_new, #show_on_show

Instance Method Summary collapse

Methods inherited from BaseField

#component_for_view, #custom?, #database_id, #fill_field, #has_own_panel?, #hydrate, #model_errors, #name, #placeholder, #resolve_attribute, #to_permitted_param, #translation_key, #type, #value, #view_component_name, #visible?

Methods included from FieldExtensions::HasFieldName

#field_name, #get_field_name

Methods included from FieldExtensions::VisibleInDifferentViews

#except_on, #hide_on, #only_on, #show_on

Constructor Details

#initialize(id, **args, &block) ⇒ HasBaseField

Returns a new instance of HasBaseField.



6
7
8
9
10
# File 'lib/avo/fields/has_base_field.rb', line 6

def initialize(id, **args, &block)
  super(id, **args, &block)

  @display = args[:display].present? ? args[:display] : :show
end

Instance Attribute Details

#displayObject

Returns the value of attribute display.



4
5
6
# File 'lib/avo/fields/has_base_field.rb', line 4

def display
  @display
end

Instance Method Details

#frame_urlObject



20
21
22
# File 'lib/avo/fields/has_base_field.rb', line 20

def frame_url
  "#{@resource.record_path}/#{id}?turbo_frame=#{turbo_frame}"
end

#resourceObject



12
13
14
# File 'lib/avo/fields/has_base_field.rb', line 12

def resource
  Avo::App.get_resource_by_model_name @model.class
end

#target_resourceObject



24
25
26
27
28
29
30
31
32
# File 'lib/avo/fields/has_base_field.rb', line 24

def target_resource
  if @model._reflections[id.to_s].klass.present?
    Avo::App.get_resource_by_model_name @model._reflections[id.to_s].klass.to_s
  elsif @model._reflections[id.to_s].options[:class_name].present?
    Avo::App.get_resource_by_model_name @model._reflections[id.to_s].options[:class_name]
  else
    Avo::App.get_resource_by_name id.to_s
  end
end

#turbo_frameObject



16
17
18
# File 'lib/avo/fields/has_base_field.rb', line 16

def turbo_frame
  "#{self.class.name.demodulize.to_s.underscore}_#{display}_#{id}"
end