2018-08-18 07:19:57 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-03-27 13:04:29 -04:00
|
|
|
module NotificationsHelper
|
2015-05-21 17:49:06 -04:00
|
|
|
include IconsHelper
|
|
|
|
|
2016-03-28 12:17:42 -04:00
|
|
|
def notification_icon_class(level)
|
|
|
|
case level.to_sym
|
2019-08-17 01:56:48 -04:00
|
|
|
when :disabled, :owner_disabled
|
2020-09-14 08:09:34 -04:00
|
|
|
'notifications-off'
|
2016-03-28 12:17:42 -04:00
|
|
|
when :participating
|
2020-09-14 08:09:34 -04:00
|
|
|
'notifications'
|
2016-03-28 12:17:42 -04:00
|
|
|
when :watch
|
|
|
|
'eye'
|
|
|
|
when :mention
|
|
|
|
'at'
|
|
|
|
when :global
|
2020-09-14 08:09:34 -04:00
|
|
|
'earth'
|
2013-07-31 10:05:22 -04:00
|
|
|
end
|
|
|
|
end
|
2015-09-14 19:37:11 -04:00
|
|
|
|
2019-08-17 01:56:48 -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
|
|
|
|
|
2020-09-14 08:09:34 -04:00
|
|
|
def notification_icon(level)
|
2020-09-22 17:10:04 -04:00
|
|
|
icon = notification_icon_class(level)
|
|
|
|
return '' unless icon
|
|
|
|
|
|
|
|
sprite_icon(icon)
|
2016-03-28 12:17:42 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def notification_title(level)
|
2017-06-07 16:13:44 -04:00
|
|
|
# Can be anything in `NotificationSetting.level:
|
2016-03-28 12:17:42 -04:00
|
|
|
case level.to_sym
|
|
|
|
when :participating
|
2017-06-07 16:13:44 -04:00
|
|
|
s_('NotificationLevel|Participate')
|
2016-03-28 12:17:42 -04:00
|
|
|
when :mention
|
2017-06-07 16:13:44 -04:00
|
|
|
s_('NotificationLevel|On mention')
|
2016-03-28 17:22:28 -04:00
|
|
|
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
|
2015-09-14 21:33:24 -04:00
|
|
|
|
2016-05-27 10:56:43 -04:00
|
|
|
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')
|
2016-05-27 10:56:43 -04:00
|
|
|
when :mention
|
2017-06-07 16:13:44 -04:00
|
|
|
_('You will receive notifications only for comments in which you were @mentioned')
|
2016-05-27 10:56:43 -04:00
|
|
|
when :watch
|
2017-06-07 16:13:44 -04:00
|
|
|
_('You will receive notifications for any activity')
|
2016-05-27 10:56:43 -04:00
|
|
|
when :disabled
|
2017-06-07 16:13:44 -04:00
|
|
|
_('You will not get any notifications via email')
|
2016-05-27 10:56:43 -04:00
|
|
|
when :global
|
2017-06-07 16:13:44 -04:00
|
|
|
_('Use your global notification setting')
|
2016-06-16 10:42:54 -04:00
|
|
|
when :custom
|
2017-06-07 16:13:44 -04:00
|
|
|
_('You will only receive notifications for the events you choose')
|
2019-08-17 01:56:48 -04:00
|
|
|
when :owner_disabled
|
|
|
|
_('Notifications have been disabled by the project or group owner')
|
2016-05-27 10:56:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-09 09:09:04 -04:00
|
|
|
def show_unsubscribe_title?(noteable)
|
|
|
|
can?(current_user, "read_#{noteable.to_ability_name}".to_sym, noteable)
|
|
|
|
end
|
2020-01-02 16:07:38 -05:00
|
|
|
|
|
|
|
def can_read_project?(project)
|
|
|
|
can?(current_user, :read_project, project)
|
|
|
|
end
|
2021-01-29 16:09:34 -05:00
|
|
|
|
|
|
|
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
|