debian-mirror-gitlab/app/helpers/notifications_helper.rb

49 lines
1.7 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
module NotificationsHelper
2015-09-11 14:41:01 +05:30
include IconsHelper
2014-09-02 18:07:02 +05:30
def notification_icon(notification)
if notification.disabled?
2015-04-26 12:48:37 +05:30
icon('volume-off', class: 'ns-mute')
2014-09-02 18:07:02 +05:30
elsif notification.participating?
2015-04-26 12:48:37 +05:30
icon('volume-down', class: 'ns-part')
2014-09-02 18:07:02 +05:30
elsif notification.watch?
2015-04-26 12:48:37 +05:30
icon('volume-up', class: 'ns-watch')
2014-09-02 18:07:02 +05:30
else
2015-04-26 12:48:37 +05:30
icon('circle-o', class: 'ns-default')
2014-09-02 18:07:02 +05:30
end
end
2015-09-25 12:07:36 +05:30
def notification_list_item(notification_level, user_membership)
case notification_level
when Notification::N_DISABLED
2015-11-26 14:37:03 +05:30
update_notification_link(Notification::N_DISABLED, user_membership, 'Disabled', 'microphone-slash')
2015-09-25 12:07:36 +05:30
when Notification::N_PARTICIPATING
2015-11-26 14:37:03 +05:30
update_notification_link(Notification::N_PARTICIPATING, user_membership, 'Participate', 'volume-up')
2015-09-25 12:07:36 +05:30
when Notification::N_WATCH
2015-11-26 14:37:03 +05:30
update_notification_link(Notification::N_WATCH, user_membership, 'Watch', 'eye')
2015-09-25 12:07:36 +05:30
when Notification::N_MENTION
2015-11-26 14:37:03 +05:30
update_notification_link(Notification::N_MENTION, user_membership, 'On mention', 'at')
2015-09-25 12:07:36 +05:30
when Notification::N_GLOBAL
2015-11-26 14:37:03 +05:30
update_notification_link(Notification::N_GLOBAL, user_membership, 'Global', 'globe')
2015-09-25 12:07:36 +05:30
else
# do nothing
end
end
2015-11-26 14:37:03 +05:30
def update_notification_link(notification_level, user_membership, title, icon)
content_tag(:li, class: active_level_for(user_membership, notification_level)) do
link_to '#', class: 'update-notification', data: { notification_level: notification_level } do
icon("#{icon} fw", text: title)
end
end
end
2015-09-25 12:07:36 +05:30
def notification_label(user_membership)
Notification.new(user_membership).to_s
end
def active_level_for(user_membership, level)
'active' if user_membership.notification_level == level
end
2014-09-02 18:07:02 +05:30
end