class Avo::ActionsComponent
def action_path(action)
When running an action for one record we should do it on a special path.
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
def action_url(action, path)
def action_url(action, path) Avo::Services::URIService.parse(path) .append_paths("actions") .append_query( { action_id: action.param_id, arguments: encrypted_arguments(action) }.compact ).to_s end
def actions
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
def encrypted_arguments(action)
EncryptionService can generate special characters that can break the URL.
Encrypt the arguments so we can pass them as a query param.
def encrypted_arguments(action) return if action.arguments.blank? Base64.encode64 Avo::Services::EncryptionService.encrypt( message: action.arguments, purpose: :action_arguments ) end
def initialize(actions: [], resource: nil, view: nil, exclude: [], include: [], style: :outline, color: :primary, label: nil, size: :md, as_row_control: false)
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 = exclude @include = include @color = color @style = style @label = label || I18n.t("avo.actions") @size = size @as_row_control = as_row_control end
def is_disabled?(action)
def is_disabled?(action) return false if action.standalone || as_row_control on_index_page? end
def many_records_path(action)
def many_records_path(action) action_url(action, @resource.records_path) end
def on_index_page?
def on_index_page? !on_record_page? end
def on_record_page?
def on_record_page? @view.in?([:show, :edit, :new]) end
def render?
def render? actions.present? end
def single_record_path(action)
def single_record_path(action) action_url(action, @resource.record_path) end