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
|
2016-03-28 12:17:42 -04:00
|
|
|
'microphone-slash'
|
|
|
|
when :participating
|
|
|
|
'volume-up'
|
|
|
|
when :watch
|
|
|
|
'eye'
|
|
|
|
when :mention
|
|
|
|
'at'
|
|
|
|
when :global
|
|
|
|
'globe'
|
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
|
|
|
|
|
2016-03-29 07:08:30 -04:00
|
|
|
def notification_icon(level, text = nil)
|
|
|
|
icon("#{notification_icon_class(level)} fw", text: text)
|
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
|
|
|
|
|
2016-03-28 12:17:42 -04:00
|
|
|
def notification_list_item(level, setting)
|
|
|
|
title = notification_title(level)
|
|
|
|
|
|
|
|
data = {
|
|
|
|
notification_level: level,
|
|
|
|
notification_title: title
|
|
|
|
}
|
|
|
|
|
2016-05-27 10:56:43 -04:00
|
|
|
content_tag(:li, role: "menuitem") do
|
|
|
|
link_to '#', class: "update-notification #{('is-active' if setting.level == level)}", data: data do
|
|
|
|
link_output = content_tag(:strong, title, class: 'dropdown-menu-inner-title')
|
|
|
|
link_output << content_tag(:span, notification_description(level), class: 'dropdown-menu-inner-content')
|
2015-11-14 13:38:05 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-06-06 11:50:54 -04:00
|
|
|
|
2016-06-14 14:36:36 -04:00
|
|
|
# Identifier to trigger individually dropdowns and custom settings modals in the same view
|
|
|
|
def notifications_menu_identifier(type, notification_setting)
|
|
|
|
"#{type}-#{notification_setting.user_id}-#{notification_setting.source_id}-#{notification_setting.source_type}"
|
|
|
|
end
|
2016-06-06 11:50:54 -04:00
|
|
|
|
2016-06-14 14:36:36 -04:00
|
|
|
# Create hidden field to send notification setting source to controller
|
|
|
|
def hidden_setting_source_input(notification_setting)
|
|
|
|
return unless notification_setting.source_type
|
2017-11-14 04:02:39 -05:00
|
|
|
|
2016-06-22 09:50:19 -04:00
|
|
|
hidden_field_tag "#{notification_setting.source_type.downcase}_id", notification_setting.source_id
|
2016-06-06 11:50:54 -04:00
|
|
|
end
|
2016-09-29 13:15:03 -04:00
|
|
|
|
|
|
|
def notification_event_name(event)
|
2018-07-22 22:42:19 -04:00
|
|
|
# All values from NotificationSetting.email_events
|
2016-09-29 13:15:03 -04:00
|
|
|
case event
|
|
|
|
when :success_pipeline
|
2017-06-07 16:13:44 -04:00
|
|
|
s_('NotificationEvent|Successful pipeline')
|
2016-09-29 13:15:03 -04:00
|
|
|
else
|
2017-06-07 16:13:44 -04:00
|
|
|
s_(event.to_s.humanize)
|
2016-09-29 13:15:03 -04:00
|
|
|
end
|
|
|
|
end
|
2019-04-19 09:02:35 -04:00
|
|
|
|
2019-08-22 22:39:34 -04:00
|
|
|
def notification_setting_icon(notification_setting = nil)
|
2019-04-19 09:02:35 -04:00
|
|
|
sprite_icon(
|
2019-08-22 22:39:34 -04:00
|
|
|
!notification_setting.present? || notification_setting.disabled? ? "notifications-off" : "notifications",
|
2019-04-19 09:02:35 -04:00
|
|
|
css_class: "icon notifications-icon js-notifications-icon"
|
|
|
|
)
|
|
|
|
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
|
2013-03-27 13:04:29 -04:00
|
|
|
end
|