# frozen_string_literal: true # # Help with nav items at the top of cards # module CoreCardNavItemsHelper # @abstract Yield the main block for card nav items def card_nav_items(&block) content_tag(:ul, class: 'nav nav-pills float-end') do yield block end end # @abstract Link to the jobs icon # @return HTML - The HTML for the given tag def jobs_nav_link(obj, path, title: 'Jobs') return unless can?(:view, obj) card_nav_item_link(path, title, 'stack-overflow') end # @abstract Link to the jobs icon # @return HTML - The HTML for the given tag def current_job_nav_link(obj, path, title: 'Current') return unless can?(:view, obj) card_nav_item_link(path, title, 'run') end # @abstract Link to the jobs icon # @return HTML - The HTML for the given tag 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 # @abstract Link to restart, replay a given object # @param [Object] obj - The object to operate on, for permission checks # @param [String] path - The path/URL for the action # @param [String] confirm - Override the default confirmation # @param [String] title - Override the default title of the button # @return HTML - The HTML for the given tag 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 def edit_nav_link(obj, path, title: 'Edit') return unless can?(:edit, obj) card_nav_item_link(path, title, 'edit') end # @abstract Link to delete an object # @return HTML - The HTML for the given tag 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 # @abstract The work horse for the card nav item # @param [String] path - The path/URL for the action # @param [String] title - The title of the action # @param [String] icon_name - Name of the icon to render # @param [String] confirm - If the action requires confirmation before completing # @param [String|Symbol] method - The HTTP method to use for the link, default is :get # @param [String] btn_class - The class of button that should be used, btn-primary is the default # @return HTML - The HTML for the given tag 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? content_tag(: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(content_tag(:span, class: 'd-none d-md-inline') { title }) end end end end