module CmAdmin::ViewHelpers::PageInfoHelper
def custom_action_items(custom_action, current_action_name)
def custom_action_items(custom_action, current_action_name) return unless custom_action.name.present? && policy([:cm_admin, @model.name.classify.constantize]).send(:"#{custom_action.name}?") scoped_model = "CmAdmin::#{@model.name}Policy::#{custom_action.name.classify}Scope".constantize.new(Current.user, @model.name.constantize).resolve has_scoped_record = if current_action_name == 'index' scoped_model.present? else scoped_model.find_by(id: @ar_object.id).present? end return unless custom_action.display_if.call(@ar_object) && has_scoped_record case custom_action.display_type when :icon_only custom_action_icon(custom_action, current_action_name) when :button custom_action_button(custom_action, current_action_name) when :modal custom_modal_button(custom_action) when :page path = cm_admin.send("#{@model.name.underscore}_#{custom_action.name}_path", @ar_object.id, custom_action.url_params) link_to custom_action_title(custom_action), path, class: 'btn-secondary ms-2', method: custom_action.verb end end