2022-01-16 01:04:47 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-08-01 11:23:47 +02:00
|
|
|
module ApplicationHelper
|
2021-08-06 22:20:55 +02:00
|
|
|
include ApplicationHelper::GraphMethods
|
2022-01-10 22:14:58 +01:00
|
|
|
include ApplicationHelper::TitleMethods
|
2014-11-10 23:46:51 +01:00
|
|
|
|
|
|
|
def inbox_count
|
|
|
|
return 0 unless user_signed_in?
|
2022-01-16 01:04:47 +01:00
|
|
|
|
2014-11-10 23:46:51 +01:00
|
|
|
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?
|
2022-01-16 01:04:47 +01:00
|
|
|
return nil unless count.count.positive?
|
|
|
|
|
2014-11-11 06:40:12 +01:00
|
|
|
count.count
|
2014-11-10 23:46:51 +01:00
|
|
|
end
|
2014-11-27 11:50:10 +01:00
|
|
|
|
2014-12-14 15:15:15 +01:00
|
|
|
def notification_count
|
|
|
|
return 0 unless user_signed_in?
|
2022-01-16 01:04:47 +01:00
|
|
|
|
2022-12-18 21:58:06 +01:00
|
|
|
count = Notification.for(current_user).where(new: true).count
|
2022-12-18 02:23:21 +01:00
|
|
|
return nil unless count.positive?
|
2022-01-16 01:04:47 +01:00
|
|
|
|
2022-12-18 02:23:21 +01:00
|
|
|
count
|
2014-12-14 15:15:15 +01:00
|
|
|
end
|
|
|
|
|
2014-11-28 19:23:54 +01:00
|
|
|
def privileged?(user)
|
2022-01-16 01:04:47 +01:00
|
|
|
!current_user.nil? && ((current_user == user) || current_user.mod?)
|
2014-11-27 11:50:10 +01:00
|
|
|
end
|
2014-11-30 14:31:38 +01:00
|
|
|
|
2021-08-06 13:38:24 +02:00
|
|
|
def rails_admin_path_for_resource(resource)
|
2022-01-16 01:04:47 +01:00
|
|
|
[rails_admin_path, resource.model_name.param_key, resource.id].join("/")
|
2021-08-06 13:38:24 +02:00
|
|
|
end
|
2014-08-01 11:23:47 +02:00
|
|
|
end
|