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, #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

Constructor Details

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

Returns a new instance of ActionsComponent.



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

def initialize(actions: [], resource: nil, view: nil, exclude: [], include: [], style: :outline, color: :primary, label: nil, size: :md, as_row_control: false)
  @actions = actions || []
  @resource = resource
  @view = view
  @exclude = Array(exclude)
  @include = include
  @color = color
  @style = style
  @label = label || I18n.t("avo.actions")
  @size = size
  @as_row_control = as_row_control
end

Instance Attribute Details

#as_row_controlObject (readonly)

Returns the value of attribute as_row_control.



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

def as_row_control
  @as_row_control
end

#labelObject (readonly)

Returns the value of attribute label.



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

def label
  @label
end

#sizeObject (readonly)

Returns the value of attribute size.



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

def size
  @size
end

Instance Method Details

#action_path(action) ⇒ Object

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



36
37
38
39
40
41
42
43
44
45
# File 'app/components/avo/actions_component.rb', line 36

def action_path(action)
  return single_record_path(action) if as_row_control
  return many_records_path(action) unless @resource.has_record_id?

  if on_record_page?
    single_record_path action
  else
    many_records_path action
  end
end

#actionsObject



24
25
26
27
28
29
30
31
32
# File 'app/components/avo/actions_component.rb', line 24

def actions
  if @exclude.present?
    @actions.reject { |action| action.class.in?(@exclude) }
  elsif @include.present?
    @actions.select { |action| action.class.in?(@include) }
  else
    @actions
  end
end

#is_disabled?(action) ⇒ Boolean

How should the action be displayed by default

Returns:

  • (Boolean)


48
49
50
51
52
# File 'app/components/avo/actions_component.rb', line 48

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

  on_index_page?
end

#render?Boolean

Returns:

  • (Boolean)


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

def render?
  actions.present?
end