BigW Consortium Gitlab

notifications_helper.rb 3.21 KB
Newer Older
1
module NotificationsHelper
2 3
  include IconsHelper

4 5 6 7 8 9 10 11 12 13 14 15
  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'
16 17
    end
  end
18

19 20
  def notification_icon(level, text = nil)
    icon("#{notification_icon_class(level)} fw", text: text)
21 22 23
  end

  def notification_title(level)
24
    # Can be anything in `NotificationSetting.level:
25 26
    case level.to_sym
    when :participating
27
      s_('NotificationLevel|Participate')
28
    when :mention
29
      s_('NotificationLevel|On mention')
30
    else
31 32 33 34 35 36
      N_('NotificationLevel|Global')
      N_('NotificationLevel|Watch')
      N_('NotificationLevel|Disabled')
      N_('NotificationLevel|Custom')
      level = "NotificationLevel|#{level.to_s.humanize}"
      s_(level)
37 38
    end
  end
39

40 41 42
  def notification_description(level)
    case level.to_sym
    when :participating
43
      _('You will only receive notifications for threads you have participated in')
44
    when :mention
45
      _('You will receive notifications only for comments in which you were @mentioned')
46
    when :watch
47
      _('You will receive notifications for any activity')
48
    when :disabled
49
      _('You will not get any notifications via email')
50
    when :global
51
      _('Use your global notification setting')
52
    when :custom
53
      _('You will only receive notifications for the events you choose')
54 55 56
    end
  end

57 58 59 60 61 62 63 64
  def notification_list_item(level, setting)
    title = notification_title(level)

    data = {
      notification_level: level,
      notification_title: title
    }

65 66 67 68
    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')
69 70 71
      end
    end
  end
72

73 74 75 76
  # 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
77

78 79 80
  # Create hidden field to send notification setting source to controller
  def hidden_setting_source_input(notification_setting)
    return unless notification_setting.source_type
81
    hidden_field_tag "#{notification_setting.source_type.downcase}_id", notification_setting.source_id
82
  end
83 84

  def notification_event_name(event)
85
    # All values from NotificationSetting::EMAIL_EVENTS
86 87
    case event
    when :success_pipeline
88
      s_('NotificationEvent|Successful pipeline')
89
    else
90 91 92 93 94 95 96 97 98 99 100
      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)
101 102
    end
  end
103
end