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



75
76
77
78
79
80
81
82
83
84
# File 'app/helpers/core_card_nav_items_helper.rb', line 75

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 the jobs icon

Returns HTML - The HTML for the given tag.

Returns:

  • HTML - The HTML for the given tag



24
25
26
27
28
# File 'app/helpers/core_card_nav_items_helper.rb', line 24

def current_job_nav_link(obj, path, title: 'Current')
  return unless can?(:view, obj)

  card_nav_item_link(path, title, 'run')
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



60
61
62
63
64
65
# File 'app/helpers/core_card_nav_items_helper.rb', line 60

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


52
53
54
55
56
# File 'app/helpers/core_card_nav_items_helper.rb', line 52

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 the jobs icon

Returns HTML - The HTML for the given tag.

Returns:

  • HTML - The HTML for the given tag



16
17
18
19
20
# File 'app/helpers/core_card_nav_items_helper.rb', line 16

def jobs_nav_link(obj, path, title: 'Jobs')
  return unless can?(:view, obj)

  card_nav_item_link(path, title, 'stack-overflow')
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



45
46
47
48
49
50
# File 'app/helpers/core_card_nav_items_helper.rb', line 45

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
This method is abstract.

Link to the jobs icon

Returns HTML - The HTML for the given tag.

Returns:

  • HTML - The HTML for the given tag



32
33
34
35
36
37
# File 'app/helpers/core_card_nav_items_helper.rb', line 32

def start_job_nav_link(obj, path, title: 'Start', confirm: nil)
  return unless can?(:view, obj)

  confirm ||= "Are you sure you want to restart this #{obj.class_title} job?"
  card_nav_item_link(path, title, 'play', btn_class: 'btn-success', confirm: confirm, method: :post)
end