Class: Avo::Index::ResourceControlsComponent
Constant Summary
Concerns::FindAssociationField::ASSOCIATIONS
Instance Attribute Summary
#fields_by_panel, #has_as_belongs_to_many_panels, #has_many_panels, #has_one_panels, #resource, #resource_tools, #view
Instance Method Summary
collapse
#can_view?
#authorize_association_for
#a_button, #a_link, #button_classes, #card_classes, #chart_color, #decode_filter_params, #empty_state, #encode_filter_params, #frame_id, #get_model_class, #input_classes, #mount_path, #number_to_social, #possibly_rails_authentication?, #render_license_warning, #root_path_without_url, #svg, #white_panel_classes
#field_wrapper, #filter_wrapper, #index_field_wrapper, #item_selector_data_attributes, #resource_grid, #resource_show_path, #resource_table
#can_create?, #can_delete?, #can_see_the_actions_button?, #can_see_the_destroy_button?, #can_see_the_edit_button?, #destroy_path, #detach_path, #has_reflection_and_is_read_only, #main_panel, #render_cards_component, #render_control, #sidebars
#referrer_params
#has_with_trial
#find_association_field
Instance Method Details
#can_detach? ⇒ Boolean
14
15
16
|
# File 'app/components/avo/index/resource_controls_component.rb', line 14
def can_detach?
is_has_many_association? ? super : false
end
|
#can_edit? ⇒ Boolean
18
19
20
21
22
|
# File 'app/components/avo/index/resource_controls_component.rb', line 18
def can_edit?
return authorize_association_for(:edit) if @reflection.present?
@resource.authorization.authorize_action(:edit, raise_exception: false)
end
|
#edit_path ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'app/components/avo/index/resource_controls_component.rb', line 28
def edit_path
args = {via_view: "index"}
if @parent_record.present?
args = {
via_resource_class: parent_resource.class.to_s,
via_record_id: @parent_record.to_param
}
end
helpers.edit_resource_path(record: @resource.record, resource: parent_or_child_resource, **args)
end
|
#is_has_many_association? ⇒ Boolean
57
58
59
60
61
62
63
|
# File 'app/components/avo/index/resource_controls_component.rb', line 57
def is_has_many_association?
@reflection.class.in? [
ActiveRecord::Reflection::HasManyReflection,
ActiveRecord::Reflection::HasAndBelongsToManyReflection,
ActiveRecord::Reflection::ThroughReflection
]
end
|
#parent_resource ⇒ Object
50
51
52
53
54
55
|
# File 'app/components/avo/index/resource_controls_component.rb', line 50
def parent_resource
return @parent_resource if @parent_resource.present?
return nil if @parent_record.blank?
Avo.resource_manager.get_resource_by_model_class @parent_record.class
end
|
#referrer_path ⇒ Object
65
66
67
|
# File 'app/components/avo/index/resource_controls_component.rb', line 65
def referrer_path
Avo.root_path(paths: ["resources", params[:resource_name], params[:id], params[:related_name]], query: request.query_parameters.to_h)
end
|
#show_path ⇒ Object
24
25
26
|
# File 'app/components/avo/index/resource_controls_component.rb', line 24
def show_path
helpers.resource_show_path(resource: @resource, parent_or_child_resource: parent_or_child_resource, parent_resource: parent_resource, parent_record: @parent_record)
end
|
#singular_resource_name ⇒ Object
42
43
44
45
46
47
48
|
# File 'app/components/avo/index/resource_controls_component.rb', line 42
def singular_resource_name
if @reflection.present?
field&.name&.singularize || reflection_resource.name
else
@resource.singular_name.present? ? @resource.singular_name : @resource.model_class.model_name.name.downcase
end
end
|