Class: Avo::Views::ResourceShowComponent

Inherits:
ResourceComponent
  • Object
show all
Includes:
ApplicationHelper, ResourcesHelper
Defined in:
app/components/avo/views/resource_show_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ApplicationHelper

#a_button, #a_link, #button_classes, #empty_state, #get_model_class, #input_classes, #render_license_warning, #render_license_warnings, #svg, #turbo_frame_wrap

Methods included from ResourcesHelper

#edit_field_wrapper, #filter_wrapper, #index_field_wrapper, #item_select_all_input, #item_selector_init, #item_selector_input, #resource_grid, #resource_table, #show_field_wrapper

Constructor Details

#initialize(resource: nil, reflection: nil, parent_model: nil) ⇒ ResourceShowComponent

Returns a new instance of ResourceShowComponent.



9
10
11
12
13
14
# File 'app/components/avo/views/resource_show_component.rb', line 9

def initialize(resource: nil, reflection: nil, parent_model: nil)
  @resource = resource
  @reflection = reflection

  split_panel_fields
end

Instance Attribute Details

#fields_by_panelObject (readonly)

Returns the value of attribute fields_by_panel.



7
8
9
# File 'app/components/avo/views/resource_show_component.rb', line 7

def fields_by_panel
  @fields_by_panel
end

#has_as_belongs_to_many_panelsObject (readonly)

Returns the value of attribute has_as_belongs_to_many_panels.



7
8
9
# File 'app/components/avo/views/resource_show_component.rb', line 7

def has_as_belongs_to_many_panels
  @has_as_belongs_to_many_panels
end

#has_many_panelsObject (readonly)

Returns the value of attribute has_many_panels.



7
8
9
# File 'app/components/avo/views/resource_show_component.rb', line 7

def has_many_panels
  @has_many_panels
end

#has_one_panelsObject (readonly)

Returns the value of attribute has_one_panels.



7
8
9
# File 'app/components/avo/views/resource_show_component.rb', line 7

def has_one_panels
  @has_one_panels
end

Instance Method Details

#back_pathObject



16
17
18
19
20
21
22
# File 'app/components/avo/views/resource_show_component.rb', line 16

def back_path
  if via_resource?
    helpers.resource_path(model: params[:via_resource_class].safe_constantize, resource: relation_resource, resource_id: params[:via_resource_id])
  else
    helpers.resources_path(resource: @resource)
  end
end

#can_detach?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'app/components/avo/views/resource_show_component.rb', line 45

def can_detach?
  authorize_association_for("detach")
end

#can_see_the_destroy_button?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'app/components/avo/views/resource_show_component.rb', line 53

def can_see_the_destroy_button?
  @resource.authorization.authorize_action(:destroy, raise_exception: false)
end

#can_see_the_edit_button?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'app/components/avo/views/resource_show_component.rb', line 49

def can_see_the_edit_button?
  @resource.authorization.authorize_action(:edit, raise_exception: false)
end

#destroy_pathObject



41
42
43
# File 'app/components/avo/views/resource_show_component.rb', line 41

def destroy_path
  helpers.resource_path(model: @resource.model, resource: @resource)
end

#detach_pathObject



37
38
39
# File 'app/components/avo/views/resource_show_component.rb', line 37

def detach_path
  helpers.resource_detach_path(params[:resource_name], params[:id], @reflection.name.to_s, @resource.model.id)
end

#edit_pathObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/components/avo/views/resource_show_component.rb', line 24

def edit_path
  args = {}

  if via_resource?
    args = {
      via_resource_class: params[:via_resource_class],
      via_resource_id: params[:via_resource_id]
    }
  end

  helpers.edit_resource_path(model: @resource.model, resource: @resource, **args)
end