Retrospring/app/helpers/application_helper.rb

49 lines
1.5 KiB
Ruby
Raw Normal View History

2022-01-15 16:04:47 -08:00
# frozen_string_literal: true
2014-08-01 02:23:47 -07:00
module ApplicationHelper
2021-08-06 13:20:55 -07:00
include ApplicationHelper::GraphMethods
include ApplicationHelper::TitleMethods
2014-11-10 14:46:51 -08:00
def inbox_count
return 0 unless user_signed_in?
2022-01-15 16:04:47 -08:00
2014-11-10 14:46:51 -08:00
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?
2022-01-15 16:04:47 -08:00
return nil unless count.count.positive?
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?
2022-01-15 16:04:47 -08:00
2014-12-14 06:15:15 -08:00
count = Notification.for(current_user).where(new: true)
return nil if count.nil?
2022-01-15 16:04:47 -08:00
return nil unless count.count.positive?
2014-12-14 06:15:15 -08:00
count.count
end
2014-11-28 10:23:54 -08:00
def privileged?(user)
2022-01-15 16:04:47 -08:00
!current_user.nil? && ((current_user == user) || current_user.mod?)
2014-11-27 02:50:10 -08:00
end
2014-11-30 05:31:38 -08:00
2014-12-06 08:08:10 -08:00
def ios_web_app?
2022-01-15 16:04:47 -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
2022-01-15 16:04:47 -08:00
return true if user_agent.match(/^Mozilla\/\d+\.\d+ \(i(?:Phone|Pad|Pod); CPU(?:.*) like Mac OS X\)(?:.*) Mobile(?:\S*)$/)
2014-12-06 08:08:10 -08:00
false
end
def rails_admin_path_for_resource(resource)
2022-01-15 16:04:47 -08:00
[rails_admin_path, resource.model_name.param_key, resource.id].join("/")
end
2014-08-01 02:23:47 -07:00
end