Class: Jav::Index::ResourceControlsComponent
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
#authorize_association_for, #can_act_on?, #can_create?, #can_delete?, #can_see_the_destroy_button?, #can_see_the_edit_button?, #destroy_path, #detach_path, #has_reflection_and_is_read_only, #main_panel, #sidebar, #sidebar_component
#has_with_trial
Constructor Details
#initialize(resource: nil, reflection: nil, parent_model: nil, parent_resource: nil, view_type: :table) ⇒ ResourceControlsComponent
Returns a new instance of ResourceControlsComponent.
4
5
6
7
8
9
10
11
|
# File 'app/components/jav/index/resource_controls_component.rb', line 4
def initialize(resource: nil, reflection: nil, parent_model: nil, parent_resource: nil, view_type: :table)
super
@resource = resource
@reflection = reflection
@parent_model = parent_model
@parent_resource = parent_resource
@view_type = view_type
end
|
Instance Method Details
#can_detach? ⇒ Boolean
13
14
15
|
# File 'app/components/jav/index/resource_controls_component.rb', line 13
def can_detach?
is_has_many_association? ? super : false
end
|
#can_edit? ⇒ Boolean
17
18
19
20
21
|
# File 'app/components/jav/index/resource_controls_component.rb', line 17
def can_edit?
return authorize_association_for(:edit) if @reflection.present?
@resource.authorization.authorize_action(:edit, raise_exception: false)
end
|
#can_reorder? ⇒ Boolean
32
33
34
35
36
|
# File 'app/components/jav/index/resource_controls_component.rb', line 32
def can_reorder?
return authorize_association_for(:reorder) if @reflection.present?
@resource.authorization.authorize_action(:reorder, raise_exception: false)
end
|
#can_view? ⇒ Boolean
23
24
25
26
27
28
29
30
|
# File 'app/components/jav/index/resource_controls_component.rb', line 23
def can_view?
return false if Jav.configuration.resource_default_view == :edit
return authorize_association_for(:show) if @reflection.present?
@resource.authorization.authorize_action(:show, raise_exception: false)
end
|
#edit_path ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'app/components/jav/index/resource_controls_component.rb', line 52
def edit_path
args = { via_view: "index" }
if @parent_model.present?
args = {
via_resource_class: parent_resource.class.to_s,
via_resource_id: @parent_model.to_param
}
args[:active_tab_name] = params[:active_tab_name] if params[:active_tab_name].present?
end
helpers.edit_resource_path(model: @resource.model, resource: parent_or_child_resource, **args)
end
|
#is_has_many_association? ⇒ Boolean
82
83
84
85
86
87
88
|
# File 'app/components/jav/index/resource_controls_component.rb', line 82
def is_has_many_association?
@reflection.class.in? [
ActiveRecord::Reflection::HasManyReflection,
ActiveRecord::Reflection::HasAndBelongsToManyReflection,
ActiveRecord::Reflection::ThroughReflection
]
end
|
#parent_resource ⇒ Object
75
76
77
78
79
80
|
# File 'app/components/jav/index/resource_controls_component.rb', line 75
def parent_resource
return @parent_resource if @parent_resource.present?
return nil if @parent_model.blank?
::Jav::App.get_resource_by_model_name @parent_model.class
end
|
#referrer_path ⇒ Object
90
91
92
|
# File 'app/components/jav/index/resource_controls_component.rb', line 90
def referrer_path
Jav::App.root_path(paths: ["resources", params[:resource_name], params[:id], params[:related_name]], query: request.query_parameters.to_h)
end
|
#show_path ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'app/components/jav/index/resource_controls_component.rb', line 38
def show_path
args = {}
if @parent_model.present?
args = {
via_resource_class: parent_resource.class.to_s,
via_resource_id: @parent_model.to_param
}
args[:active_tab_name] = params[:active_tab_name] if params[:active_tab_name].present?
end
helpers.resource_path(model: @resource.model, resource: parent_or_child_resource, **args)
end
|
#singular_resource_name ⇒ Object
67
68
69
70
71
72
73
|
# File 'app/components/jav/index/resource_controls_component.rb', line 67
def singular_resource_name
if @reflection.present?
field&.name&.singularize || reflection_resource.name
else
@resource.singular_name.presence || @resource.model_class.model_name.name.downcase
end
end
|