Class: Avo::ResourceComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- Avo::ResourceComponent
- Includes:
- Concerns::ChecksAssocAuthorization, Concerns::HasResourceStimulusControllers, Concerns::RequestMethods
- Defined in:
- app/components/avo/resource_component.rb
Direct Known Subclasses
Index::ResourceControlsComponent, Items::PanelComponent, Items::SwitcherComponent, Views::ResourceEditComponent, Views::ResourceIndexComponent, Views::ResourceShowComponent
Constant Summary
Constants included from Concerns::FindAssociationField
Concerns::FindAssociationField::ASSOCIATIONS
Instance Attribute Summary collapse
-
#fields_by_panel ⇒ Object
readonly
Returns the value of attribute fields_by_panel.
-
#has_as_belongs_to_many_panels ⇒ Object
readonly
Returns the value of attribute has_as_belongs_to_many_panels.
-
#has_many_panels ⇒ Object
readonly
Returns the value of attribute has_many_panels.
-
#has_one_panels ⇒ Object
readonly
Returns the value of attribute has_one_panels.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#resource_tools ⇒ Object
readonly
Returns the value of attribute resource_tools.
-
#view ⇒ Object
readonly
Returns the value of attribute view.
Instance Method Summary collapse
- #can_create? ⇒ Boolean
- #can_delete? ⇒ Boolean
- #can_detach? ⇒ Boolean
- #can_see_the_actions_button? ⇒ Boolean
- #can_see_the_destroy_button? ⇒ Boolean
- #can_see_the_edit_button? ⇒ Boolean
- #destroy_path ⇒ Object
- #detach_path ⇒ Object
- #render_cards_component ⇒ Object
- #render_control(control) ⇒ Object
- #sidebars ⇒ Object
Methods included from Concerns::HasResourceStimulusControllers
#add_stimulus_attributes_for, #get_stimulus_controllers, #stimulus_data_attributes
Methods included from Concerns::RequestMethods
Methods included from Concerns::ChecksAssocAuthorization
Methods inherited from BaseComponent
#component_name, #hotkey_badge
Methods included from ApplicationHelper
#a_button, #a_link, #body_classes, #button_classes, #chart_color, #container_classes, #d, #decode_filter_params, #e, #editor_file_path, #editor_url, #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, #rtl?, #text_direction, #ui, #wrap_in_modal
Methods included from ResourcesHelper
#field_wrapper, #filter_wrapper, #index_field_wrapper, #item_selector_data_attributes, #record_path, #record_title, #resource_for_record, #resource_grid, #resource_show_path, #resource_table
Methods included from Concerns::FindAssociationField
Instance Attribute Details
#fields_by_panel ⇒ Object (readonly)
Returns the value of attribute fields_by_panel.
6 7 8 |
# File 'app/components/avo/resource_component.rb', line 6 def fields_by_panel @fields_by_panel end |
#has_as_belongs_to_many_panels ⇒ Object (readonly)
Returns the value of attribute has_as_belongs_to_many_panels.
9 10 11 |
# File 'app/components/avo/resource_component.rb', line 9 def has_as_belongs_to_many_panels @has_as_belongs_to_many_panels end |
#has_many_panels ⇒ Object (readonly)
Returns the value of attribute has_many_panels.
8 9 10 |
# File 'app/components/avo/resource_component.rb', line 8 def has_many_panels @has_many_panels end |
#has_one_panels ⇒ Object (readonly)
Returns the value of attribute has_one_panels.
7 8 9 |
# File 'app/components/avo/resource_component.rb', line 7 def has_one_panels @has_one_panels end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
11 12 13 |
# File 'app/components/avo/resource_component.rb', line 11 def resource @resource end |
#resource_tools ⇒ Object (readonly)
Returns the value of attribute resource_tools.
10 11 12 |
# File 'app/components/avo/resource_component.rb', line 10 def resource_tools @resource_tools end |
#view ⇒ Object (readonly)
Returns the value of attribute view.
12 13 14 |
# File 'app/components/avo/resource_component.rb', line 12 def view @view end |
Instance Method Details
#can_create? ⇒ Boolean
14 15 16 17 18 |
# File 'app/components/avo/resource_component.rb', line 14 def can_create? return (:create) if @reflection.present? @resource..(:create, raise_exception: false) end |
#can_delete? ⇒ Boolean
20 21 22 23 24 |
# File 'app/components/avo/resource_component.rb', line 20 def can_delete? return (:destroy) if @reflection.present? @resource..(:destroy, raise_exception: false) end |
#can_detach? ⇒ Boolean
26 27 28 29 30 31 32 33 34 35 |
# File 'app/components/avo/resource_component.rb', line 26 def can_detach? return false if @reflection.blank? || @resource.record.blank? || !(:detach) # If the inverse_of is a belongs_to, we need to check if it's optional in order to know if we can detach it. if inverse_of.is_a?(ActiveRecord::Reflection::BelongsToReflection) inverse_of.[:optional] else true end end |
#can_see_the_actions_button? ⇒ Boolean
59 60 61 62 63 |
# File 'app/components/avo/resource_component.rb', line 59 def return (:act_on) if @reflection.present? @resource..(:act_on, raise_exception: false) end |
#can_see_the_destroy_button? ⇒ Boolean
52 53 54 55 56 57 |
# File 'app/components/avo/resource_component.rb', line 52 def # Disable destroy for ArrayResources return false if @resource.resource_type_array? @resource..(:destroy, raise_exception: false) end |
#can_see_the_edit_button? ⇒ Boolean
43 44 45 46 47 48 49 50 |
# File 'app/components/avo/resource_component.rb', line 43 def # Disable edit for ArrayResources return false if @resource.resource_type_array? return (:edit) if @reflection.present? @resource..(:edit, raise_exception: false) end |
#destroy_path ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/components/avo/resource_component.rb', line 65 def destroy_path args = {record: @resource.record, resource: @resource} args[:referrer] = if params[:via_resource_class].present? back_path # If we're deleting a resource from a parent resource, we need to go back to the parent resource page after the deletion elsif @parent_resource.present? helpers.resource_path(record: @parent_record, resource: @parent_resource) end helpers.resource_path(**args) end |
#detach_path ⇒ Object
37 38 39 40 41 |
# File 'app/components/avo/resource_component.rb', line 37 def detach_path return "/" if @reflection.blank? helpers.resource_detach_path(params[:resource_name], params[:id], @reflection.name.to_s, @resource.record_param) end |
#render_cards_component ⇒ Object
92 93 94 95 96 |
# File 'app/components/avo/resource_component.rb', line 92 def render_cards_component if Avo.plugin_manager.installed?("avo-dashboards") render Avo::CardsComponent.new cards: @resource.detect_cards.visible_cards, classes: "pb-4 sm:grid-cols-3" end end |
#render_control(control) ⇒ Object
88 89 90 |
# File 'app/components/avo/resource_component.rb', line 88 def render_control(control) send :"render_#{control.type}", control end |
#sidebars ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'app/components/avo/resource_component.rb', line 78 def @sidebars ||= @item.items .select do |item| item. end .map do || .hydrate(view: view, resource: resource) end end |