2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
module NotificationsHelper
|
2015-09-11 14:41:01 +05:30
|
|
|
include IconsHelper
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
def notification_icon_class(level)
|
|
|
|
case level.to_sym
|
2019-10-12 21:52:04 +05:30
|
|
|
when :disabled, :owner_disabled
|
2020-11-24 15:15:51 +05:30
|
|
|
'notifications-off'
|
2016-06-02 11:05:42 +05:30
|
|
|
when :participating
|
2020-11-24 15:15:51 +05:30
|
|
|
'notifications'
|
2016-06-02 11:05:42 +05:30
|
|
|
when :watch
|
|
|
|
'eye'
|
|
|
|
when :mention
|
|
|
|
'at'
|
|
|
|
when :global
|
2020-11-24 15:15:51 +05:30
|
|
|
'earth'
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
2015-09-25 12:07:36 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
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-11-24 15:15:51 +05:30
|
|
|
def notification_icon(level)
|
|
|
|
icon = notification_icon_class(level)
|
|
|
|
return '' unless icon
|
|
|
|
|
|
|
|
sprite_icon(icon)
|
2015-09-25 12:07:36 +05:30
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
def notification_title(level)
|
2017-09-10 17:25:29 +05:30
|
|
|
# Can be anything in `NotificationSetting.level:
|
2016-06-02 11:05:42 +05:30
|
|
|
case level.to_sym
|
|
|
|
when :participating
|
2017-09-10 17:25:29 +05:30
|
|
|
s_('NotificationLevel|Participate')
|
2016-06-02 11:05:42 +05:30
|
|
|
when :mention
|
2017-09-10 17:25:29 +05:30
|
|
|
s_('NotificationLevel|On mention')
|
2016-06-02 11:05:42 +05:30
|
|
|
else
|
2017-09-10 17:25:29 +05:30
|
|
|
N_('NotificationLevel|Global')
|
|
|
|
N_('NotificationLevel|Watch')
|
|
|
|
N_('NotificationLevel|Disabled')
|
|
|
|
N_('NotificationLevel|Custom')
|
|
|
|
level = "NotificationLevel|#{level.to_s.humanize}"
|
|
|
|
s_(level)
|
2015-11-26 14:37:03 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
def notification_description(level)
|
|
|
|
case level.to_sym
|
|
|
|
when :participating
|
2017-09-10 17:25:29 +05:30
|
|
|
_('You will only receive notifications for threads you have participated in')
|
2016-06-16 23:09:34 +05:30
|
|
|
when :mention
|
2017-09-10 17:25:29 +05:30
|
|
|
_('You will receive notifications only for comments in which you were @mentioned')
|
2016-06-16 23:09:34 +05:30
|
|
|
when :watch
|
2017-09-10 17:25:29 +05:30
|
|
|
_('You will receive notifications for any activity')
|
2016-06-16 23:09:34 +05:30
|
|
|
when :disabled
|
2017-09-10 17:25:29 +05:30
|
|
|
_('You will not get any notifications via email')
|
2016-06-16 23:09:34 +05:30
|
|
|
when :global
|
2017-09-10 17:25:29 +05:30
|
|
|
_('Use your global notification setting')
|
2016-06-22 15:30:34 +05:30
|
|
|
when :custom
|
2017-09-10 17:25:29 +05:30
|
|
|
_('You will only receive notifications for the events you choose')
|
2019-10-12 21:52:04 +05:30
|
|
|
when :owner_disabled
|
2021-01-29 00:20:46 +05:30
|
|
|
# Any change must be reflected in board_sidebar_subscription.vue
|
2019-10-12 21:52:04 +05:30
|
|
|
_('Notifications have been disabled by the project or group owner')
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-05 12:25:43 +05:30
|
|
|
def show_unsubscribe_title?(noteable)
|
|
|
|
can?(current_user, "read_#{noteable.to_ability_name}".to_sym, noteable)
|
|
|
|
end
|
2020-01-03 18:37:03 +05:30
|
|
|
|
|
|
|
def can_read_project?(project)
|
|
|
|
can?(current_user, :read_project, project)
|
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
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
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|