Retrospring/app/helpers/application_helper.rb

53 lines
1.2 KiB
Ruby
Raw Normal View History

2014-08-01 02:23:47 -07:00
module ApplicationHelper
2014-11-10 14:46:51 -08:00
def nav_entry(body, path, options = {})
options = {
badge: nil,
badge_color: nil,
icon: nil
}.merge(options)
unless options[:icon].nil?
body = "#{content_tag(:i, '', class: "mdi-#{options[:icon]}")} #{body}"
end
unless options[:badge].nil?
# TODO: make this prettier?
body << " #{
content_tag(:span, options[:badge], class: ("badge#{
" badge-#{options[:badge_color]}" unless options[:badge_color].nil?
}"))}"
end
content_tag(:li, link_to(body.html_safe, path), class: ('active' if current_page? path))
2014-08-01 06:27:08 -07:00
end
##
#
def bootstrap_color c
case c
when "error", "alert"
"danger"
when "notice"
"info"
else
c
end
end
2014-11-10 14:46:51 -08:00
def inbox_count
return 0 unless user_signed_in?
count = Inbox.select("COUNT(id) AS count")
.where(new: true)
.where(user_id: current_user.id)
.group(:user_id)
.order(:count)
.first
return nil if count.nil?
return nil unless count.count > 0
count.count
2014-11-10 14:46:51 -08:00
end
2014-11-27 02:50:10 -08:00
2014-11-28 10:23:54 -08:00
def privileged?(user)
2014-11-28 12:18:20 -08:00
(current_user && (current_user == user || current_user.admin?)) ? true : false
2014-11-27 02:50:10 -08:00
end
2014-08-01 02:23:47 -07:00
end