Class: EasyAdmin::Fields::BaseComponent

Inherits:
Phlex::HTML
  • Object
show all
Includes:
ActionView::Helpers::DateHelper, ActionView::Helpers::NumberHelper, ActionView::Helpers::TextHelper, ActionView::Helpers::UrlHelper, DashboardsHelper, EasyAdmin::FieldsHelper
Defined in:
app/components/easy_admin/fields/base_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from EasyAdmin::FieldsHelper

#field_component, #render_field

Methods included from DashboardsHelper

#delta_badge_classes, #metric_value_classes, #render_card, #sparkline_color, #sparkline_points, #trend_direction, #trend_icon, #trend_indicator_classes

Constructor Details

#initialize(field:, value: nil, record: nil, form: nil, **options) ⇒ BaseComponent

Returns a new instance of BaseComponent.



38
39
40
41
42
43
44
# File 'app/components/easy_admin/fields/base_component.rb', line 38

def initialize(field:, value: nil, record: nil, form: nil, **options)
  @field = field
  @value = value
  @record = record
  @form = form
  @options = options
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



36
37
38
# File 'app/components/easy_admin/fields/base_component.rb', line 36

def field
  @field
end

#formObject (readonly)

Returns the value of attribute form.



36
37
38
# File 'app/components/easy_admin/fields/base_component.rb', line 36

def form
  @form
end

#recordObject (readonly)

Returns the value of attribute record.



36
37
38
# File 'app/components/easy_admin/fields/base_component.rb', line 36

def record
  @record
end

#valueObject (readonly)

Returns the value of attribute value.



36
37
38
# File 'app/components/easy_admin/fields/base_component.rb', line 36

def value
  @value
end

Instance Method Details

#easy_admin_url_helpersObject

Direct access to EasyAdmin URL helpers



27
28
29
# File 'app/components/easy_admin/fields/base_component.rb', line 27

def easy_admin_url_helpers
  @easy_admin_url_helpers ||= EasyAdmin::Engine.routes.url_helpers
end

#helpersObject

Add method to access all Rails helpers if needed



18
19
20
21
22
23
24
# File 'app/components/easy_admin/fields/base_component.rb', line 18

def helpers
  @helpers ||= Class.new do
    include ActionView::Helpers
    include Rails.application.routes.url_helpers
    include EasyAdmin::Engine.routes.url_helpers
  end.new
end

#rails_url_helpersObject

Direct access to Rails URL helpers



32
33
34
# File 'app/components/easy_admin/fields/base_component.rb', line 32

def rails_url_helpers
  @rails_url_helpers ||= Rails.application.routes.url_helpers
end

#view_templateObject



46
47
48
# File 'app/components/easy_admin/fields/base_component.rb', line 46

def view_template
  # Override this in subclasses
end