gitlab-org--gitlab-foss/app/helpers/notifications_helper.rb

92 lines
2.4 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2013-03-27 13:04:29 -04:00
module NotificationsHelper
2015-05-21 17:49:06 -04:00
include IconsHelper
def notification_icon_class(level)
case level.to_sym
when :disabled, :owner_disabled
'notifications-off'
when :participating
'notifications'
when :watch
'eye'
when :mention
'at'
when :global
'earth'
end
end
2015-09-14 19:37:11 -04:00
def notification_icon_level(notification_setting, emails_disabled = false)
if emails_disabled
'owner_disabled'
elsif notification_setting.global?
current_user.global_notification_setting.level
else
notification_setting.level
end
end
def notification_icon(level)
icon = notification_icon_class(level)
return '' unless icon
sprite_icon(icon)
end
def notification_title(level)
2017-06-07 16:13:44 -04:00
# Can be anything in `NotificationSetting.level:
case level.to_sym
when :participating
2017-06-07 16:13:44 -04:00
s_('NotificationLevel|Participate')
when :mention
2017-06-07 16:13:44 -04:00
s_('NotificationLevel|On mention')
else
2017-06-07 16:13:44 -04:00
N_('NotificationLevel|Global')
N_('NotificationLevel|Watch')
N_('NotificationLevel|Disabled')
N_('NotificationLevel|Custom')
level = "NotificationLevel|#{level.to_s.humanize}"
s_(level)
2015-09-14 19:37:11 -04:00
end
end
def notification_description(level)
case level.to_sym
when :participating
2017-06-07 16:13:44 -04:00
_('You will only receive notifications for threads you have participated in')
when :mention
2017-06-07 16:13:44 -04:00
_('You will receive notifications only for comments in which you were @mentioned')
when :watch
2017-06-07 16:13:44 -04:00
_('You will receive notifications for any activity')
when :disabled
2017-06-07 16:13:44 -04:00
_('You will not get any notifications via email')
when :global
2017-06-07 16:13:44 -04:00
_('Use your global notification setting')
when :custom
2017-06-07 16:13:44 -04:00
_('You will only receive notifications for the events you choose')
when :owner_disabled
# Any change must be reflected in board_sidebar_subscription.vue
_('Notifications have been disabled by the project or group owner')
end
end
def show_unsubscribe_title?(noteable)
can?(current_user, "read_#{noteable.to_ability_name}".to_sym, noteable)
end
def can_read_project?(project)
can?(current_user, :read_project, project)
end
def notification_dropdown_items(notification_setting)
NotificationSetting.levels.each_key.map do |level|
next if level == "custom"
next if level == "global" && notification_setting.source.nil?
level
end.compact
end
2013-03-27 13:04:29 -04:00
end