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 ,
2014-12-13 10:28:46 -08:00
icon : nil ,
class : ''
2014-11-10 14:46:51 -08:00
} . 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
2014-12-13 10:28:46 -08:00
content_tag ( :li , link_to ( body . html_safe , path ) , class : ( " #{ 'active ' if current_page? path } #{ options [ :class ] } " ) )
2014-08-01 06:27:08 -07:00
end
2015-04-19 07:49:53 -07:00
def list_group_item ( body , path , options = { } )
options = {
badge : nil ,
badge_color : nil ,
class : ''
} . merge ( options )
unless options [ :badge ] . nil? or options [ :badge ] == 0
# TODO: make this prettier?
body << " #{
content_tag ( :span , options [ :badge ] , class : ( " badge #{
" badge- #{ options [ :badge_color ] } " unless options [ :badge_color ] . nil?
} " ))} "
end
content_tag ( :a , body . html_safe , href : path , class : ( " list-group-item #{ 'active ' if current_page? path } #{ options [ :class ] } " ) )
end
2014-08-01 06:27:08 -07:00
##
#
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 )
2014-11-10 21:40:12 -08:00
. 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-12-14 06:15:15 -08:00
def notification_count
return 0 unless user_signed_in?
count = Notification . for ( current_user ) . where ( new : true )
return nil if count . nil?
return nil unless count . count > 0
count . count
end
2014-11-28 10:23:54 -08:00
def privileged? ( user )
2014-12-28 12:14:01 -08:00
( ( ! current_user . nil? ) && ( ( current_user == user ) || current_user . mod? ) ) ? true : false
2014-11-27 02:50:10 -08:00
end
2014-11-30 05:31:38 -08:00
2014-12-29 03:56:41 -08:00
# @deprecated Use {User#profile_picture.url} instead.
2014-11-30 05:31:38 -08:00
def gravatar_url ( user )
2014-12-29 05:57:16 -08:00
return user . profile_picture . url :medium
2014-12-12 09:04:34 -08:00
# return '/cage.png'
2014-12-29 03:56:41 -08:00
#return '//www.gravatar.com/avatar' if user.nil?
#return "//www.gravatar.com/avatar/#{Digest::MD5.hexdigest(user)}" if user.is_a? String
#"//www.gravatar.com/avatar/#{Digest::MD5.hexdigest(user.email)}"
2014-11-30 05:31:38 -08:00
end
2014-12-06 08:08:10 -08:00
def ios_web_app?
2014-12-08 03:11:20 -08:00
user_agent = request . env [ 'HTTP_USER_AGENT' ] || 'Mozilla/5.0'
2014-12-06 08:08:10 -08: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 02:23:47 -07:00
end