Class: Avo::Fields::HasBaseField
- Includes:
- Concerns::IsSearchable, Concerns::LinkableTitle, Concerns::ReloadIcon, Concerns::UseResource
- Defined in:
- lib/avo/fields/has_base_field.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attach_fields ⇒ Object
readonly
Returns the value of attribute attach_fields.
-
#attach_scope ⇒ Object
Returns the value of attribute attach_scope.
-
#description ⇒ Object
Returns the value of attribute description.
-
#discreet_pagination ⇒ Object
Returns the value of attribute discreet_pagination.
-
#display ⇒ Object
Returns the value of attribute display.
-
#hide_search_input ⇒ Object
Returns the value of attribute hide_search_input.
-
#link_to_child_resource ⇒ Object
readonly
Returns the value of attribute link_to_child_resource.
-
#scope ⇒ Object
Returns the value of attribute scope.
Attributes inherited from BaseField
#action, #as_avatar, #autocomplete, #block, #computable, #computed, #computed_value, #default, #for_attribute, #for_presentation_only, #format_using, #help, #id, #null_values, #nullable, #panel_name, #readonly, #record, #required, #sortable, #stacked, #summarizable, #user
Attributes included from Concerns::IsDisabled
Attributes included from Concerns::HasHTMLAttributes
Attributes included from Concerns::VisibleInDifferentViews
#show_on_edit, #show_on_index, #show_on_new, #show_on_preview, #show_on_show
Attributes included from Concerns::IsVisible
Attributes included from Concerns::IsResourceItem
Instance Method Summary collapse
- #association_name ⇒ Object
- #authorized? ⇒ Boolean
-
#component_for_view(view = Avo::ViewInquirer.new("index")) ⇒ Object
Adds the view override component has_one, has_many, has_and_belongs_to_many fields don’t have edit views.
- #default_name ⇒ Object
-
#field_label ⇒ Object
What the user sees in the text field.
- #field_resource ⇒ Object
-
#field_value ⇒ Object
The value.
- #frame_url(add_turbo_frame: true) ⇒ Object
- #has_own_panel? ⇒ Boolean
-
#initialize(id, **args, &block) ⇒ HasBaseField
constructor
A new instance of HasBaseField.
- #placeholder ⇒ Object
- #query_params(add_turbo_frame: true) ⇒ Object
- #target_resource ⇒ Object
- #turbo_frame ⇒ Object
- #visible_in_reflection? ⇒ Boolean
Methods included from Concerns::LinkableTitle
Methods included from Concerns::ReloadIcon
Methods included from Concerns::UseResource
Methods included from Concerns::IsSearchable
Methods inherited from BaseField
#apply_update_using, #assign_value, #custom?, #custom_name?, #database_id, #execute_block, #fill_field, #form_field_label, #has_attribute?, #hidden_in_reflection?, #meta, #name, #options_for_filter, #plural_name, #record_errors, #resolve_attribute, #table_header_label, #to_permitted_param, #translated_name, #translated_plural_name, #translation_key, #type, #updatable, #value
Methods included from Concerns::UseViewComponents
#view_component_name, #view_component_namespace
Methods included from Concerns::IsRequired
Methods included from Concerns::IsDisabled
Methods included from Concerns::IsReadonly
Methods included from Concerns::HasHTMLAttributes
Methods included from Concerns::HasDefault
Methods included from Concerns::HasHelpers
Methods included from Concerns::VisibleInDifferentViews
#except_on, #hide_on, #initialize_views, #only_on, #post_initialize, #show_on, #show_on_create, #show_on_update, #visible_in_view?
Methods included from Concerns::IsVisible
Methods included from Concerns::HasItemType
#is_field?, #is_heading?, #is_main_panel?, #is_panel?, #is_row?, #is_sidebar?, #is_tab?, #is_tab_group?, #is_tool?
Methods included from Concerns::IsResourceItem
Methods included from Concerns::Hydration
Constructor Details
#initialize(id, **args, &block) ⇒ HasBaseField
Returns a new instance of HasBaseField.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/avo/fields/has_base_field.rb', line 18 def initialize(id, **args, &block) super(id, **args, &block) @scope = args[:scope].present? ? args[:scope] : nil @attach_scope = args[:attach_scope].present? ? args[:attach_scope] : nil @display = args[:display].present? ? args[:display] : :show @searchable = args[:searchable] == true @hide_search_input = args[:hide_search_input] || false @description = args[:description] @use_resource = args[:use_resource] || nil @discreet_pagination = args[:discreet_pagination] || false # Defaults to nil so that if not set falls back to `link_to_child_resource` defined in the resource @link_to_child_resource = args[:link_to_child_resource] @reloadable = args[:reloadable].present? ? args[:reloadable] : false @linkable = args[:linkable].present? ? args[:linkable] : false @attach_fields = args[:attach_fields] end |
Instance Attribute Details
#attach_fields ⇒ Object (readonly)
Returns the value of attribute attach_fields.
16 17 18 |
# File 'lib/avo/fields/has_base_field.rb', line 16 def attach_fields @attach_fields end |
#attach_scope ⇒ Object
Returns the value of attribute attach_scope.
11 12 13 |
# File 'lib/avo/fields/has_base_field.rb', line 11 def attach_scope @attach_scope end |
#description ⇒ Object
Returns the value of attribute description.
12 13 14 |
# File 'lib/avo/fields/has_base_field.rb', line 12 def description @description end |
#discreet_pagination ⇒ Object
Returns the value of attribute discreet_pagination.
13 14 15 |
# File 'lib/avo/fields/has_base_field.rb', line 13 def discreet_pagination @discreet_pagination end |
#display ⇒ Object
Returns the value of attribute display.
9 10 11 |
# File 'lib/avo/fields/has_base_field.rb', line 9 def display @display end |
#hide_search_input ⇒ Object
Returns the value of attribute hide_search_input.
14 15 16 |
# File 'lib/avo/fields/has_base_field.rb', line 14 def hide_search_input @hide_search_input end |
#link_to_child_resource ⇒ Object (readonly)
Returns the value of attribute link_to_child_resource.
15 16 17 |
# File 'lib/avo/fields/has_base_field.rb', line 15 def link_to_child_resource @link_to_child_resource end |
#scope ⇒ Object
Returns the value of attribute scope.
10 11 12 |
# File 'lib/avo/fields/has_base_field.rb', line 10 def scope @scope end |
Instance Method Details
#association_name ⇒ Object
113 114 115 |
# File 'lib/avo/fields/has_base_field.rb', line 113 def association_name @association_name ||= (@for_attribute || id).to_s end |
#authorized? ⇒ Boolean
96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/avo/fields/has_base_field.rb', line 96 def return true unless Avo.configuration. method = :"view_#{id}?" service = field_resource. if service.has_method? method service.(method, raise_exception: false) else !Avo.configuration. end end |
#component_for_view(view = Avo::ViewInquirer.new("index")) ⇒ Object
Adds the view override component has_one, has_many, has_and_belongs_to_many fields don’t have edit views
90 91 92 93 94 |
# File 'lib/avo/fields/has_base_field.rb', line 90 def component_for_view(view = Avo::ViewInquirer.new("index")) view = Avo::ViewInquirer.new("show") if view.in? %w[new create update edit] super(view) end |
#default_name ⇒ Object
109 110 111 |
# File 'lib/avo/fields/has_base_field.rb', line 109 def default_name use_resource&.name || super end |
#field_label ⇒ Object
What the user sees in the text field
58 59 60 61 62 |
# File 'lib/avo/fields/has_base_field.rb', line 58 def field_label target_resource.new(record: value, view: view, user: user).record_title rescue nil end |
#field_resource ⇒ Object
35 36 37 |
# File 'lib/avo/fields/has_base_field.rb', line 35 def field_resource resource || get_resource_by_model_class(@record.class) end |
#field_value ⇒ Object
The value
51 52 53 54 55 |
# File 'lib/avo/fields/has_base_field.rb', line 51 def field_value value.send(database_value) rescue nil end |
#frame_url(add_turbo_frame: true) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/avo/fields/has_base_field.rb', line 43 def frame_url(add_turbo_frame: true) Avo::Services::URIService.parse(field_resource.record_path) .append_path(id.to_s) .append_query(query_params(add_turbo_frame:)) .to_s end |
#has_own_panel? ⇒ Boolean
80 81 82 |
# File 'lib/avo/fields/has_base_field.rb', line 80 def has_own_panel? true end |
#placeholder ⇒ Object
76 77 78 |
# File 'lib/avo/fields/has_base_field.rb', line 76 def placeholder @placeholder || I18n.t("avo.choose_an_option") end |
#query_params(add_turbo_frame: true) ⇒ Object
117 118 119 120 121 122 123 |
# File 'lib/avo/fields/has_base_field.rb', line 117 def query_params(add_turbo_frame: true) { view:, for_attribute: @for_attribute, turbo_frame: add_turbo_frame ? turbo_frame : nil }.compact end |
#target_resource ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/avo/fields/has_base_field.rb', line 64 def target_resource reflection = @record.class.reflect_on_association(association_name) if reflection.klass.present? get_resource_by_model_class(reflection.klass.to_s) elsif reflection.[:class_name].present? get_resource_by_model_class(reflection.[:class_name]) else Avo.resource_manager.get_resource_by_name association_name end end |
#turbo_frame ⇒ Object
39 40 41 |
# File 'lib/avo/fields/has_base_field.rb', line 39 def turbo_frame "#{self.class.name.demodulize.to_s.underscore}_#{display}_#{frame_id}" end |
#visible_in_reflection? ⇒ Boolean
84 85 86 |
# File 'lib/avo/fields/has_base_field.rb', line 84 def visible_in_reflection? false end |