2014-08-01 11:23:47 +02:00
module ApplicationHelper
2014-11-10 23:46:51 +01: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 15:27:08 +02:00
end
##
#
def bootstrap_color c
case c
when " error " , " alert "
" danger "
when " notice "
" info "
else
c
end
end
2014-11-10 23:46:51 +01: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 )
2014-11-11 06:40:12 +01:00
. first
return nil if count . nil?
return nil unless count . count > 0
count . count
2014-11-10 23:46:51 +01:00
end
2014-11-27 11:50:10 +01:00
2014-11-28 19:23:54 +01:00
def privileged? ( user )
2014-11-28 21:18:20 +01:00
( current_user && ( current_user == user || current_user . admin? ) ) ? true : false
2014-11-27 11:50:10 +01:00
end
2014-11-30 14:31:38 +01:00
def gravatar_url ( user )
2014-12-12 18:04:34 +01:00
# return '/cage.png'
2014-11-30 14:34:27 +01:00
return '//www.gravatar.com/avatar' if user . nil?
2014-12-12 16:45:39 +01:00
return " //www.gravatar.com/avatar/ #{ Digest :: MD5 . hexdigest ( user ) } " if user . is_a? String
2014-11-30 14:31:38 +01:00
" //www.gravatar.com/avatar/ #{ Digest :: MD5 . hexdigest ( user . email ) } "
end
2014-12-06 17:08:10 +01:00
def ios_web_app?
2014-12-08 12:11:20 +01:00
user_agent = request . env [ 'HTTP_USER_AGENT' ] || 'Mozilla/5.0'
2014-12-06 17:08:10 +01:00
# normal MobileSafari.app UA: Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B435 Safari/600.1.4
# webapp UA: Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12B435
return true if user_agent . match / ^Mozilla \/ \ d+ \ . \ d+ \ (i(?:Phone|Pad|Pod); CPU(?:.*) like Mac OS X \ )(?:.*) Mobile(?: \ S*)$ /
false
end
2014-08-01 11:23:47 +02:00
end