Class: Avo::TabSwitcherComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- Avo::TabSwitcherComponent
- Includes:
- ApplicationHelper, UrlHelpers
- Defined in:
- app/components/avo/tab_switcher_component.rb
Instance Attribute Summary collapse
-
#active_tab_name ⇒ Object
readonly
Returns the value of attribute active_tab_name.
-
#current_tab ⇒ Object
readonly
Returns the value of attribute current_tab.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#tabs ⇒ Object
readonly
Returns the value of attribute tabs.
-
#view ⇒ Object
readonly
Returns the value of attribute view.
Instance Method Summary collapse
-
#current_one?(tab) ⇒ Boolean
We’ll mark the tab as selected if it’s the current one.
-
#initialize(resource:, group:, current_tab:, active_tab_name:, view:) ⇒ TabSwitcherComponent
constructor
A new instance of TabSwitcherComponent.
- #is_edit? ⇒ Boolean
- #is_new? ⇒ Boolean
-
#tab_path(tab) ⇒ Object
TOD: helper to record:.
Methods included from ApplicationHelper
#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, #render_license_warning, #root_path_without_url, #svg, #white_panel_classes
Methods included from ResourcesHelper
#field_wrapper, #filter_wrapper, #index_field_wrapper, #item_select_all_input, #item_selector_init, #item_selector_input, #resource_grid, #resource_table
Methods included from UrlHelpers
#edit_resource_path, #new_resource_path, #preview_resource_path, #related_resources_path, #resource_attach_path, #resource_detach_path, #resource_path, #resource_view_path, #resources_path
Methods inherited from BaseComponent
Constructor Details
#initialize(resource:, group:, current_tab:, active_tab_name:, view:) ⇒ TabSwitcherComponent
Returns a new instance of TabSwitcherComponent.
17 18 19 20 21 22 23 24 |
# File 'app/components/avo/tab_switcher_component.rb', line 17 def initialize(resource:, group:, current_tab:, active_tab_name:, view:) @active_tab_name = active_tab_name @resource = resource @group = group @current_tab = current_tab @tabs = group.items @view = view end |
Instance Attribute Details
#active_tab_name ⇒ Object (readonly)
Returns the value of attribute active_tab_name.
7 8 9 |
# File 'app/components/avo/tab_switcher_component.rb', line 7 def active_tab_name @active_tab_name end |
#current_tab ⇒ Object (readonly)
Returns the value of attribute current_tab.
9 10 11 |
# File 'app/components/avo/tab_switcher_component.rb', line 9 def current_tab @current_tab end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
8 9 10 |
# File 'app/components/avo/tab_switcher_component.rb', line 8 def group @group end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
12 13 14 |
# File 'app/components/avo/tab_switcher_component.rb', line 12 def resource @resource end |
#tabs ⇒ Object (readonly)
Returns the value of attribute tabs.
10 11 12 |
# File 'app/components/avo/tab_switcher_component.rb', line 10 def tabs @tabs end |
#view ⇒ Object (readonly)
Returns the value of attribute view.
11 12 13 |
# File 'app/components/avo/tab_switcher_component.rb', line 11 def view @view end |
Instance Method Details
#current_one?(tab) ⇒ Boolean
We’ll mark the tab as selected if it’s the current one
46 47 48 |
# File 'app/components/avo/tab_switcher_component.rb', line 46 def current_one?(tab) tab.name == active_tab_name end |
#is_edit? ⇒ Boolean
37 38 39 |
# File 'app/components/avo/tab_switcher_component.rb', line 37 def is_edit? @view.in?(%w[edit update]) end |
#is_new? ⇒ Boolean
41 42 43 |
# File 'app/components/avo/tab_switcher_component.rb', line 41 def is_new? @view.in?(%w[new create]) end |
#tab_path(tab) ⇒ Object
TOD: helper to record:
27 28 29 30 31 32 33 34 35 |
# File 'app/components/avo/tab_switcher_component.rb', line 27 def tab_path(tab) if is_edit? helpers.edit_resource_path(resource: @resource, record: @resource.record, keep_query_params: true, active_tab_name: tab.name, tab_turbo_frame: group.turbo_frame_id) elsif is_new? helpers.new_resource_path(resource: @resource, keep_query_params: true, active_tab_name: tab.name, tab_turbo_frame: group.turbo_frame_id) else helpers.resource_path(resource: @resource, record: @resource.record, keep_query_params: true, active_tab_name: tab.name, tab_turbo_frame: group.turbo_frame_id) end end |