notifications_helper.rb 1.7 KB
Newer Older
D
Dmitriy Zaporozhets 已提交
1
module NotificationsHelper
2 3
  include IconsHelper

4 5
  def notification_icon(notification)
    if notification.disabled?
6
      icon('volume-off', class: 'ns-mute')
7
    elsif notification.participating?
8
      icon('volume-down', class: 'ns-part')
9
    elsif notification.watch?
10
      icon('volume-up', class: 'ns-watch')
11
    else
12
      icon('circle-o', class: 'ns-default')
13 14
    end
  end
D
Darby 已提交
15

16
  def notification_list_item(notification_level, user_membership)
D
Darby 已提交
17
    case notification_level
18
    when Notification::N_DISABLED
19
      update_notification_link(Notification::N_DISABLED, user_membership, 'Disabled', 'microphone-slash')
20
    when Notification::N_PARTICIPATING
21
      update_notification_link(Notification::N_PARTICIPATING, user_membership, 'Participate', 'volume-up')
22
    when Notification::N_WATCH
23
      update_notification_link(Notification::N_WATCH, user_membership, 'Watch', 'eye')
24
    when Notification::N_MENTION
25
      update_notification_link(Notification::N_MENTION, user_membership, 'On mention', 'at')
26
    when Notification::N_GLOBAL
27
      update_notification_link(Notification::N_GLOBAL, user_membership, 'Global', 'globe')
28 29
    else
      # do nothing
D
Darby 已提交
30 31
    end
  end
32

D
Dmitriy Zaporozhets 已提交
33
  def update_notification_link(notification_level, user_membership, title, icon)
34
    content_tag(:li, class: active_level_for(user_membership, notification_level)) do
D
Dmitriy Zaporozhets 已提交
35
      link_to '#', class: 'update-notification', data: { notification_level: notification_level } do
36 37 38 39 40
        icon("#{icon} fw", text: title)
      end
    end
  end

41 42 43 44
  def notification_label(user_membership)
    Notification.new(user_membership).to_s
  end

45
  def active_level_for(user_membership, level)
D
Douwe Maan 已提交
46
    'active' if user_membership.notification_level == level
47
  end
D
Dmitriy Zaporozhets 已提交
48
end