2023-01-04 08:22:06 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-01-10 13:14:58 -08:00
|
|
|
module BootstrapHelper
|
|
|
|
def nav_entry(body, path, options = {})
|
|
|
|
options = {
|
2023-01-04 08:22:06 -08:00
|
|
|
badge: nil,
|
2022-01-10 13:14:58 -08:00
|
|
|
badge_color: nil,
|
2023-01-04 08:22:06 -08:00
|
|
|
icon: nil,
|
|
|
|
class: ""
|
2022-01-10 13:14:58 -08:00
|
|
|
}.merge(options)
|
|
|
|
|
|
|
|
classes = [
|
|
|
|
"nav-item",
|
|
|
|
current_page?(path) ? "active" : nil,
|
|
|
|
options[:class]
|
|
|
|
].compact.join(" ")
|
|
|
|
|
|
|
|
unless options[:icon].nil?
|
2023-01-04 08:22:06 -08:00
|
|
|
body = if options[:icon_only]
|
|
|
|
content_tag(:i, "", class: "fa fa-#{options[:icon]}", title: body).to_s
|
|
|
|
else
|
|
|
|
"#{content_tag(:i, '', class: "fa fa-#{options[:icon]}")} #{body}"
|
|
|
|
end
|
2022-01-10 13:14:58 -08:00
|
|
|
end
|
|
|
|
unless options[:badge].nil?
|
2023-01-04 08:22:06 -08:00
|
|
|
badge_class = [
|
|
|
|
"badge",
|
|
|
|
("badge-#{options[:badge_color]}" unless options[:badge_color].nil?),
|
|
|
|
("badge-pill" if options[:badge_pill])
|
|
|
|
].compact.join(" ")
|
|
|
|
|
2023-01-05 05:32:04 -08:00
|
|
|
body += " #{content_tag(:span, options[:badge], class: badge_class)}".html_safe
|
2022-01-10 13:14:58 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
content_tag(:li, link_to(body.html_safe, path, class: "nav-link"), class: classes)
|
|
|
|
end
|
|
|
|
|
|
|
|
def list_group_item(body, path, options = {})
|
|
|
|
options = {
|
2023-01-04 08:22:06 -08:00
|
|
|
badge: nil,
|
2022-01-10 13:14:58 -08:00
|
|
|
badge_color: nil,
|
2023-01-04 08:22:06 -08:00
|
|
|
class: ""
|
2022-01-10 13:14:58 -08:00
|
|
|
}.merge(options)
|
|
|
|
|
|
|
|
classes = [
|
|
|
|
"list-group-item",
|
|
|
|
"list-group-item-action",
|
|
|
|
current_page?(path) ? "active" : nil,
|
|
|
|
options[:class]
|
|
|
|
].compact.join(" ")
|
|
|
|
|
2023-01-04 08:22:06 -08:00
|
|
|
unless options[:badge].nil? || (options[:badge]).zero?
|
2022-01-10 13:14:58 -08:00
|
|
|
# TODO: make this prettier?
|
|
|
|
body << " #{
|
2023-01-04 08:22:06 -08:00
|
|
|
content_tag(:span, options[:badge], class: "badge#{
|
2022-01-10 13:14:58 -08:00
|
|
|
" badge-#{options[:badge_color]}" unless options[:badge_color].nil?
|
2023-01-04 08:22:06 -08:00
|
|
|
}")}"
|
2022-01-10 13:14:58 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
content_tag(:a, body.html_safe, href: path, class: classes)
|
|
|
|
end
|
|
|
|
|
|
|
|
def tooltip(body, tooltip_content, placement = "bottom")
|
2023-01-04 08:22:06 -08:00
|
|
|
content_tag(:span, body, { :title => tooltip_content, "data-bs-toggle" => "tooltip", "data-bs-placement" => placement })
|
2022-01-10 13:14:58 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
def time_tooltip(subject, placement = "bottom")
|
|
|
|
tooltip time_ago_in_words(subject.created_at), localize(subject.created_at), placement
|
|
|
|
end
|
|
|
|
|
|
|
|
def hidespan(body, hide)
|
|
|
|
content_tag(:span, body, class: hide)
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
#
|
2023-01-04 08:49:52 -08:00
|
|
|
def bootstrap_color(color)
|
|
|
|
case color
|
2022-01-10 13:14:58 -08:00
|
|
|
when "error", "alert"
|
|
|
|
"danger"
|
|
|
|
when "notice"
|
|
|
|
"info"
|
|
|
|
else
|
2023-01-04 08:49:52 -08:00
|
|
|
color
|
2022-01-10 13:14:58 -08:00
|
|
|
end
|
|
|
|
end
|
2023-01-04 03:23:47 -08:00
|
|
|
end
|