BigW Consortium Gitlab

notifications_helper.rb 1.68 KB
Newer Older
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
15

16
  def notification_list_item(notification_level, user_membership)
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
30 31
    end
  end
32

33
  def update_notification_link(notification_level, user_membership, title, icon)
34
    content_tag(:li, class: active_level_for(user_membership, notification_level)) do
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)
Douwe Maan committed
46
    'active' if user_membership.notification_level == level
47
  end
48
end