Module: NotificationsHelper

Includes:
IconsHelper
Included in:
IssuableSidebarExtrasEntity
Defined in:
app/helpers/notifications_helper.rb

Constant Summary

Constants included from IconsHelper

IconsHelper::DEFAULT_ICON_SIZE

Instance Method Summary collapse

Methods included from IconsHelper

#audit_icon, #boolean_to_icon, #custom_icon, #external_snippet_icon, #file_type_icon_class, #icon, #loading_icon, #spinner, #sprite_file_icons_path, #sprite_icon, #sprite_icon_path, #visibility_level_icon

Instance Method Details

#can_read_project?(project) ⇒ Boolean

Returns:

  • (Boolean)

120
121
122
# File 'app/helpers/notifications_helper.rb', line 120

def can_read_project?(project)
  can?(current_user, :read_project, project)
end

#hidden_setting_source_input(notification_setting) ⇒ Object

Create hidden field to send notification setting source to controller


93
94
95
96
97
# File 'app/helpers/notifications_helper.rb', line 93

def hidden_setting_source_input(notification_setting)
  return unless notification_setting.source_type

  hidden_field_tag "#{notification_setting.source_type.downcase}_id", notification_setting.source_id
end

#notification_description(level) ⇒ Object


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/helpers/notifications_helper.rb', line 52

def notification_description(level)
  case level.to_sym
  when :participating
    _('You will only receive notifications for threads you have participated in')
  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')
  when :custom
    _('You will only receive notifications for the events you choose')
  when :owner_disabled
    _('Notifications have been disabled by the project or group owner')
  end
end

#notification_event_name(event) ⇒ Object


99
100
101
102
103
104
105
106
107
# File 'app/helpers/notifications_helper.rb', line 99

def notification_event_name(event)
  # All values from NotificationSetting.email_events
  case event
  when :success_pipeline
    s_('NotificationEvent|Successful pipeline')
  else
    s_(event.to_s.humanize)
  end
end

#notification_icon(level) ⇒ Object


31
32
33
# File 'app/helpers/notifications_helper.rb', line 31

def notification_icon(level)
  sprite_icon("#{notification_icon_class(level)}")
end

#notification_icon_class(level) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/helpers/notifications_helper.rb', line 6

def notification_icon_class(level)
  case level.to_sym
  when :disabled, :owner_disabled
    'notifications-off'
  when :participating
    'notifications'
  when :watch
    'eye'
  when :mention
    'at'
  when :global
    'earth'
  end
end

#notification_icon_level(notification_setting, emails_disabled = false) ⇒ Object


21
22
23
24
25
26
27
28
29
# File 'app/helpers/notifications_helper.rb', line 21

def notification_icon_level(notification_setting, emails_disabled = false)
  if emails_disabled
    'owner_disabled'
  elsif notification_setting.global?
    current_user.global_notification_setting.level
  else
    notification_setting.level
  end
end

#notification_list_item(level, setting) ⇒ Object


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/helpers/notifications_helper.rb', line 71

def notification_list_item(level, setting)
  title = notification_title(level)

  data = {
    notification_level: level,
    notification_title: title
  }

  (:li, role: "menuitem") do
    link_to '#', class: "update-notification #{('is-active' if setting.level == level)}", data: data do
      link_output = (:strong, title, class: 'dropdown-menu-inner-title')
      link_output << (:span, notification_description(level), class: 'dropdown-menu-inner-content')
    end
  end
end

#notification_setting_icon(notification_setting = nil) ⇒ Object


109
110
111
112
113
114
# File 'app/helpers/notifications_helper.rb', line 109

def notification_setting_icon(notification_setting = nil)
  sprite_icon(
    !notification_setting.present? || notification_setting.disabled? ? "notifications-off" : "notifications",
    css_class: "icon notifications-icon js-notifications-icon"
  )
end

#notification_title(level) ⇒ Object


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/helpers/notifications_helper.rb', line 35

def notification_title(level)
  # Can be anything in `NotificationSetting.level:
  case level.to_sym
  when :participating
    s_('NotificationLevel|Participate')
  when :mention
    s_('NotificationLevel|On mention')
  else
    N_('NotificationLevel|Global')
    N_('NotificationLevel|Watch')
    N_('NotificationLevel|Disabled')
    N_('NotificationLevel|Custom')
    level = "NotificationLevel|#{level.to_s.humanize}"
    s_(level)
  end
end

#notifications_menu_identifier(type, notification_setting) ⇒ Object

Identifier to trigger individually dropdowns and custom settings modals in the same view


88
89
90
# File 'app/helpers/notifications_helper.rb', line 88

def notifications_menu_identifier(type, notification_setting)
  "#{type}-#{notification_setting.user_id}-#{notification_setting.source_id}-#{notification_setting.source_type}"
end

#show_unsubscribe_title?(noteable) ⇒ Boolean

Returns:

  • (Boolean)

116
117
118
# File 'app/helpers/notifications_helper.rb', line 116

def show_unsubscribe_title?(noteable)
  can?(current_user, "read_#{noteable.to_ability_name}".to_sym, noteable)
end