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

61 lines
2.2 KiB
Ruby
Raw Normal View History

2013-03-27 17:04:29 +00:00
module NotificationsHelper
2015-05-21 21:49:06 +00:00
include IconsHelper
def notification_icon(notification)
if notification.disabled?
icon('volume-off', class: 'ns-mute')
elsif notification.participating?
icon('volume-down', class: 'ns-part')
elsif notification.watch?
icon('volume-up', class: 'ns-watch')
else
icon('circle-o', class: 'ns-default')
end
end
2015-09-14 23:37:11 +00:00
def notification_list_item(notification_level, user_membership)
2015-09-14 23:37:11 +00:00
case notification_level
when Notification::N_DISABLED
2015-09-20 16:28:14 +00:00
content_tag(:li, class: active_level_for(user_membership, Notification::N_DISABLED)) do
link_to '#', class: 'update-notification', data: { notification_level: Notification::N_DISABLED } do
icon('microphone-slash fw', text: 'Disabled')
2015-09-14 23:37:11 +00:00
end
end
when Notification::N_PARTICIPATING
2015-09-20 16:28:14 +00:00
content_tag(:li, class: active_level_for(user_membership, Notification::N_PARTICIPATING)) do
link_to '#', class: 'update-notification', data: { notification_level: Notification::N_PARTICIPATING } do
icon('volume-up fw', text: 'Participate')
2015-09-14 23:37:11 +00:00
end
end
when Notification::N_WATCH
2015-09-20 16:28:14 +00:00
content_tag(:li, class: active_level_for(user_membership, Notification::N_WATCH)) do
link_to '#', class: 'update-notification', data: { notification_level: Notification::N_WATCH } do
icon('eye fw', text: 'Watch')
2015-09-14 23:37:11 +00:00
end
end
when Notification::N_MENTION
2015-09-20 16:28:14 +00:00
content_tag(:li, class: active_level_for(user_membership, Notification::N_MENTION)) do
link_to '#', class: 'update-notification', data: { notification_level: Notification::N_MENTION } do
icon('at fw', text: 'On mention')
end
end
when Notification::N_GLOBAL
2015-09-20 16:28:14 +00:00
content_tag(:li, class: active_level_for(user_membership, Notification::N_GLOBAL)) do
link_to '#', class: 'update-notification', data: { notification_level: Notification::N_GLOBAL } do
icon('globe fw', text: 'Global')
2015-09-14 23:37:11 +00:00
end
end
else
# do nothing
2015-09-14 23:37:11 +00:00
end
end
def notification_label(user_membership)
Notification.new(user_membership).to_s
end
def active_level_for(user_membership, level)
2015-09-20 16:28:14 +00:00
'active' if user_membership.notification_level == level
end
2013-03-27 17:04:29 +00:00
end