BigW Consortium Gitlab

notifications_helper.rb 2.39 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 24 25 26 27 28
  end

  def notification_title(level)
    case level.to_sym
    when :participating
      'Participate'
    when :mention
      'On mention'
29 30
    else
      level.to_s.titlecase
31 32
    end
  end
33

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

51 52 53 54 55 56 57 58
  def notification_list_item(level, setting)
    title = notification_title(level)

    data = {
      notification_level: level,
      notification_title: title
    }

59 60 61 62
    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')
63 64 65
      end
    end
  end
66

67 68 69 70
  # 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
71

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

  def notification_event_name(event)
    case event
    when :success_pipeline
      'Successful pipeline'
    else
      event.to_s.humanize
    end
  end
86
end