Class: Avo::Fields::FrameBaseField
Instance Attribute Summary
Attributes inherited from BaseField
#action, #as_avatar, #autocomplete, #block, #computable, #computed, #computed_value, #copyable, #default, #for_attribute, #for_presentation_only, #format_using, #help, #id, #null_values, #nullable, #panel_name, #readonly, #record, #required, #sortable, #stacked, #summarizable, #user
#disabled
#html
#show_on_edit, #show_on_index, #show_on_new, #show_on_preview, #show_on_show
#visible
#resource, #view
Instance Method Summary
collapse
#description
#linkable?
#reloadable?
#use_resource
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
#view_component_name, #view_component_namespace
#is_required?
#is_disabled?
#is_readonly?
#get_html
#computed_default_value
#helpers
#except_on, #hide_on, #initialize_views, #only_on, #post_initialize, #show_on, #show_on_create, #show_on_update, #visible_in_view?
#visible?
#is_field?, #is_heading?, #is_main_panel?, #is_panel?, #is_row?, #is_sidebar?, #is_tab?, #is_tab_group?, #is_tool?
#visible?
#hydrate
Constructor Details
#initialize(id, **args, &block) ⇒ FrameBaseField
Returns a new instance of FrameBaseField.
9
10
11
12
13
14
15
16
|
# File 'lib/avo/fields/frame_base_field.rb', line 9
def initialize(id, **args, &block)
super(id, **args, &block)
@use_resource = args[:use_resource]
@reloadable = args[:reloadable]
@linkable = args[:linkable]
@description = args[:description]
end
|
Instance Method Details
#association_name ⇒ Object
96
97
98
|
# File 'lib/avo/fields/frame_base_field.rb', line 96
def association_name
@association_name ||= (@for_attribute || id).to_s
end
|
#authorized? ⇒ Boolean
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/avo/fields/frame_base_field.rb', line 79
def authorized?
return true unless Avo.configuration.authorization_enabled?
method = :"view_#{id}?"
service = field_resource.authorization
if service.has_method? method
service.authorize_action(method, raise_exception: false)
else
!Avo.configuration.explicit_authorization
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
73
74
75
76
77
|
# File 'lib/avo/fields/frame_base_field.rb', line 73
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
92
93
94
|
# File 'lib/avo/fields/frame_base_field.rb', line 92
def default_name
use_resource&.name || super
end
|
#field_label ⇒ Object
What the user sees in the text field
41
42
43
44
45
|
# File 'lib/avo/fields/frame_base_field.rb', line 41
def field_label
target_resource.new(record: value, view: view, user: user).record_title
rescue
nil
end
|
#field_resource ⇒ Object
18
19
20
|
# File 'lib/avo/fields/frame_base_field.rb', line 18
def field_resource
resource || get_resource_by_model_class(@record.class)
end
|
#field_value ⇒ Object
34
35
36
37
38
|
# File 'lib/avo/fields/frame_base_field.rb', line 34
def field_value
value.send(database_value)
rescue
nil
end
|
#frame_url(add_turbo_frame: true) ⇒ Object
26
27
28
29
30
31
|
# File 'lib/avo/fields/frame_base_field.rb', line 26
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
63
64
65
|
# File 'lib/avo/fields/frame_base_field.rb', line 63
def has_own_panel?
true
end
|
#placeholder ⇒ Object
59
60
61
|
# File 'lib/avo/fields/frame_base_field.rb', line 59
def placeholder
@placeholder || I18n.t("avo.choose_an_option")
end
|
#query_params(add_turbo_frame: true) ⇒ Object
100
101
102
103
104
105
106
|
# File 'lib/avo/fields/frame_base_field.rb', line 100
def query_params(add_turbo_frame: true)
{
view:,
for_attribute: @for_attribute,
turbo_frame: add_turbo_frame ? turbo_frame : nil
}.compact
end
|
#resource_class(params) ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/avo/fields/frame_base_field.rb', line 108
def resource_class(params)
return use_resource if use_resource.present?
return Avo.resource_manager.get_resource_by_name @id.to_s if @array
reflection = @record.class.reflect_on_association(@for_attribute || params[:related_name])
reflected_model = reflection.klass
Avo.resource_manager.get_resource_by_model_class reflected_model
end
|
#target_resource ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/avo/fields/frame_base_field.rb', line 47
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.options[:class_name].present?
get_resource_by_model_class(reflection.options[:class_name])
else
Avo.resource_manager.get_resource_by_name association_name
end
end
|
#turbo_frame ⇒ Object
22
23
24
|
# File 'lib/avo/fields/frame_base_field.rb', line 22
def turbo_frame
"#{self.class.name.demodulize.to_s.underscore}_show_#{frame_id}"
end
|
#visible_in_reflection? ⇒ Boolean
67
68
69
|
# File 'lib/avo/fields/frame_base_field.rb', line 67
def visible_in_reflection?
false
end
|