Class: Avo::ActionsComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
ApplicationHelper
Defined in:
app/components/avo/actions_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, #root_path_without_url, #svg, #white_panel_classes

Constructor Details

#initialize(actions: [], resource: nil, view: nil, exclude: [], style: :outline, color: :primary, label: nil) ⇒ ActionsComponent

Returns a new instance of ActionsComponent.



7
8
9
10
11
12
13
14
15
# File 'app/components/avo/actions_component.rb', line 7

def initialize(actions: [], resource: nil, view: nil, exclude: [], style: :outline, color: :primary, label: nil)
  @actions = actions || []
  @resource = resource
  @view = view
  @exclude = exclude
  @color = color
  @style = style
  @label = label || t("avo.actions")
end

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



5
6
7
# File 'app/components/avo/actions_component.rb', line 5

def label
  @label
end

Instance Method Details

#action_path(id) ⇒ Object

When running an action for one record we should do it on a special path. We do that so we get the ‘model` param inside the action so we can prefill fields.



27
28
29
30
31
32
33
34
35
# File 'app/components/avo/actions_component.rb', line 27

def action_path(id)
  return many_records_path(id) unless @resource.has_model_id?

  if on_record_page?
    single_record_path id
  else
    many_records_path id
  end
end

#actionsObject



21
22
23
# File 'app/components/avo/actions_component.rb', line 21

def actions
  @actions.reject { |action| action.class.in?(@exclude) }
end

#is_disabled?(action) ⇒ Boolean

How should the action be displayed by default

Returns:

  • (Boolean)


38
39
40
41
42
# File 'app/components/avo/actions_component.rb', line 38

def is_disabled?(action)
  return false if action.standalone

  on_index_page?
end

#render?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'app/components/avo/actions_component.rb', line 17

def render?
  actions.present?
end