Module: CoreCardNavItemsHelper

Defined in:
app/helpers/core_card_nav_items_helper.rb

Overview

Help with nav items at the top of cards

Instance Method Summary collapse

Instance Method Details

This method is abstract.

The work horse for the card nav item

Returns HTML - The HTML for the given tag.

Parameters:

  • path (String)
    • The path/URL for the action

  • title (String)
    • The title of the action

  • icon_name (String)
    • Name of the icon to render

  • confirm (String) (defaults to: nil)
    • If the action requires confirmation before completing

  • method (String|Symbol) (defaults to: :get)
    • The HTTP method to use for the link, default is :get

  • btn_class (String) (defaults to: 'btn-primary')
    • The class of button that should be used, btn-primary is the default

Returns:

  • HTML - The HTML for the given tag



50
51
52
53
54
55
56
57
58
59
# File 'app/helpers/core_card_nav_items_helper.rb', line 50

def card_nav_item_link(path, title, icon_name, confirm: nil, method: :get, btn_class: 'btn-primary')
  data = { method: method }
  data[:confirm] = confirm if confirm.present?
  (:li, class: 'nav-item me-2') do
    link_to path, class: "#{btn_class} btn nav-link active", data: data do
      concat(remix_icon(icon_name, classes: ['me-2'], tooltip_text: title))
      concat((:span, class: 'd-none d-md-inline') { title })
    end
  end
end

#card_nav_items(&block) ⇒ Object

This method is abstract.

Yield the main block for card nav items



8
9
10
11
12
# File 'app/helpers/core_card_nav_items_helper.rb', line 8

def card_nav_items(&block)
  (:ul, class: 'nav nav-pills float-end') do
    yield block
  end
end
This method is abstract.

Link to delete an object

Returns HTML - The HTML for the given tag.

Returns:

  • HTML - The HTML for the given tag



35
36
37
38
39
40
# File 'app/helpers/core_card_nav_items_helper.rb', line 35

def delete_nav_link(obj, path, confirm: nil, title: 'Delete')
  return unless can?(:manage, obj)

  confirm ||= "Are you sure you want to delete this #{obj.class_title}?"
  card_nav_item_link(path, title, 'delete-bin', confirm: confirm, method: :delete, btn_class: 'btn-danger')
end


27
28
29
30
31
# File 'app/helpers/core_card_nav_items_helper.rb', line 27

def edit_nav_link(obj, path, title: 'Edit')
  return unless can?(:edit, obj)

  card_nav_item_link(path, title, 'edit')
end
This method is abstract.

Link to restart, replay a given object

Returns HTML - The HTML for the given tag.

Parameters:

  • obj (Object)
    • The object to operate on, for permission checks

  • path (String)
    • The path/URL for the action

  • confirm (String) (defaults to: nil)
    • Override the default confirmation

  • title (String) (defaults to: 'Restart')
    • Override the default title of the button

Returns:

  • HTML - The HTML for the given tag



20
21
22
23
24
25
# File 'app/helpers/core_card_nav_items_helper.rb', line 20

def restart_nav_link(obj, path, confirm: nil, title: 'Restart')
  return unless can?(:edit, obj)

  confirm ||= "Are you sure you want to restart this #{obj.class_title}?"
  card_nav_item_link(path, title, 'delete-bin', confirm: confirm)
end