2013-03-27 17:04:29 +00:00
|
|
|
module NotificationsHelper
|
2015-05-21 21:49:06 +00:00
|
|
|
include IconsHelper
|
|
|
|
|
2016-03-28 16:17:42 +00:00
|
|
|
def notification_icon_class(level)
|
|
|
|
case level.to_sym
|
|
|
|
when :disabled
|
|
|
|
'microphone-slash'
|
|
|
|
when :participating
|
|
|
|
'volume-up'
|
|
|
|
when :watch
|
|
|
|
'eye'
|
|
|
|
when :mention
|
|
|
|
'at'
|
|
|
|
when :global
|
|
|
|
'globe'
|
2013-07-31 14:05:22 +00:00
|
|
|
end
|
|
|
|
end
|
2015-09-14 23:37:11 +00:00
|
|
|
|
2016-03-29 11:08:30 +00:00
|
|
|
def notification_icon(level, text = nil)
|
|
|
|
icon("#{notification_icon_class(level)} fw", text: text)
|
2016-03-28 16:17:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def notification_title(level)
|
2017-06-07 20:13:44 +00:00
|
|
|
# Can be anything in `NotificationSetting.level:
|
2016-03-28 16:17:42 +00:00
|
|
|
case level.to_sym
|
|
|
|
when :participating
|
2017-06-07 20:13:44 +00:00
|
|
|
s_('NotificationLevel|Participate')
|
2016-03-28 16:17:42 +00:00
|
|
|
when :mention
|
2017-06-07 20:13:44 +00:00
|
|
|
s_('NotificationLevel|On mention')
|
2016-03-28 21:22:28 +00:00
|
|
|
else
|
2017-06-07 20:13:44 +00:00
|
|
|
N_('NotificationLevel|Global')
|
|
|
|
N_('NotificationLevel|Watch')
|
|
|
|
N_('NotificationLevel|Disabled')
|
|
|
|
N_('NotificationLevel|Custom')
|
|
|
|
level = "NotificationLevel|#{level.to_s.humanize}"
|
|
|
|
s_(level)
|
2015-09-14 23:37:11 +00:00
|
|
|
end
|
|
|
|
end
|
2015-09-15 01:33:24 +00:00
|
|
|
|
2016-05-27 14:56:43 +00:00
|
|
|
def notification_description(level)
|
|
|
|
case level.to_sym
|
|
|
|
when :participating
|
2017-06-07 20:13:44 +00:00
|
|
|
_('You will only receive notifications for threads you have participated in')
|
2016-05-27 14:56:43 +00:00
|
|
|
when :mention
|
2017-06-07 20:13:44 +00:00
|
|
|
_('You will receive notifications only for comments in which you were @mentioned')
|
2016-05-27 14:56:43 +00:00
|
|
|
when :watch
|
2017-06-07 20:13:44 +00:00
|
|
|
_('You will receive notifications for any activity')
|
2016-05-27 14:56:43 +00:00
|
|
|
when :disabled
|
2017-06-07 20:13:44 +00:00
|
|
|
_('You will not get any notifications via email')
|
2016-05-27 14:56:43 +00:00
|
|
|
when :global
|
2017-06-07 20:13:44 +00:00
|
|
|
_('Use your global notification setting')
|
2016-06-16 14:42:54 +00:00
|
|
|
when :custom
|
2017-06-07 20:13:44 +00:00
|
|
|
_('You will only receive notifications for the events you choose')
|
2016-05-27 14:56:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-03-28 16:17:42 +00:00
|
|
|
def notification_list_item(level, setting)
|
|
|
|
title = notification_title(level)
|
|
|
|
|
|
|
|
data = {
|
|
|
|
notification_level: level,
|
|
|
|
notification_title: title
|
|
|
|
}
|
|
|
|
|
2016-05-27 14:56:43 +00: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 18:38:05 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-06-06 15:50:54 +00:00
|
|
|
|
2016-06-14 18:36:36 +00: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 15:50:54 +00:00
|
|
|
|
2016-06-14 18:36:36 +00: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 09:02:39 +00:00
|
|
|
|
2016-06-22 13:50:19 +00:00
|
|
|
hidden_field_tag "#{notification_setting.source_type.downcase}_id", notification_setting.source_id
|
2016-06-06 15:50:54 +00:00
|
|
|
end
|
2016-09-29 17:15:03 +00:00
|
|
|
|
|
|
|
def notification_event_name(event)
|
2017-06-07 20:13:44 +00:00
|
|
|
# All values from NotificationSetting::EMAIL_EVENTS
|
2016-09-29 17:15:03 +00:00
|
|
|
case event
|
|
|
|
when :success_pipeline
|
2017-06-07 20:13:44 +00:00
|
|
|
s_('NotificationEvent|Successful pipeline')
|
2016-09-29 17:15:03 +00:00
|
|
|
else
|
2017-06-07 20:13:44 +00:00
|
|
|
N_('NotificationEvent|New note')
|
|
|
|
N_('NotificationEvent|New issue')
|
|
|
|
N_('NotificationEvent|Reopen issue')
|
|
|
|
N_('NotificationEvent|Close issue')
|
|
|
|
N_('NotificationEvent|Reassign issue')
|
|
|
|
N_('NotificationEvent|New merge request')
|
|
|
|
N_('NotificationEvent|Close merge request')
|
|
|
|
N_('NotificationEvent|Reassign merge request')
|
|
|
|
N_('NotificationEvent|Merge merge request')
|
|
|
|
N_('NotificationEvent|Failed pipeline')
|
|
|
|
s_(event.to_s.humanize)
|
2016-09-29 17:15:03 +00:00
|
|
|
end
|
|
|
|
end
|
2013-03-27 17:04:29 +00:00
|
|
|
end
|